blob: 6b19bd2ad762b02c877bae4f2aa40b47d141900c [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 Gregor9bda6cf2015-07-07 03:58:14 +0000688 /// \brief Build an Objective-C object type.
689 ///
690 /// By default, performs semantic analysis when building the object type.
691 /// Subclasses may override this routine to provide different behavior.
692 QualType RebuildObjCObjectType(QualType BaseType,
693 SourceLocation Loc,
694 SourceLocation TypeArgsLAngleLoc,
695 ArrayRef<TypeSourceInfo *> TypeArgs,
696 SourceLocation TypeArgsRAngleLoc,
697 SourceLocation ProtocolLAngleLoc,
698 ArrayRef<ObjCProtocolDecl *> Protocols,
699 ArrayRef<SourceLocation> ProtocolLocs,
700 SourceLocation ProtocolRAngleLoc);
701
702 /// \brief Build a new Objective-C object pointer type given the pointee type.
703 ///
704 /// By default, directly builds the pointer type, with no additional semantic
705 /// analysis.
706 QualType RebuildObjCObjectPointerType(QualType PointeeType,
707 SourceLocation Star);
708
Douglas Gregord6ff3322009-08-04 16:50:30 +0000709 /// \brief Build a new array type given the element type, size
710 /// modifier, size of the array (if known), size expression, and index type
711 /// qualifiers.
712 ///
713 /// By default, performs semantic analysis when building the array type.
714 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000715 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000716 QualType RebuildArrayType(QualType ElementType,
717 ArrayType::ArraySizeModifier SizeMod,
718 const llvm::APInt *Size,
719 Expr *SizeExpr,
720 unsigned IndexTypeQuals,
721 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000722
Douglas Gregord6ff3322009-08-04 16:50:30 +0000723 /// \brief Build a new constant array type given the element type, size
724 /// modifier, (known) size of the array, 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 RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000729 ArrayType::ArraySizeModifier SizeMod,
730 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000731 unsigned IndexTypeQuals,
732 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000733
Douglas Gregord6ff3322009-08-04 16:50:30 +0000734 /// \brief Build a new incomplete array type given the element type, size
735 /// modifier, 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 RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000741 unsigned IndexTypeQuals,
742 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000743
Mike Stump11289f42009-09-09 15:08:12 +0000744 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000745 /// size modifier, size expression, and index type qualifiers.
746 ///
747 /// By default, performs semantic analysis when building the array type.
748 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000749 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000750 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000751 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000752 unsigned IndexTypeQuals,
753 SourceRange BracketsRange);
754
Mike Stump11289f42009-09-09 15:08:12 +0000755 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000756 /// size modifier, size expression, and index type qualifiers.
757 ///
758 /// By default, performs semantic analysis when building the array type.
759 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000760 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000761 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000762 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000763 unsigned IndexTypeQuals,
764 SourceRange BracketsRange);
765
766 /// \brief Build a new vector type given the element type and
767 /// number of elements.
768 ///
769 /// By default, performs semantic analysis when building the vector type.
770 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000771 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000772 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000773
Douglas Gregord6ff3322009-08-04 16:50:30 +0000774 /// \brief Build a new extended vector type given the element type and
775 /// number of elements.
776 ///
777 /// By default, performs semantic analysis when building the vector type.
778 /// Subclasses may override this routine to provide different behavior.
779 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
780 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000781
782 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000783 /// given the element type and number of elements.
784 ///
785 /// By default, performs semantic analysis when building the vector type.
786 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000787 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000788 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000789 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000790
Douglas Gregord6ff3322009-08-04 16:50:30 +0000791 /// \brief Build a new function type.
792 ///
793 /// By default, performs semantic analysis when building the function type.
794 /// Subclasses may override this routine to provide different behavior.
795 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000796 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000797 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000798
John McCall550e0c22009-10-21 00:40:46 +0000799 /// \brief Build a new unprototyped function type.
800 QualType RebuildFunctionNoProtoType(QualType ResultType);
801
John McCallb96ec562009-12-04 22:46:56 +0000802 /// \brief Rebuild an unresolved typename type, given the decl that
803 /// the UnresolvedUsingTypenameDecl was transformed to.
804 QualType RebuildUnresolvedUsingType(Decl *D);
805
Douglas Gregord6ff3322009-08-04 16:50:30 +0000806 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000807 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000808 return SemaRef.Context.getTypeDeclType(Typedef);
809 }
810
811 /// \brief Build a new class/struct/union type.
812 QualType RebuildRecordType(RecordDecl *Record) {
813 return SemaRef.Context.getTypeDeclType(Record);
814 }
815
816 /// \brief Build a new Enum type.
817 QualType RebuildEnumType(EnumDecl *Enum) {
818 return SemaRef.Context.getTypeDeclType(Enum);
819 }
John McCallfcc33b02009-09-05 00:15:47 +0000820
Mike Stump11289f42009-09-09 15:08:12 +0000821 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000822 ///
823 /// By default, performs semantic analysis when building the typeof type.
824 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000825 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000826
Mike Stump11289f42009-09-09 15:08:12 +0000827 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000828 ///
829 /// By default, builds a new TypeOfType with the given underlying type.
830 QualType RebuildTypeOfType(QualType Underlying);
831
Alexis Hunte852b102011-05-24 22:41:36 +0000832 /// \brief Build a new unary transform type.
833 QualType RebuildUnaryTransformType(QualType BaseType,
834 UnaryTransformType::UTTKind UKind,
835 SourceLocation Loc);
836
Richard Smith74aeef52013-04-26 16:15:35 +0000837 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000838 ///
839 /// By default, performs semantic analysis when building the decltype type.
840 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000841 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000842
Richard Smith74aeef52013-04-26 16:15:35 +0000843 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000844 ///
845 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000846 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000847 // Note, IsDependent is always false here: we implicitly convert an 'auto'
848 // which has been deduced to a dependent type into an undeduced 'auto', so
849 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000850 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
851 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000852 }
853
Douglas Gregord6ff3322009-08-04 16:50:30 +0000854 /// \brief Build a new template specialization type.
855 ///
856 /// By default, performs semantic analysis when building the template
857 /// specialization type. Subclasses may override this routine to provide
858 /// different behavior.
859 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000860 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000861 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000862
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000863 /// \brief Build a new parenthesized type.
864 ///
865 /// By default, builds a new ParenType type from the inner type.
866 /// Subclasses may override this routine to provide different behavior.
867 QualType RebuildParenType(QualType InnerType) {
868 return SemaRef.Context.getParenType(InnerType);
869 }
870
Douglas Gregord6ff3322009-08-04 16:50:30 +0000871 /// \brief Build a new qualified name type.
872 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000873 /// By default, builds a new ElaboratedType type from the keyword,
874 /// the nested-name-specifier and the named type.
875 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000876 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
877 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000878 NestedNameSpecifierLoc QualifierLoc,
879 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000880 return SemaRef.Context.getElaboratedType(Keyword,
881 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000882 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000883 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000884
885 /// \brief Build a new typename type that refers to a template-id.
886 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000887 /// By default, builds a new DependentNameType type from the
888 /// nested-name-specifier and the given type. Subclasses may override
889 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000890 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000891 ElaboratedTypeKeyword Keyword,
892 NestedNameSpecifierLoc QualifierLoc,
893 const IdentifierInfo *Name,
894 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000895 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000896 // Rebuild the template name.
897 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000898 CXXScopeSpec SS;
899 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000900 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000901 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
902 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000903
Douglas Gregora7a795b2011-03-01 20:11:18 +0000904 if (InstName.isNull())
905 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000906
Douglas Gregora7a795b2011-03-01 20:11:18 +0000907 // If it's still dependent, make a dependent specialization.
908 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000909 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
910 QualifierLoc.getNestedNameSpecifier(),
911 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000912 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000913
Douglas Gregora7a795b2011-03-01 20:11:18 +0000914 // Otherwise, make an elaborated type wrapping a non-dependent
915 // specialization.
916 QualType T =
917 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
918 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000919
Craig Topperc3ec1492014-05-26 06:22:03 +0000920 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000921 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000922
923 return SemaRef.Context.getElaboratedType(Keyword,
924 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000925 T);
926 }
927
Douglas Gregord6ff3322009-08-04 16:50:30 +0000928 /// \brief Build a new typename type that refers to an identifier.
929 ///
930 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000931 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000932 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000933 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000934 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000935 NestedNameSpecifierLoc QualifierLoc,
936 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000937 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000938 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000939 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000940
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000941 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000942 // If the name is still dependent, just build a new dependent name type.
943 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000944 return SemaRef.Context.getDependentNameType(Keyword,
945 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000946 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000947 }
948
Abramo Bagnara6150c882010-05-11 21:36:43 +0000949 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000950 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000951 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000952
953 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
954
Abramo Bagnarad7548482010-05-19 21:37:53 +0000955 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000956 // into a non-dependent elaborated-type-specifier. Find the tag we're
957 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000958 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000959 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
960 if (!DC)
961 return QualType();
962
John McCallbf8c5192010-05-27 06:40:31 +0000963 if (SemaRef.RequireCompleteDeclContext(SS, DC))
964 return QualType();
965
Craig Topperc3ec1492014-05-26 06:22:03 +0000966 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000967 SemaRef.LookupQualifiedName(Result, DC);
968 switch (Result.getResultKind()) {
969 case LookupResult::NotFound:
970 case LookupResult::NotFoundInCurrentInstantiation:
971 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000972
Douglas Gregore677daf2010-03-31 22:19:08 +0000973 case LookupResult::Found:
974 Tag = Result.getAsSingle<TagDecl>();
975 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000976
Douglas Gregore677daf2010-03-31 22:19:08 +0000977 case LookupResult::FoundOverloaded:
978 case LookupResult::FoundUnresolvedValue:
979 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000980
Douglas Gregore677daf2010-03-31 22:19:08 +0000981 case LookupResult::Ambiguous:
982 // Let the LookupResult structure handle ambiguities.
983 return QualType();
984 }
985
986 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000987 // Check where the name exists but isn't a tag type and use that to emit
988 // better diagnostics.
989 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
990 SemaRef.LookupQualifiedName(Result, DC);
991 switch (Result.getResultKind()) {
992 case LookupResult::Found:
993 case LookupResult::FoundOverloaded:
994 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000995 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000996 unsigned Kind = 0;
997 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000998 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
999 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +00001000 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
1001 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1002 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001003 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001004 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001005 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001006 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001007 break;
1008 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001009 return QualType();
1010 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001011
Richard Trieucaa33d32011-06-10 03:11:26 +00001012 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001013 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001014 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001015 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1016 return QualType();
1017 }
1018
1019 // Build the elaborated-type-specifier type.
1020 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001021 return SemaRef.Context.getElaboratedType(Keyword,
1022 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001023 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001024 }
Mike Stump11289f42009-09-09 15:08:12 +00001025
Douglas Gregor822d0302011-01-12 17:07:58 +00001026 /// \brief Build a new pack expansion type.
1027 ///
1028 /// By default, builds a new PackExpansionType type from the given pattern.
1029 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001030 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001031 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001032 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001033 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001034 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1035 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001036 }
1037
Eli Friedman0dfb8892011-10-06 23:00:33 +00001038 /// \brief Build a new atomic type given its value type.
1039 ///
1040 /// By default, performs semantic analysis when building the atomic type.
1041 /// Subclasses may override this routine to provide different behavior.
1042 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1043
Douglas Gregor71dc5092009-08-06 06:41:21 +00001044 /// \brief Build a new template name given a nested name specifier, a flag
1045 /// indicating whether the "template" keyword was provided, and the template
1046 /// that the template name refers to.
1047 ///
1048 /// By default, builds the new template name directly. Subclasses may override
1049 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001050 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001051 bool TemplateKW,
1052 TemplateDecl *Template);
1053
Douglas Gregor71dc5092009-08-06 06:41:21 +00001054 /// \brief Build a new template name given a nested name specifier and the
1055 /// name that is referred to as a template.
1056 ///
1057 /// By default, performs semantic analysis to determine whether the name can
1058 /// be resolved to a specific template, then builds the appropriate kind of
1059 /// template name. Subclasses may override this routine to provide different
1060 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001061 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1062 const IdentifierInfo &Name,
1063 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001064 QualType ObjectType,
1065 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001066
Douglas Gregor71395fa2009-11-04 00:56:37 +00001067 /// \brief Build a new template name given a nested name specifier and the
1068 /// overloaded operator name that is referred to as a template.
1069 ///
1070 /// By default, performs semantic analysis to determine whether the name can
1071 /// be resolved to a specific template, then builds the appropriate kind of
1072 /// template name. Subclasses may override this routine to provide different
1073 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001074 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001075 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001076 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001077 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001078
1079 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001080 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001081 ///
1082 /// By default, performs semantic analysis to determine whether the name can
1083 /// be resolved to a specific template, then builds the appropriate kind of
1084 /// template name. Subclasses may override this routine to provide different
1085 /// behavior.
1086 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1087 const TemplateArgument &ArgPack) {
1088 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1089 }
1090
Douglas Gregorebe10102009-08-20 07:17:43 +00001091 /// \brief Build a new compound statement.
1092 ///
1093 /// By default, performs semantic analysis to build the new statement.
1094 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001095 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001096 MultiStmtArg Statements,
1097 SourceLocation RBraceLoc,
1098 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001099 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001100 IsStmtExpr);
1101 }
1102
1103 /// \brief Build a new case statement.
1104 ///
1105 /// By default, performs semantic analysis to build the new statement.
1106 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001107 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001108 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001109 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001110 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001111 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001112 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 ColonLoc);
1114 }
Mike Stump11289f42009-09-09 15:08:12 +00001115
Douglas Gregorebe10102009-08-20 07:17:43 +00001116 /// \brief Attach the body to a new case statement.
1117 ///
1118 /// By default, performs semantic analysis to build the new statement.
1119 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001120 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001121 getSema().ActOnCaseStmtBody(S, Body);
1122 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001123 }
Mike Stump11289f42009-09-09 15:08:12 +00001124
Douglas Gregorebe10102009-08-20 07:17:43 +00001125 /// \brief Build a new default statement.
1126 ///
1127 /// By default, performs semantic analysis to build the new statement.
1128 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001129 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001130 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001131 Stmt *SubStmt) {
1132 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001133 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001134 }
Mike Stump11289f42009-09-09 15:08:12 +00001135
Douglas Gregorebe10102009-08-20 07:17:43 +00001136 /// \brief Build a new label statement.
1137 ///
1138 /// By default, performs semantic analysis to build the new statement.
1139 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001140 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1141 SourceLocation ColonLoc, Stmt *SubStmt) {
1142 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001143 }
Mike Stump11289f42009-09-09 15:08:12 +00001144
Richard Smithc202b282012-04-14 00:33:13 +00001145 /// \brief Build a new label statement.
1146 ///
1147 /// By default, performs semantic analysis to build the new statement.
1148 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001149 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1150 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001151 Stmt *SubStmt) {
1152 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1153 }
1154
Douglas Gregorebe10102009-08-20 07:17:43 +00001155 /// \brief Build a new "if" statement.
1156 ///
1157 /// By default, performs semantic analysis to build the new statement.
1158 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001159 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001160 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001161 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001162 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001163 }
Mike Stump11289f42009-09-09 15:08:12 +00001164
Douglas Gregorebe10102009-08-20 07:17:43 +00001165 /// \brief Start building a new switch statement.
1166 ///
1167 /// By default, performs semantic analysis to build the new statement.
1168 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001169 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001170 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001171 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001172 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001173 }
Mike Stump11289f42009-09-09 15:08:12 +00001174
Douglas Gregorebe10102009-08-20 07:17:43 +00001175 /// \brief Attach the body to the switch statement.
1176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001179 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001180 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001181 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001182 }
1183
1184 /// \brief Build a new while statement.
1185 ///
1186 /// By default, performs semantic analysis to build the new statement.
1187 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001188 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1189 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001190 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001191 }
Mike Stump11289f42009-09-09 15:08:12 +00001192
Douglas Gregorebe10102009-08-20 07:17:43 +00001193 /// \brief Build a new do-while statement.
1194 ///
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001197 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001198 SourceLocation WhileLoc, SourceLocation LParenLoc,
1199 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001200 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1201 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001202 }
1203
1204 /// \brief Build a new for statement.
1205 ///
1206 /// By default, performs semantic analysis to build the new statement.
1207 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001208 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001209 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001210 VarDecl *CondVar, Sema::FullExprArg Inc,
1211 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001212 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001213 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001214 }
Mike Stump11289f42009-09-09 15:08:12 +00001215
Douglas Gregorebe10102009-08-20 07:17:43 +00001216 /// \brief Build a new goto statement.
1217 ///
1218 /// By default, performs semantic analysis to build the new statement.
1219 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001220 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1221 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001222 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001223 }
1224
1225 /// \brief Build a new indirect goto statement.
1226 ///
1227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001229 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001230 SourceLocation StarLoc,
1231 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001232 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001233 }
Mike Stump11289f42009-09-09 15:08:12 +00001234
Douglas Gregorebe10102009-08-20 07:17:43 +00001235 /// \brief Build a new return statement.
1236 ///
1237 /// By default, performs semantic analysis to build the new statement.
1238 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001239 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001240 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001241 }
Mike Stump11289f42009-09-09 15:08:12 +00001242
Douglas Gregorebe10102009-08-20 07:17:43 +00001243 /// \brief Build a new declaration statement.
1244 ///
1245 /// By default, performs semantic analysis to build the new statement.
1246 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001247 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001248 SourceLocation StartLoc, SourceLocation EndLoc) {
1249 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001250 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001251 }
Mike Stump11289f42009-09-09 15:08:12 +00001252
Anders Carlssonaaeef072010-01-24 05:50:09 +00001253 /// \brief Build a new inline asm statement.
1254 ///
1255 /// By default, performs semantic analysis to build the new statement.
1256 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001257 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1258 bool IsVolatile, unsigned NumOutputs,
1259 unsigned NumInputs, IdentifierInfo **Names,
1260 MultiExprArg Constraints, MultiExprArg Exprs,
1261 Expr *AsmString, MultiExprArg Clobbers,
1262 SourceLocation RParenLoc) {
1263 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1264 NumInputs, Names, Constraints, Exprs,
1265 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001266 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001267
Chad Rosier32503022012-06-11 20:47:18 +00001268 /// \brief Build a new MS style inline asm statement.
1269 ///
1270 /// By default, performs semantic analysis to build the new statement.
1271 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001272 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001273 ArrayRef<Token> AsmToks,
1274 StringRef AsmString,
1275 unsigned NumOutputs, unsigned NumInputs,
1276 ArrayRef<StringRef> Constraints,
1277 ArrayRef<StringRef> Clobbers,
1278 ArrayRef<Expr*> Exprs,
1279 SourceLocation EndLoc) {
1280 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1281 NumOutputs, NumInputs,
1282 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001283 }
1284
James Dennett2a4d13c2012-06-15 07:13:21 +00001285 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001286 ///
1287 /// By default, performs semantic analysis to build the new statement.
1288 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001289 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001290 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001291 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001292 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001293 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001294 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001295 }
1296
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001297 /// \brief Rebuild an Objective-C exception declaration.
1298 ///
1299 /// By default, performs semantic analysis to build the new declaration.
1300 /// Subclasses may override this routine to provide different behavior.
1301 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1302 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001303 return getSema().BuildObjCExceptionDecl(TInfo, T,
1304 ExceptionDecl->getInnerLocStart(),
1305 ExceptionDecl->getLocation(),
1306 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001307 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001308
James Dennett2a4d13c2012-06-15 07:13:21 +00001309 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +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 RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001314 SourceLocation RParenLoc,
1315 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001316 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001317 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001318 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001319 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001320
James Dennett2a4d13c2012-06-15 07:13:21 +00001321 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001322 ///
1323 /// By default, performs semantic analysis to build the new statement.
1324 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001325 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001326 Stmt *Body) {
1327 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001328 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001329
James Dennett2a4d13c2012-06-15 07:13:21 +00001330 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001331 ///
1332 /// By default, performs semantic analysis to build the new statement.
1333 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001334 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001335 Expr *Operand) {
1336 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001337 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001338
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001339 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001340 ///
1341 /// By default, performs semantic analysis to build the new statement.
1342 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001343 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001344 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001345 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001346 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001347 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001348 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001349 return getSema().ActOnOpenMPExecutableDirective(
1350 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001351 }
1352
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001353 /// \brief Build a new OpenMP 'if' clause.
1354 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001355 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001356 /// Subclasses may override this routine to provide different behavior.
1357 OMPClause *RebuildOMPIfClause(Expr *Condition,
1358 SourceLocation StartLoc,
1359 SourceLocation LParenLoc,
1360 SourceLocation EndLoc) {
1361 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1362 LParenLoc, EndLoc);
1363 }
1364
Alexey Bataev3778b602014-07-17 07:32:53 +00001365 /// \brief Build a new OpenMP 'final' clause.
1366 ///
1367 /// By default, performs semantic analysis to build the new OpenMP clause.
1368 /// Subclasses may override this routine to provide different behavior.
1369 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1370 SourceLocation LParenLoc,
1371 SourceLocation EndLoc) {
1372 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1373 EndLoc);
1374 }
1375
Alexey Bataev568a8332014-03-06 06:15:19 +00001376 /// \brief Build a new OpenMP 'num_threads' clause.
1377 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001378 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001379 /// Subclasses may override this routine to provide different behavior.
1380 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1381 SourceLocation StartLoc,
1382 SourceLocation LParenLoc,
1383 SourceLocation EndLoc) {
1384 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1385 LParenLoc, EndLoc);
1386 }
1387
Alexey Bataev62c87d22014-03-21 04:51:18 +00001388 /// \brief Build a new OpenMP 'safelen' clause.
1389 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001390 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001391 /// Subclasses may override this routine to provide different behavior.
1392 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1393 SourceLocation LParenLoc,
1394 SourceLocation EndLoc) {
1395 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1396 }
1397
Alexander Musman8bd31e62014-05-27 15:12:19 +00001398 /// \brief Build a new OpenMP 'collapse' clause.
1399 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001400 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001401 /// Subclasses may override this routine to provide different behavior.
1402 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1403 SourceLocation LParenLoc,
1404 SourceLocation EndLoc) {
1405 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1406 EndLoc);
1407 }
1408
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001409 /// \brief Build a new OpenMP 'default' clause.
1410 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001411 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001412 /// Subclasses may override this routine to provide different behavior.
1413 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1414 SourceLocation KindKwLoc,
1415 SourceLocation StartLoc,
1416 SourceLocation LParenLoc,
1417 SourceLocation EndLoc) {
1418 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1419 StartLoc, LParenLoc, EndLoc);
1420 }
1421
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001422 /// \brief Build a new OpenMP 'proc_bind' clause.
1423 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001424 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001425 /// Subclasses may override this routine to provide different behavior.
1426 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1427 SourceLocation KindKwLoc,
1428 SourceLocation StartLoc,
1429 SourceLocation LParenLoc,
1430 SourceLocation EndLoc) {
1431 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1432 StartLoc, LParenLoc, EndLoc);
1433 }
1434
Alexey Bataev56dafe82014-06-20 07:16:17 +00001435 /// \brief Build a new OpenMP 'schedule' clause.
1436 ///
1437 /// By default, performs semantic analysis to build the new OpenMP clause.
1438 /// Subclasses may override this routine to provide different behavior.
1439 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1440 Expr *ChunkSize,
1441 SourceLocation StartLoc,
1442 SourceLocation LParenLoc,
1443 SourceLocation KindLoc,
1444 SourceLocation CommaLoc,
1445 SourceLocation EndLoc) {
1446 return getSema().ActOnOpenMPScheduleClause(
1447 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1448 }
1449
Alexey Bataev10e775f2015-07-30 11:36:16 +00001450 /// \brief Build a new OpenMP 'ordered' clause.
1451 ///
1452 /// By default, performs semantic analysis to build the new OpenMP clause.
1453 /// Subclasses may override this routine to provide different behavior.
1454 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1455 SourceLocation EndLoc,
1456 SourceLocation LParenLoc, Expr *Num) {
1457 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1458 }
1459
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001460 /// \brief Build a new OpenMP 'private' clause.
1461 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001462 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001463 /// Subclasses may override this routine to provide different behavior.
1464 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1465 SourceLocation StartLoc,
1466 SourceLocation LParenLoc,
1467 SourceLocation EndLoc) {
1468 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1469 EndLoc);
1470 }
1471
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001472 /// \brief Build a new OpenMP 'firstprivate' clause.
1473 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001474 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001475 /// Subclasses may override this routine to provide different behavior.
1476 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1477 SourceLocation StartLoc,
1478 SourceLocation LParenLoc,
1479 SourceLocation EndLoc) {
1480 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1481 EndLoc);
1482 }
1483
Alexander Musman1bb328c2014-06-04 13:06:39 +00001484 /// \brief Build a new OpenMP 'lastprivate' clause.
1485 ///
1486 /// By default, performs semantic analysis to build the new OpenMP clause.
1487 /// Subclasses may override this routine to provide different behavior.
1488 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1489 SourceLocation StartLoc,
1490 SourceLocation LParenLoc,
1491 SourceLocation EndLoc) {
1492 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1493 EndLoc);
1494 }
1495
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001496 /// \brief Build a new OpenMP 'shared' clause.
1497 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001498 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001499 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001500 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1501 SourceLocation StartLoc,
1502 SourceLocation LParenLoc,
1503 SourceLocation EndLoc) {
1504 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1505 EndLoc);
1506 }
1507
Alexey Bataevc5e02582014-06-16 07:08:35 +00001508 /// \brief Build a new OpenMP 'reduction' clause.
1509 ///
1510 /// By default, performs semantic analysis to build the new statement.
1511 /// Subclasses may override this routine to provide different behavior.
1512 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1513 SourceLocation StartLoc,
1514 SourceLocation LParenLoc,
1515 SourceLocation ColonLoc,
1516 SourceLocation EndLoc,
1517 CXXScopeSpec &ReductionIdScopeSpec,
1518 const DeclarationNameInfo &ReductionId) {
1519 return getSema().ActOnOpenMPReductionClause(
1520 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1521 ReductionId);
1522 }
1523
Alexander Musman8dba6642014-04-22 13:09:42 +00001524 /// \brief Build a new OpenMP 'linear' clause.
1525 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001526 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001527 /// Subclasses may override this routine to provide different behavior.
1528 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1529 SourceLocation StartLoc,
1530 SourceLocation LParenLoc,
1531 SourceLocation ColonLoc,
1532 SourceLocation EndLoc) {
1533 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1534 ColonLoc, EndLoc);
1535 }
1536
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001537 /// \brief Build a new OpenMP 'aligned' clause.
1538 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001539 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001540 /// Subclasses may override this routine to provide different behavior.
1541 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1542 SourceLocation StartLoc,
1543 SourceLocation LParenLoc,
1544 SourceLocation ColonLoc,
1545 SourceLocation EndLoc) {
1546 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1547 LParenLoc, ColonLoc, EndLoc);
1548 }
1549
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001550 /// \brief Build a new OpenMP 'copyin' clause.
1551 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001552 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001553 /// Subclasses may override this routine to provide different behavior.
1554 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1555 SourceLocation StartLoc,
1556 SourceLocation LParenLoc,
1557 SourceLocation EndLoc) {
1558 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1559 EndLoc);
1560 }
1561
Alexey Bataevbae9a792014-06-27 10:37:06 +00001562 /// \brief Build a new OpenMP 'copyprivate' clause.
1563 ///
1564 /// By default, performs semantic analysis to build the new OpenMP clause.
1565 /// Subclasses may override this routine to provide different behavior.
1566 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1567 SourceLocation StartLoc,
1568 SourceLocation LParenLoc,
1569 SourceLocation EndLoc) {
1570 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1571 EndLoc);
1572 }
1573
Alexey Bataev6125da92014-07-21 11:26:11 +00001574 /// \brief Build a new OpenMP 'flush' pseudo clause.
1575 ///
1576 /// By default, performs semantic analysis to build the new OpenMP clause.
1577 /// Subclasses may override this routine to provide different behavior.
1578 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1579 SourceLocation StartLoc,
1580 SourceLocation LParenLoc,
1581 SourceLocation EndLoc) {
1582 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1583 EndLoc);
1584 }
1585
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001586 /// \brief Build a new OpenMP 'depend' pseudo clause.
1587 ///
1588 /// By default, performs semantic analysis to build the new OpenMP clause.
1589 /// Subclasses may override this routine to provide different behavior.
1590 OMPClause *
1591 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1592 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1593 SourceLocation StartLoc, SourceLocation LParenLoc,
1594 SourceLocation EndLoc) {
1595 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1596 StartLoc, LParenLoc, EndLoc);
1597 }
1598
Michael Wonge710d542015-08-07 16:16:36 +00001599 /// \brief Build a new OpenMP 'device' clause.
1600 ///
1601 /// By default, performs semantic analysis to build the new statement.
1602 /// Subclasses may override this routine to provide different behavior.
1603 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1604 SourceLocation LParenLoc,
1605 SourceLocation EndLoc) {
1606 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
1607 EndLoc);
1608 }
1609
James Dennett2a4d13c2012-06-15 07:13:21 +00001610 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001611 ///
1612 /// By default, performs semantic analysis to build the new statement.
1613 /// Subclasses may override this routine to provide different behavior.
1614 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1615 Expr *object) {
1616 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1617 }
1618
James Dennett2a4d13c2012-06-15 07:13:21 +00001619 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001620 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001621 /// By default, performs semantic analysis to build the new statement.
1622 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001623 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001624 Expr *Object, Stmt *Body) {
1625 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001626 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001627
James Dennett2a4d13c2012-06-15 07:13:21 +00001628 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001629 ///
1630 /// By default, performs semantic analysis to build the new statement.
1631 /// Subclasses may override this routine to provide different behavior.
1632 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1633 Stmt *Body) {
1634 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1635 }
John McCall53848232011-07-27 01:07:15 +00001636
Douglas Gregorf68a5082010-04-22 23:10:45 +00001637 /// \brief Build a new Objective-C fast enumeration statement.
1638 ///
1639 /// By default, performs semantic analysis to build the new statement.
1640 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001641 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001642 Stmt *Element,
1643 Expr *Collection,
1644 SourceLocation RParenLoc,
1645 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001646 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001647 Element,
John McCallb268a282010-08-23 23:25:46 +00001648 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001649 RParenLoc);
1650 if (ForEachStmt.isInvalid())
1651 return StmtError();
1652
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001653 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001654 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001655
Douglas Gregorebe10102009-08-20 07:17:43 +00001656 /// \brief Build a new C++ exception declaration.
1657 ///
1658 /// By default, performs semantic analysis to build the new decaration.
1659 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001660 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001661 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001662 SourceLocation StartLoc,
1663 SourceLocation IdLoc,
1664 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001665 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001666 StartLoc, IdLoc, Id);
1667 if (Var)
1668 getSema().CurContext->addDecl(Var);
1669 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001670 }
1671
1672 /// \brief Build a new C++ catch statement.
1673 ///
1674 /// By default, performs semantic analysis to build the new statement.
1675 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001676 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001677 VarDecl *ExceptionDecl,
1678 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001679 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1680 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001681 }
Mike Stump11289f42009-09-09 15:08:12 +00001682
Douglas Gregorebe10102009-08-20 07:17:43 +00001683 /// \brief Build a new C++ try statement.
1684 ///
1685 /// By default, performs semantic analysis to build the new statement.
1686 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001687 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1688 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001689 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001690 }
Mike Stump11289f42009-09-09 15:08:12 +00001691
Richard Smith02e85f32011-04-14 22:09:26 +00001692 /// \brief Build a new C++0x range-based for statement.
1693 ///
1694 /// By default, performs semantic analysis to build the new statement.
1695 /// Subclasses may override this routine to provide different behavior.
1696 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1697 SourceLocation ColonLoc,
1698 Stmt *Range, Stmt *BeginEnd,
1699 Expr *Cond, Expr *Inc,
1700 Stmt *LoopVar,
1701 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001702 // If we've just learned that the range is actually an Objective-C
1703 // collection, treat this as an Objective-C fast enumeration loop.
1704 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1705 if (RangeStmt->isSingleDecl()) {
1706 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001707 if (RangeVar->isInvalidDecl())
1708 return StmtError();
1709
Douglas Gregorf7106af2013-04-08 18:40:13 +00001710 Expr *RangeExpr = RangeVar->getInit();
1711 if (!RangeExpr->isTypeDependent() &&
1712 RangeExpr->getType()->isObjCObjectPointerType())
1713 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1714 RParenLoc);
1715 }
1716 }
1717 }
1718
Richard Smith02e85f32011-04-14 22:09:26 +00001719 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001720 Cond, Inc, LoopVar, RParenLoc,
1721 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001722 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001723
1724 /// \brief Build a new C++0x range-based for statement.
1725 ///
1726 /// By default, performs semantic analysis to build the new statement.
1727 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001728 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001729 bool IsIfExists,
1730 NestedNameSpecifierLoc QualifierLoc,
1731 DeclarationNameInfo NameInfo,
1732 Stmt *Nested) {
1733 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1734 QualifierLoc, NameInfo, Nested);
1735 }
1736
Richard Smith02e85f32011-04-14 22:09:26 +00001737 /// \brief Attach body to a C++0x range-based for statement.
1738 ///
1739 /// By default, performs semantic analysis to finish the new statement.
1740 /// Subclasses may override this routine to provide different behavior.
1741 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1742 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1743 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001744
David Majnemerfad8f482013-10-15 09:33:02 +00001745 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001746 Stmt *TryBlock, Stmt *Handler) {
1747 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001748 }
1749
David Majnemerfad8f482013-10-15 09:33:02 +00001750 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001751 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001752 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001753 }
1754
David Majnemerfad8f482013-10-15 09:33:02 +00001755 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001756 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001757 }
1758
Alexey Bataevec474782014-10-09 08:45:04 +00001759 /// \brief Build a new predefined expression.
1760 ///
1761 /// By default, performs semantic analysis to build the new expression.
1762 /// Subclasses may override this routine to provide different behavior.
1763 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1764 PredefinedExpr::IdentType IT) {
1765 return getSema().BuildPredefinedExpr(Loc, IT);
1766 }
1767
Douglas Gregora16548e2009-08-11 05:31:07 +00001768 /// \brief Build a new expression that references a declaration.
1769 ///
1770 /// By default, performs semantic analysis to build the new expression.
1771 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001772 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001773 LookupResult &R,
1774 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001775 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1776 }
1777
1778
1779 /// \brief Build a new expression that references a declaration.
1780 ///
1781 /// By default, performs semantic analysis to build the new expression.
1782 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001783 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001784 ValueDecl *VD,
1785 const DeclarationNameInfo &NameInfo,
1786 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001787 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001788 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001789
1790 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001791
1792 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001793 }
Mike Stump11289f42009-09-09 15:08:12 +00001794
Douglas Gregora16548e2009-08-11 05:31:07 +00001795 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001796 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001797 /// By default, performs semantic analysis to build the new expression.
1798 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001799 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001800 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001801 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001802 }
1803
Douglas Gregorad8a3362009-09-04 17:36:40 +00001804 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001805 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001806 /// By default, performs semantic analysis to build the new expression.
1807 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001808 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001809 SourceLocation OperatorLoc,
1810 bool isArrow,
1811 CXXScopeSpec &SS,
1812 TypeSourceInfo *ScopeType,
1813 SourceLocation CCLoc,
1814 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001815 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001816
Douglas Gregora16548e2009-08-11 05:31:07 +00001817 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001818 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001819 /// By default, performs semantic analysis to build the new expression.
1820 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001821 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001822 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001823 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001824 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001825 }
Mike Stump11289f42009-09-09 15:08:12 +00001826
Douglas Gregor882211c2010-04-28 22:16:22 +00001827 /// \brief Build a new builtin offsetof expression.
1828 ///
1829 /// By default, performs semantic analysis to build the new expression.
1830 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001831 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001832 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001833 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001834 unsigned NumComponents,
1835 SourceLocation RParenLoc) {
1836 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1837 NumComponents, RParenLoc);
1838 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001839
1840 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001841 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001842 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001843 /// By default, performs semantic analysis to build the new expression.
1844 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001845 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1846 SourceLocation OpLoc,
1847 UnaryExprOrTypeTrait ExprKind,
1848 SourceRange R) {
1849 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001850 }
1851
Peter Collingbournee190dee2011-03-11 19:24:49 +00001852 /// \brief Build a new sizeof, alignof or vec step expression with an
1853 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001854 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001855 /// By default, performs semantic analysis to build the new expression.
1856 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001857 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1858 UnaryExprOrTypeTrait ExprKind,
1859 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001860 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001861 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001862 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001863 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001864
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001865 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001866 }
Mike Stump11289f42009-09-09 15:08:12 +00001867
Douglas Gregora16548e2009-08-11 05:31:07 +00001868 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001869 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001870 /// By default, performs semantic analysis to build the new expression.
1871 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001872 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001873 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001874 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001875 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001876 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001877 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001878 RBracketLoc);
1879 }
1880
1881 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001882 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001883 /// By default, performs semantic analysis to build the new expression.
1884 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001885 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001886 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001887 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001888 Expr *ExecConfig = nullptr) {
1889 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001890 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001891 }
1892
1893 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001894 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001895 /// By default, performs semantic analysis to build the new expression.
1896 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001897 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001898 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001899 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001900 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001901 const DeclarationNameInfo &MemberNameInfo,
1902 ValueDecl *Member,
1903 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001904 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001905 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001906 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1907 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001908 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001909 // We have a reference to an unnamed field. This is always the
1910 // base of an anonymous struct/union member access, i.e. the
1911 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001912 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001913 assert(Member->getType()->isRecordType() &&
1914 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001915
Richard Smithcab9a7d2011-10-26 19:06:56 +00001916 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001917 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001918 QualifierLoc.getNestedNameSpecifier(),
1919 FoundDecl, Member);
1920 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001921 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001922 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001923 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00001924 MemberExpr *ME = new (getSema().Context)
1925 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
1926 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001927 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001928 }
Mike Stump11289f42009-09-09 15:08:12 +00001929
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001930 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001931 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001932
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001933 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001934 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001935
John McCall16df1e52010-03-30 21:47:33 +00001936 // FIXME: this involves duplicating earlier analysis in a lot of
1937 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001938 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001939 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001940 R.resolveKind();
1941
John McCallb268a282010-08-23 23:25:46 +00001942 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001943 SS, TemplateKWLoc,
1944 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001945 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 }
Mike Stump11289f42009-09-09 15:08:12 +00001947
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001949 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001950 /// By default, performs semantic analysis to build the new expression.
1951 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001952 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001953 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001954 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001955 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001956 }
1957
1958 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001959 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 /// By default, performs semantic analysis to build the new expression.
1961 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001962 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001963 SourceLocation QuestionLoc,
1964 Expr *LHS,
1965 SourceLocation ColonLoc,
1966 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001967 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1968 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 }
1970
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001972 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 /// By default, performs semantic analysis to build the new expression.
1974 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001975 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001976 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001977 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001978 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001979 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001980 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001981 }
Mike Stump11289f42009-09-09 15:08:12 +00001982
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001984 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001985 /// By default, performs semantic analysis to build the new expression.
1986 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001987 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001988 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001989 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001990 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001991 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001992 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 }
Mike Stump11289f42009-09-09 15:08:12 +00001994
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001996 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001997 /// By default, performs semantic analysis to build the new expression.
1998 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001999 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 SourceLocation OpLoc,
2001 SourceLocation AccessorLoc,
2002 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002003
John McCall10eae182009-11-30 22:42:35 +00002004 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002005 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002006 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002007 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002008 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002009 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002010 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002011 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002012 }
Mike Stump11289f42009-09-09 15:08:12 +00002013
Douglas Gregora16548e2009-08-11 05:31:07 +00002014 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002015 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002016 /// By default, performs semantic analysis to build the new expression.
2017 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002018 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002019 MultiExprArg Inits,
2020 SourceLocation RBraceLoc,
2021 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002022 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002023 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002024 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002025 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002026
Douglas Gregord3d93062009-11-09 17:16:50 +00002027 // Patch in the result type we were given, which may have been computed
2028 // when the initial InitListExpr was built.
2029 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2030 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002031 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002032 }
Mike Stump11289f42009-09-09 15:08:12 +00002033
Douglas Gregora16548e2009-08-11 05:31:07 +00002034 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002035 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002036 /// By default, performs semantic analysis to build the new expression.
2037 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002038 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002039 MultiExprArg ArrayExprs,
2040 SourceLocation EqualOrColonLoc,
2041 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002042 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002043 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002044 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002045 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002046 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002047 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002048
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002049 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002050 }
Mike Stump11289f42009-09-09 15:08:12 +00002051
Douglas Gregora16548e2009-08-11 05:31:07 +00002052 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002053 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002054 /// By default, builds the implicit value initialization without performing
2055 /// any semantic analysis. Subclasses may override this routine to provide
2056 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002057 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002058 return new (SemaRef.Context) ImplicitValueInitExpr(T);
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 \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002062 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002063 /// 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 RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002066 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002067 SourceLocation RParenLoc) {
2068 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002069 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002070 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002071 }
2072
2073 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002074 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002075 /// By default, performs semantic analysis to build the new expression.
2076 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002077 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002078 MultiExprArg SubExprs,
2079 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002080 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002081 }
Mike Stump11289f42009-09-09 15:08:12 +00002082
Douglas Gregora16548e2009-08-11 05:31:07 +00002083 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002084 ///
2085 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002086 /// rather than attempting to map the label statement itself.
2087 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002088 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002089 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002090 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002091 }
Mike Stump11289f42009-09-09 15:08:12 +00002092
Douglas Gregora16548e2009-08-11 05:31:07 +00002093 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002094 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002095 /// By default, performs semantic analysis to build the new expression.
2096 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002097 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002098 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002099 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002100 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002101 }
Mike Stump11289f42009-09-09 15:08:12 +00002102
Douglas Gregora16548e2009-08-11 05:31:07 +00002103 /// \brief Build a new __builtin_choose_expr expression.
2104 ///
2105 /// By default, performs semantic analysis to build the new expression.
2106 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002107 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002108 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002109 SourceLocation RParenLoc) {
2110 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002111 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002112 RParenLoc);
2113 }
Mike Stump11289f42009-09-09 15:08:12 +00002114
Peter Collingbourne91147592011-04-15 00:35:48 +00002115 /// \brief Build a new generic selection expression.
2116 ///
2117 /// By default, performs semantic analysis to build the new expression.
2118 /// Subclasses may override this routine to provide different behavior.
2119 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2120 SourceLocation DefaultLoc,
2121 SourceLocation RParenLoc,
2122 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002123 ArrayRef<TypeSourceInfo *> Types,
2124 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002125 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002126 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002127 }
2128
Douglas Gregora16548e2009-08-11 05:31:07 +00002129 /// \brief Build a new overloaded operator call expression.
2130 ///
2131 /// By default, performs semantic analysis to build the new expression.
2132 /// The semantic analysis provides the behavior of template instantiation,
2133 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002134 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 /// argument-dependent lookup, etc. Subclasses may override this routine to
2136 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002137 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002139 Expr *Callee,
2140 Expr *First,
2141 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002142
2143 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002144 /// reinterpret_cast.
2145 ///
2146 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002147 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002148 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002149 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002150 Stmt::StmtClass Class,
2151 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002152 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002153 SourceLocation RAngleLoc,
2154 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002155 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002156 SourceLocation RParenLoc) {
2157 switch (Class) {
2158 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002159 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002160 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002161 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002162
2163 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002164 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002165 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002166 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002167
Douglas Gregora16548e2009-08-11 05:31:07 +00002168 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002169 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002170 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002171 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002173
Douglas Gregora16548e2009-08-11 05:31:07 +00002174 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002175 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002176 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002177 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002178
Douglas Gregora16548e2009-08-11 05:31:07 +00002179 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002180 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002182 }
Mike Stump11289f42009-09-09 15:08:12 +00002183
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 /// \brief Build a new C++ static_cast expression.
2185 ///
2186 /// By default, performs semantic analysis to build the new expression.
2187 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002188 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002190 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002191 SourceLocation RAngleLoc,
2192 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002193 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002195 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002196 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002197 SourceRange(LAngleLoc, RAngleLoc),
2198 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002199 }
2200
2201 /// \brief Build a new C++ dynamic_cast expression.
2202 ///
2203 /// By default, performs semantic analysis to build the new expression.
2204 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002205 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002206 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002207 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002208 SourceLocation RAngleLoc,
2209 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002210 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002211 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002212 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002213 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002214 SourceRange(LAngleLoc, RAngleLoc),
2215 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002216 }
2217
2218 /// \brief Build a new C++ reinterpret_cast expression.
2219 ///
2220 /// By default, performs semantic analysis to build the new expression.
2221 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002222 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002223 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002224 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002225 SourceLocation RAngleLoc,
2226 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002227 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002228 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002229 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002230 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002231 SourceRange(LAngleLoc, RAngleLoc),
2232 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 }
2234
2235 /// \brief Build a new C++ const_cast expression.
2236 ///
2237 /// By default, performs semantic analysis to build the new expression.
2238 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002239 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002240 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002241 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002242 SourceLocation RAngleLoc,
2243 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002244 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002245 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002246 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002247 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002248 SourceRange(LAngleLoc, RAngleLoc),
2249 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002250 }
Mike Stump11289f42009-09-09 15:08:12 +00002251
Douglas Gregora16548e2009-08-11 05:31:07 +00002252 /// \brief Build a new C++ functional-style cast expression.
2253 ///
2254 /// By default, performs semantic analysis to build the new expression.
2255 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002256 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2257 SourceLocation LParenLoc,
2258 Expr *Sub,
2259 SourceLocation RParenLoc) {
2260 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002261 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002262 RParenLoc);
2263 }
Mike Stump11289f42009-09-09 15:08:12 +00002264
Douglas Gregora16548e2009-08-11 05:31:07 +00002265 /// \brief Build a new C++ typeid(type) expression.
2266 ///
2267 /// By default, performs semantic analysis to build the new expression.
2268 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002269 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002270 SourceLocation TypeidLoc,
2271 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002272 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002273 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002274 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002275 }
Mike Stump11289f42009-09-09 15:08:12 +00002276
Francois Pichet9f4f2072010-09-08 12:20:18 +00002277
Douglas Gregora16548e2009-08-11 05:31:07 +00002278 /// \brief Build a new C++ typeid(expr) expression.
2279 ///
2280 /// By default, performs semantic analysis to build the new expression.
2281 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002282 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002283 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002284 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002285 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002286 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002287 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002288 }
2289
Francois Pichet9f4f2072010-09-08 12:20:18 +00002290 /// \brief Build a new C++ __uuidof(type) expression.
2291 ///
2292 /// By default, performs semantic analysis to build the new expression.
2293 /// Subclasses may override this routine to provide different behavior.
2294 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2295 SourceLocation TypeidLoc,
2296 TypeSourceInfo *Operand,
2297 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002298 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002299 RParenLoc);
2300 }
2301
2302 /// \brief Build a new C++ __uuidof(expr) expression.
2303 ///
2304 /// By default, performs semantic analysis to build the new expression.
2305 /// Subclasses may override this routine to provide different behavior.
2306 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2307 SourceLocation TypeidLoc,
2308 Expr *Operand,
2309 SourceLocation RParenLoc) {
2310 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2311 RParenLoc);
2312 }
2313
Douglas Gregora16548e2009-08-11 05:31:07 +00002314 /// \brief Build a new C++ "this" expression.
2315 ///
2316 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002317 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002318 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002319 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002320 QualType ThisType,
2321 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002322 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002323 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002324 }
2325
2326 /// \brief Build a new C++ throw expression.
2327 ///
2328 /// By default, performs semantic analysis to build the new expression.
2329 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002330 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2331 bool IsThrownVariableInScope) {
2332 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002333 }
2334
2335 /// \brief Build a new C++ default-argument expression.
2336 ///
2337 /// By default, builds a new default-argument expression, which does not
2338 /// require any semantic analysis. Subclasses may override this routine to
2339 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002340 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002341 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002342 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002343 }
2344
Richard Smith852c9db2013-04-20 22:23:05 +00002345 /// \brief Build a new C++11 default-initialization expression.
2346 ///
2347 /// By default, builds a new default field initialization expression, which
2348 /// does not require any semantic analysis. Subclasses may override this
2349 /// routine to provide different behavior.
2350 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2351 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002352 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002353 }
2354
Douglas Gregora16548e2009-08-11 05:31:07 +00002355 /// \brief Build a new C++ zero-initialization expression.
2356 ///
2357 /// By default, performs semantic analysis to build the new expression.
2358 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002359 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2360 SourceLocation LParenLoc,
2361 SourceLocation RParenLoc) {
2362 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002363 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002364 }
Mike Stump11289f42009-09-09 15:08:12 +00002365
Douglas Gregora16548e2009-08-11 05:31:07 +00002366 /// \brief Build a new C++ "new" expression.
2367 ///
2368 /// By default, performs semantic analysis to build the new expression.
2369 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002370 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002371 bool UseGlobal,
2372 SourceLocation PlacementLParen,
2373 MultiExprArg PlacementArgs,
2374 SourceLocation PlacementRParen,
2375 SourceRange TypeIdParens,
2376 QualType AllocatedType,
2377 TypeSourceInfo *AllocatedTypeInfo,
2378 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002379 SourceRange DirectInitRange,
2380 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002381 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002382 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002383 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002384 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002385 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002386 AllocatedType,
2387 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002388 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002389 DirectInitRange,
2390 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002391 }
Mike Stump11289f42009-09-09 15:08:12 +00002392
Douglas Gregora16548e2009-08-11 05:31:07 +00002393 /// \brief Build a new C++ "delete" expression.
2394 ///
2395 /// By default, performs semantic analysis to build the new expression.
2396 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002397 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002398 bool IsGlobalDelete,
2399 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002400 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002401 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002402 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002403 }
Mike Stump11289f42009-09-09 15:08:12 +00002404
Douglas Gregor29c42f22012-02-24 07:38:34 +00002405 /// \brief Build a new type trait expression.
2406 ///
2407 /// By default, performs semantic analysis to build the new expression.
2408 /// Subclasses may override this routine to provide different behavior.
2409 ExprResult RebuildTypeTrait(TypeTrait Trait,
2410 SourceLocation StartLoc,
2411 ArrayRef<TypeSourceInfo *> Args,
2412 SourceLocation RParenLoc) {
2413 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2414 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002415
John Wiegley6242b6a2011-04-28 00:16:57 +00002416 /// \brief Build a new array type trait expression.
2417 ///
2418 /// By default, performs semantic analysis to build the new expression.
2419 /// Subclasses may override this routine to provide different behavior.
2420 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2421 SourceLocation StartLoc,
2422 TypeSourceInfo *TSInfo,
2423 Expr *DimExpr,
2424 SourceLocation RParenLoc) {
2425 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2426 }
2427
John Wiegleyf9f65842011-04-25 06:54:41 +00002428 /// \brief Build a new expression trait expression.
2429 ///
2430 /// By default, performs semantic analysis to build the new expression.
2431 /// Subclasses may override this routine to provide different behavior.
2432 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2433 SourceLocation StartLoc,
2434 Expr *Queried,
2435 SourceLocation RParenLoc) {
2436 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2437 }
2438
Mike Stump11289f42009-09-09 15:08:12 +00002439 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002440 /// expression.
2441 ///
2442 /// By default, performs semantic analysis to build the new expression.
2443 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002444 ExprResult RebuildDependentScopeDeclRefExpr(
2445 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002446 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002447 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002448 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002449 bool IsAddressOfOperand,
2450 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002451 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002452 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002453
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002454 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002455 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2456 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002457
Reid Kleckner32506ed2014-06-12 23:03:48 +00002458 return getSema().BuildQualifiedDeclarationNameExpr(
2459 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002460 }
2461
2462 /// \brief Build a new template-id expression.
2463 ///
2464 /// By default, performs semantic analysis to build the new expression.
2465 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002466 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002467 SourceLocation TemplateKWLoc,
2468 LookupResult &R,
2469 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002470 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002471 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2472 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002473 }
2474
2475 /// \brief Build a new object-construction expression.
2476 ///
2477 /// By default, performs semantic analysis to build the new expression.
2478 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002479 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002480 SourceLocation Loc,
2481 CXXConstructorDecl *Constructor,
2482 bool IsElidable,
2483 MultiExprArg Args,
2484 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002485 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002486 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002487 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002488 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002489 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002490 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002491 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002492 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002493 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002494
Douglas Gregordb121ba2009-12-14 16:27:04 +00002495 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002496 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002497 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002498 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002499 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002500 RequiresZeroInit, ConstructKind,
2501 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002502 }
2503
2504 /// \brief Build a new object-construction expression.
2505 ///
2506 /// By default, performs semantic analysis to build the new expression.
2507 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002508 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2509 SourceLocation LParenLoc,
2510 MultiExprArg Args,
2511 SourceLocation RParenLoc) {
2512 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002513 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002514 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002515 RParenLoc);
2516 }
2517
2518 /// \brief Build a new object-construction expression.
2519 ///
2520 /// By default, performs semantic analysis to build the new expression.
2521 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002522 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2523 SourceLocation LParenLoc,
2524 MultiExprArg Args,
2525 SourceLocation RParenLoc) {
2526 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002527 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002528 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002529 RParenLoc);
2530 }
Mike Stump11289f42009-09-09 15:08:12 +00002531
Douglas Gregora16548e2009-08-11 05:31:07 +00002532 /// \brief Build a new member reference expression.
2533 ///
2534 /// By default, performs semantic analysis to build the new expression.
2535 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002536 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002537 QualType BaseType,
2538 bool IsArrow,
2539 SourceLocation OperatorLoc,
2540 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002541 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002542 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002543 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002544 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002545 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002546 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002547
John McCallb268a282010-08-23 23:25:46 +00002548 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002549 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002550 SS, TemplateKWLoc,
2551 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002552 MemberNameInfo,
2553 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002554 }
2555
John McCall10eae182009-11-30 22:42:35 +00002556 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002557 ///
2558 /// By default, performs semantic analysis to build the new expression.
2559 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002560 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2561 SourceLocation OperatorLoc,
2562 bool IsArrow,
2563 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002564 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002565 NamedDecl *FirstQualifierInScope,
2566 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002567 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002568 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002569 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002570
John McCallb268a282010-08-23 23:25:46 +00002571 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002572 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002573 SS, TemplateKWLoc,
2574 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002575 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002576 }
Mike Stump11289f42009-09-09 15:08:12 +00002577
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002578 /// \brief Build a new noexcept expression.
2579 ///
2580 /// By default, performs semantic analysis to build the new expression.
2581 /// Subclasses may override this routine to provide different behavior.
2582 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2583 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2584 }
2585
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002586 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002587 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2588 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002589 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002590 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002591 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002592 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2593 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002594 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002595
2596 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2597 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002598 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002599 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002600
Patrick Beard0caa3942012-04-19 00:25:12 +00002601 /// \brief Build a new Objective-C boxed expression.
2602 ///
2603 /// By default, performs semantic analysis to build the new expression.
2604 /// Subclasses may override this routine to provide different behavior.
2605 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2606 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2607 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002608
Ted Kremeneke65b0862012-03-06 20:05:56 +00002609 /// \brief Build a new Objective-C array literal.
2610 ///
2611 /// By default, performs semantic analysis to build the new expression.
2612 /// Subclasses may override this routine to provide different behavior.
2613 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2614 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002615 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002616 MultiExprArg(Elements, NumElements));
2617 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002618
2619 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002620 Expr *Base, Expr *Key,
2621 ObjCMethodDecl *getterMethod,
2622 ObjCMethodDecl *setterMethod) {
2623 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2624 getterMethod, setterMethod);
2625 }
2626
2627 /// \brief Build a new Objective-C dictionary literal.
2628 ///
2629 /// By default, performs semantic analysis to build the new expression.
2630 /// Subclasses may override this routine to provide different behavior.
2631 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2632 ObjCDictionaryElement *Elements,
2633 unsigned NumElements) {
2634 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2635 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002636
James Dennett2a4d13c2012-06-15 07:13:21 +00002637 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002638 ///
2639 /// By default, performs semantic analysis to build the new expression.
2640 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002641 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002642 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002643 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002644 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002645 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002646
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002647 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002648 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002649 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002650 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002651 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002652 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002653 MultiExprArg Args,
2654 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002655 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2656 ReceiverTypeInfo->getType(),
2657 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002658 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002659 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002660 }
2661
2662 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002663 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002664 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002665 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002666 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002667 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002668 MultiExprArg Args,
2669 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002670 return SemaRef.BuildInstanceMessage(Receiver,
2671 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002672 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002673 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002674 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002675 }
2676
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002677 /// \brief Build a new Objective-C instance/class message to 'super'.
2678 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2679 Selector Sel,
2680 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002681 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002682 ObjCMethodDecl *Method,
2683 SourceLocation LBracLoc,
2684 MultiExprArg Args,
2685 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002686 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002687 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002688 SuperLoc,
2689 Sel, Method, LBracLoc, SelectorLocs,
2690 RBracLoc, Args)
2691 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002692 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002693 SuperLoc,
2694 Sel, Method, LBracLoc, SelectorLocs,
2695 RBracLoc, Args);
2696
2697
2698 }
2699
Douglas Gregord51d90d2010-04-26 20:11:03 +00002700 /// \brief Build a new Objective-C ivar reference expression.
2701 ///
2702 /// By default, performs semantic analysis to build the new expression.
2703 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002704 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002705 SourceLocation IvarLoc,
2706 bool IsArrow, bool IsFreeIvar) {
2707 // FIXME: We lose track of the IsFreeIvar bit.
2708 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002709 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2710 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002711 /*FIXME:*/IvarLoc, IsArrow,
2712 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002713 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002714 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002715 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002716 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002717
2718 /// \brief Build a new Objective-C property reference expression.
2719 ///
2720 /// By default, performs semantic analysis to build the new expression.
2721 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002722 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002723 ObjCPropertyDecl *Property,
2724 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002725 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002726 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2727 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2728 /*FIXME:*/PropertyLoc,
2729 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002730 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002731 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002732 NameInfo,
2733 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002734 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002735
John McCallb7bd14f2010-12-02 01:19:52 +00002736 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002737 ///
2738 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002739 /// Subclasses may override this routine to provide different behavior.
2740 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2741 ObjCMethodDecl *Getter,
2742 ObjCMethodDecl *Setter,
2743 SourceLocation PropertyLoc) {
2744 // Since these expressions can only be value-dependent, we do not
2745 // need to perform semantic analysis again.
2746 return Owned(
2747 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2748 VK_LValue, OK_ObjCProperty,
2749 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002750 }
2751
Douglas Gregord51d90d2010-04-26 20:11:03 +00002752 /// \brief Build a new Objective-C "isa" expression.
2753 ///
2754 /// By default, performs semantic analysis to build the new expression.
2755 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002756 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002757 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002758 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002759 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2760 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002761 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002762 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002763 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002764 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002765 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002766 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002767
Douglas Gregora16548e2009-08-11 05:31:07 +00002768 /// \brief Build a new shuffle vector expression.
2769 ///
2770 /// By default, performs semantic analysis to build the new expression.
2771 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002772 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002773 MultiExprArg SubExprs,
2774 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002775 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002776 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002777 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2778 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2779 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002780 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002781
Douglas Gregora16548e2009-08-11 05:31:07 +00002782 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002783 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002784 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2785 SemaRef.Context.BuiltinFnTy,
2786 VK_RValue, BuiltinLoc);
2787 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2788 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002789 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002790
2791 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002792 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002793 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002794 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002795
Douglas Gregora16548e2009-08-11 05:31:07 +00002796 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002797 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002798 }
John McCall31f82722010-11-12 08:19:04 +00002799
Hal Finkelc4d7c822013-09-18 03:29:45 +00002800 /// \brief Build a new convert vector expression.
2801 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2802 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2803 SourceLocation RParenLoc) {
2804 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2805 BuiltinLoc, RParenLoc);
2806 }
2807
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002808 /// \brief Build a new template argument pack expansion.
2809 ///
2810 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002811 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002812 /// different behavior.
2813 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002814 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002815 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002816 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002817 case TemplateArgument::Expression: {
2818 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002819 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2820 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002821 if (Result.isInvalid())
2822 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002823
Douglas Gregor98318c22011-01-03 21:37:45 +00002824 return TemplateArgumentLoc(Result.get(), Result.get());
2825 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002826
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002827 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002828 return TemplateArgumentLoc(TemplateArgument(
2829 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002830 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002831 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002832 Pattern.getTemplateNameLoc(),
2833 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002834
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002835 case TemplateArgument::Null:
2836 case TemplateArgument::Integral:
2837 case TemplateArgument::Declaration:
2838 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002839 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002840 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002841 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002842
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002843 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002844 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002845 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002846 EllipsisLoc,
2847 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002848 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2849 Expansion);
2850 break;
2851 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002852
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002853 return TemplateArgumentLoc();
2854 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002855
Douglas Gregor968f23a2011-01-03 19:31:53 +00002856 /// \brief Build a new expression pack expansion.
2857 ///
2858 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002859 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002860 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002861 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002862 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002863 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002864 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002865
Richard Smith0f0af192014-11-08 05:07:16 +00002866 /// \brief Build a new C++1z fold-expression.
2867 ///
2868 /// By default, performs semantic analysis in order to build a new fold
2869 /// expression.
2870 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
2871 BinaryOperatorKind Operator,
2872 SourceLocation EllipsisLoc, Expr *RHS,
2873 SourceLocation RParenLoc) {
2874 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
2875 RHS, RParenLoc);
2876 }
2877
2878 /// \brief Build an empty C++1z fold-expression with the given operator.
2879 ///
2880 /// By default, produces the fallback value for the fold-expression, or
2881 /// produce an error if there is no fallback value.
2882 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
2883 BinaryOperatorKind Operator) {
2884 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
2885 }
2886
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002887 /// \brief Build a new atomic operation expression.
2888 ///
2889 /// By default, performs semantic analysis to build the new expression.
2890 /// Subclasses may override this routine to provide different behavior.
2891 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2892 MultiExprArg SubExprs,
2893 QualType RetTy,
2894 AtomicExpr::AtomicOp Op,
2895 SourceLocation RParenLoc) {
2896 // Just create the expression; there is not any interesting semantic
2897 // analysis here because we can't actually build an AtomicExpr until
2898 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002899 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002900 RParenLoc);
2901 }
2902
John McCall31f82722010-11-12 08:19:04 +00002903private:
Douglas Gregor14454802011-02-25 02:25:35 +00002904 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2905 QualType ObjectType,
2906 NamedDecl *FirstQualifierInScope,
2907 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002908
2909 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2910 QualType ObjectType,
2911 NamedDecl *FirstQualifierInScope,
2912 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002913
2914 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2915 NamedDecl *FirstQualifierInScope,
2916 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002917};
Douglas Gregora16548e2009-08-11 05:31:07 +00002918
Douglas Gregorebe10102009-08-20 07:17:43 +00002919template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002920StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002921 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002922 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002923
Douglas Gregorebe10102009-08-20 07:17:43 +00002924 switch (S->getStmtClass()) {
2925 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002926
Douglas Gregorebe10102009-08-20 07:17:43 +00002927 // Transform individual statement nodes
2928#define STMT(Node, Parent) \
2929 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002930#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002931#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002932#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002933
Douglas Gregorebe10102009-08-20 07:17:43 +00002934 // Transform expressions by calling TransformExpr.
2935#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002936#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002937#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002938#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002939 {
John McCalldadc5752010-08-24 06:29:42 +00002940 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002941 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002942 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002943
Richard Smith945f8d32013-01-14 22:39:08 +00002944 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002945 }
Mike Stump11289f42009-09-09 15:08:12 +00002946 }
2947
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002948 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002949}
Mike Stump11289f42009-09-09 15:08:12 +00002950
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002951template<typename Derived>
2952OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2953 if (!S)
2954 return S;
2955
2956 switch (S->getClauseKind()) {
2957 default: break;
2958 // Transform individual clause nodes
2959#define OPENMP_CLAUSE(Name, Class) \
2960 case OMPC_ ## Name : \
2961 return getDerived().Transform ## Class(cast<Class>(S));
2962#include "clang/Basic/OpenMPKinds.def"
2963 }
2964
2965 return S;
2966}
2967
Mike Stump11289f42009-09-09 15:08:12 +00002968
Douglas Gregore922c772009-08-04 22:27:00 +00002969template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002970ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002971 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002972 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002973
2974 switch (E->getStmtClass()) {
2975 case Stmt::NoStmtClass: break;
2976#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002977#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002978#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002979 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002980#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002981 }
2982
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002983 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002984}
2985
2986template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002987ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00002988 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00002989 // Initializers are instantiated like expressions, except that various outer
2990 // layers are stripped.
2991 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002992 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002993
2994 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2995 Init = ExprTemp->getSubExpr();
2996
Richard Smithe6ca4752013-05-30 22:40:16 +00002997 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2998 Init = MTE->GetTemporaryExpr();
2999
Richard Smithd59b8322012-12-19 01:39:02 +00003000 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3001 Init = Binder->getSubExpr();
3002
3003 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3004 Init = ICE->getSubExprAsWritten();
3005
Richard Smithcc1b96d2013-06-12 22:31:48 +00003006 if (CXXStdInitializerListExpr *ILE =
3007 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003008 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003009
Richard Smithc6abd962014-07-25 01:12:44 +00003010 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003011 // InitListExprs. Other forms of copy-initialization will be a no-op if
3012 // the initializer is already the right type.
3013 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003014 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003015 return getDerived().TransformExpr(Init);
3016
3017 // Revert value-initialization back to empty parens.
3018 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3019 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003020 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003021 Parens.getEnd());
3022 }
3023
3024 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3025 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003026 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003027 SourceLocation());
3028
3029 // Revert initialization by constructor back to a parenthesized or braced list
3030 // of expressions. Any other form of initializer can just be reused directly.
3031 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003032 return getDerived().TransformExpr(Init);
3033
Richard Smithf8adcdc2014-07-17 05:12:35 +00003034 // If the initialization implicitly converted an initializer list to a
3035 // std::initializer_list object, unwrap the std::initializer_list too.
3036 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003037 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003038
Richard Smithd59b8322012-12-19 01:39:02 +00003039 SmallVector<Expr*, 8> NewArgs;
3040 bool ArgChanged = false;
3041 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003042 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003043 return ExprError();
3044
3045 // If this was list initialization, revert to list form.
3046 if (Construct->isListInitialization())
3047 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3048 Construct->getLocEnd(),
3049 Construct->getType());
3050
Richard Smithd59b8322012-12-19 01:39:02 +00003051 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003052 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003053 if (Parens.isInvalid()) {
3054 // This was a variable declaration's initialization for which no initializer
3055 // was specified.
3056 assert(NewArgs.empty() &&
3057 "no parens or braces but have direct init with arguments?");
3058 return ExprEmpty();
3059 }
Richard Smithd59b8322012-12-19 01:39:02 +00003060 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3061 Parens.getEnd());
3062}
3063
3064template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00003065bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
3066 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003067 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003068 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003069 bool *ArgChanged) {
3070 for (unsigned I = 0; I != NumInputs; ++I) {
3071 // If requested, drop call arguments that need to be dropped.
3072 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3073 if (ArgChanged)
3074 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003075
Douglas Gregora3efea12011-01-03 19:04:46 +00003076 break;
3077 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003078
Douglas Gregor968f23a2011-01-03 19:31:53 +00003079 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3080 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003081
Chris Lattner01cf8db2011-07-20 06:58:45 +00003082 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003083 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3084 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003085
Douglas Gregor968f23a2011-01-03 19:31:53 +00003086 // Determine whether the set of unexpanded parameter packs can and should
3087 // be expanded.
3088 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003089 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003090 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3091 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003092 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3093 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003094 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003095 Expand, RetainExpansion,
3096 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003097 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003098
Douglas Gregor968f23a2011-01-03 19:31:53 +00003099 if (!Expand) {
3100 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003101 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003102 // expansion.
3103 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3104 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3105 if (OutPattern.isInvalid())
3106 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003107
3108 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003109 Expansion->getEllipsisLoc(),
3110 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003111 if (Out.isInvalid())
3112 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003113
Douglas Gregor968f23a2011-01-03 19:31:53 +00003114 if (ArgChanged)
3115 *ArgChanged = true;
3116 Outputs.push_back(Out.get());
3117 continue;
3118 }
John McCall542e7c62011-07-06 07:30:07 +00003119
3120 // Record right away that the argument was changed. This needs
3121 // to happen even if the array expands to nothing.
3122 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003123
Douglas Gregor968f23a2011-01-03 19:31:53 +00003124 // The transform has determined that we should perform an elementwise
3125 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003126 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003127 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3128 ExprResult Out = getDerived().TransformExpr(Pattern);
3129 if (Out.isInvalid())
3130 return true;
3131
Richard Smith9467be42014-06-06 17:33:35 +00003132 // FIXME: Can this happen? We should not try to expand the pack
3133 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003134 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003135 Out = getDerived().RebuildPackExpansion(
3136 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003137 if (Out.isInvalid())
3138 return true;
3139 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003140
Douglas Gregor968f23a2011-01-03 19:31:53 +00003141 Outputs.push_back(Out.get());
3142 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003143
Richard Smith9467be42014-06-06 17:33:35 +00003144 // If we're supposed to retain a pack expansion, do so by temporarily
3145 // forgetting the partially-substituted parameter pack.
3146 if (RetainExpansion) {
3147 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3148
3149 ExprResult Out = getDerived().TransformExpr(Pattern);
3150 if (Out.isInvalid())
3151 return true;
3152
3153 Out = getDerived().RebuildPackExpansion(
3154 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3155 if (Out.isInvalid())
3156 return true;
3157
3158 Outputs.push_back(Out.get());
3159 }
3160
Douglas Gregor968f23a2011-01-03 19:31:53 +00003161 continue;
3162 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003163
Richard Smithd59b8322012-12-19 01:39:02 +00003164 ExprResult Result =
3165 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3166 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003167 if (Result.isInvalid())
3168 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003169
Douglas Gregora3efea12011-01-03 19:04:46 +00003170 if (Result.get() != Inputs[I] && ArgChanged)
3171 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003172
3173 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003174 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003175
Douglas Gregora3efea12011-01-03 19:04:46 +00003176 return false;
3177}
3178
3179template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003180NestedNameSpecifierLoc
3181TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3182 NestedNameSpecifierLoc NNS,
3183 QualType ObjectType,
3184 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003185 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003186 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003187 Qualifier = Qualifier.getPrefix())
3188 Qualifiers.push_back(Qualifier);
3189
3190 CXXScopeSpec SS;
3191 while (!Qualifiers.empty()) {
3192 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3193 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003194
Douglas Gregor14454802011-02-25 02:25:35 +00003195 switch (QNNS->getKind()) {
3196 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003197 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003198 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003199 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003200 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003201 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003202 FirstQualifierInScope, false))
3203 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003204
Douglas Gregor14454802011-02-25 02:25:35 +00003205 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003206
Douglas Gregor14454802011-02-25 02:25:35 +00003207 case NestedNameSpecifier::Namespace: {
3208 NamespaceDecl *NS
3209 = cast_or_null<NamespaceDecl>(
3210 getDerived().TransformDecl(
3211 Q.getLocalBeginLoc(),
3212 QNNS->getAsNamespace()));
3213 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3214 break;
3215 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003216
Douglas Gregor14454802011-02-25 02:25:35 +00003217 case NestedNameSpecifier::NamespaceAlias: {
3218 NamespaceAliasDecl *Alias
3219 = cast_or_null<NamespaceAliasDecl>(
3220 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3221 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003222 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003223 Q.getLocalEndLoc());
3224 break;
3225 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003226
Douglas Gregor14454802011-02-25 02:25:35 +00003227 case NestedNameSpecifier::Global:
3228 // There is no meaningful transformation that one could perform on the
3229 // global scope.
3230 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3231 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003232
Nikola Smiljanic67860242014-09-26 00:28:20 +00003233 case NestedNameSpecifier::Super: {
3234 CXXRecordDecl *RD =
3235 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3236 SourceLocation(), QNNS->getAsRecordDecl()));
3237 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3238 break;
3239 }
3240
Douglas Gregor14454802011-02-25 02:25:35 +00003241 case NestedNameSpecifier::TypeSpecWithTemplate:
3242 case NestedNameSpecifier::TypeSpec: {
3243 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3244 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003245
Douglas Gregor14454802011-02-25 02:25:35 +00003246 if (!TL)
3247 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003248
Douglas Gregor14454802011-02-25 02:25:35 +00003249 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003250 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003251 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003252 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003253 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003254 if (TL.getType()->isEnumeralType())
3255 SemaRef.Diag(TL.getBeginLoc(),
3256 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003257 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3258 Q.getLocalEndLoc());
3259 break;
3260 }
Richard Trieude756fb2011-05-07 01:36:37 +00003261 // If the nested-name-specifier is an invalid type def, don't emit an
3262 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003263 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3264 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003265 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003266 << TL.getType() << SS.getRange();
3267 }
Douglas Gregor14454802011-02-25 02:25:35 +00003268 return NestedNameSpecifierLoc();
3269 }
Douglas Gregore16af532011-02-28 18:50:33 +00003270 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003271
Douglas Gregore16af532011-02-28 18:50:33 +00003272 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003273 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003274 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003275 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003276
Douglas Gregor14454802011-02-25 02:25:35 +00003277 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003278 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003279 !getDerived().AlwaysRebuild())
3280 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003281
3282 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003283 // nested-name-specifier, do so.
3284 if (SS.location_size() == NNS.getDataLength() &&
3285 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3286 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3287
3288 // Allocate new nested-name-specifier location information.
3289 return SS.getWithLocInContext(SemaRef.Context);
3290}
3291
3292template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003293DeclarationNameInfo
3294TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003295::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003296 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003297 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003298 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003299
3300 switch (Name.getNameKind()) {
3301 case DeclarationName::Identifier:
3302 case DeclarationName::ObjCZeroArgSelector:
3303 case DeclarationName::ObjCOneArgSelector:
3304 case DeclarationName::ObjCMultiArgSelector:
3305 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003306 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003307 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003308 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003309
Douglas Gregorf816bd72009-09-03 22:13:48 +00003310 case DeclarationName::CXXConstructorName:
3311 case DeclarationName::CXXDestructorName:
3312 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003313 TypeSourceInfo *NewTInfo;
3314 CanQualType NewCanTy;
3315 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003316 NewTInfo = getDerived().TransformType(OldTInfo);
3317 if (!NewTInfo)
3318 return DeclarationNameInfo();
3319 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003320 }
3321 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003322 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003323 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003324 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003325 if (NewT.isNull())
3326 return DeclarationNameInfo();
3327 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3328 }
Mike Stump11289f42009-09-09 15:08:12 +00003329
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003330 DeclarationName NewName
3331 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3332 NewCanTy);
3333 DeclarationNameInfo NewNameInfo(NameInfo);
3334 NewNameInfo.setName(NewName);
3335 NewNameInfo.setNamedTypeInfo(NewTInfo);
3336 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003337 }
Mike Stump11289f42009-09-09 15:08:12 +00003338 }
3339
David Blaikie83d382b2011-09-23 05:06:16 +00003340 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003341}
3342
3343template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003344TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003345TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3346 TemplateName Name,
3347 SourceLocation NameLoc,
3348 QualType ObjectType,
3349 NamedDecl *FirstQualifierInScope) {
3350 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3351 TemplateDecl *Template = QTN->getTemplateDecl();
3352 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003353
Douglas Gregor9db53502011-03-02 18:07:45 +00003354 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 SS.getScopeRep() == QTN->getQualifier() &&
3362 TransTemplate == Template)
3363 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003364
Douglas Gregor9db53502011-03-02 18:07:45 +00003365 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3366 TransTemplate);
3367 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003368
Douglas Gregor9db53502011-03-02 18:07:45 +00003369 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3370 if (SS.getScopeRep()) {
3371 // These apply to the scope specifier, not the template.
3372 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003373 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003374 }
3375
Douglas Gregor9db53502011-03-02 18:07:45 +00003376 if (!getDerived().AlwaysRebuild() &&
3377 SS.getScopeRep() == DTN->getQualifier() &&
3378 ObjectType.isNull())
3379 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003380
Douglas Gregor9db53502011-03-02 18:07:45 +00003381 if (DTN->isIdentifier()) {
3382 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003383 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003384 NameLoc,
3385 ObjectType,
3386 FirstQualifierInScope);
3387 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003388
Douglas Gregor9db53502011-03-02 18:07:45 +00003389 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3390 ObjectType);
3391 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003392
Douglas Gregor9db53502011-03-02 18:07:45 +00003393 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3394 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003395 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003396 Template));
3397 if (!TransTemplate)
3398 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003399
Douglas Gregor9db53502011-03-02 18:07:45 +00003400 if (!getDerived().AlwaysRebuild() &&
3401 TransTemplate == Template)
3402 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003403
Douglas Gregor9db53502011-03-02 18:07:45 +00003404 return TemplateName(TransTemplate);
3405 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003406
Douglas Gregor9db53502011-03-02 18:07:45 +00003407 if (SubstTemplateTemplateParmPackStorage *SubstPack
3408 = Name.getAsSubstTemplateTemplateParmPack()) {
3409 TemplateTemplateParmDecl *TransParam
3410 = cast_or_null<TemplateTemplateParmDecl>(
3411 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3412 if (!TransParam)
3413 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003414
Douglas Gregor9db53502011-03-02 18:07:45 +00003415 if (!getDerived().AlwaysRebuild() &&
3416 TransParam == SubstPack->getParameterPack())
3417 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003418
3419 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003420 SubstPack->getArgumentPack());
3421 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003422
Douglas Gregor9db53502011-03-02 18:07:45 +00003423 // These should be getting filtered out before they reach the AST.
3424 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003425}
3426
3427template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003428void TreeTransform<Derived>::InventTemplateArgumentLoc(
3429 const TemplateArgument &Arg,
3430 TemplateArgumentLoc &Output) {
3431 SourceLocation Loc = getDerived().getBaseLocation();
3432 switch (Arg.getKind()) {
3433 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003434 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003435 break;
3436
3437 case TemplateArgument::Type:
3438 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003439 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003440
John McCall0ad16662009-10-29 08:12:44 +00003441 break;
3442
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003443 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003444 case TemplateArgument::TemplateExpansion: {
3445 NestedNameSpecifierLocBuilder Builder;
3446 TemplateName Template = Arg.getAsTemplate();
3447 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3448 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3449 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3450 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003451
Douglas Gregor9d802122011-03-02 17:09:35 +00003452 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003453 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003454 Builder.getWithLocInContext(SemaRef.Context),
3455 Loc);
3456 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003457 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003458 Builder.getWithLocInContext(SemaRef.Context),
3459 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003460
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003461 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003462 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003463
John McCall0ad16662009-10-29 08:12:44 +00003464 case TemplateArgument::Expression:
3465 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3466 break;
3467
3468 case TemplateArgument::Declaration:
3469 case TemplateArgument::Integral:
3470 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003471 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003472 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003473 break;
3474 }
3475}
3476
3477template<typename Derived>
3478bool TreeTransform<Derived>::TransformTemplateArgument(
3479 const TemplateArgumentLoc &Input,
3480 TemplateArgumentLoc &Output) {
3481 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003482 switch (Arg.getKind()) {
3483 case TemplateArgument::Null:
3484 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003485 case TemplateArgument::Pack:
3486 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003487 case TemplateArgument::NullPtr:
3488 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003489
Douglas Gregore922c772009-08-04 22:27:00 +00003490 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003491 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003492 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003493 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003494
3495 DI = getDerived().TransformType(DI);
3496 if (!DI) return true;
3497
3498 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3499 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003500 }
Mike Stump11289f42009-09-09 15:08:12 +00003501
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003502 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003503 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3504 if (QualifierLoc) {
3505 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3506 if (!QualifierLoc)
3507 return true;
3508 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003509
Douglas Gregordf846d12011-03-02 18:46:51 +00003510 CXXScopeSpec SS;
3511 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003512 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003513 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3514 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003515 if (Template.isNull())
3516 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003517
Douglas Gregor9d802122011-03-02 17:09:35 +00003518 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003519 Input.getTemplateNameLoc());
3520 return false;
3521 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003522
3523 case TemplateArgument::TemplateExpansion:
3524 llvm_unreachable("Caller should expand pack expansions");
3525
Douglas Gregore922c772009-08-04 22:27:00 +00003526 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003527 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003528 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003529 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003530
John McCall0ad16662009-10-29 08:12:44 +00003531 Expr *InputExpr = Input.getSourceExpression();
3532 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3533
Chris Lattnercdb591a2011-04-25 20:37:58 +00003534 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003535 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003536 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003537 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003538 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003539 }
Douglas Gregore922c772009-08-04 22:27:00 +00003540 }
Mike Stump11289f42009-09-09 15:08:12 +00003541
Douglas Gregore922c772009-08-04 22:27:00 +00003542 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003543 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003544}
3545
Douglas Gregorfe921a72010-12-20 23:36:19 +00003546/// \brief Iterator adaptor that invents template argument location information
3547/// for each of the template arguments in its underlying iterator.
3548template<typename Derived, typename InputIterator>
3549class TemplateArgumentLocInventIterator {
3550 TreeTransform<Derived> &Self;
3551 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003552
Douglas Gregorfe921a72010-12-20 23:36:19 +00003553public:
3554 typedef TemplateArgumentLoc value_type;
3555 typedef TemplateArgumentLoc reference;
3556 typedef typename std::iterator_traits<InputIterator>::difference_type
3557 difference_type;
3558 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003559
Douglas Gregorfe921a72010-12-20 23:36:19 +00003560 class pointer {
3561 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003562
Douglas Gregorfe921a72010-12-20 23:36:19 +00003563 public:
3564 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003565
Douglas Gregorfe921a72010-12-20 23:36:19 +00003566 const TemplateArgumentLoc *operator->() const { return &Arg; }
3567 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003568
Douglas Gregorfe921a72010-12-20 23:36:19 +00003569 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003570
Douglas Gregorfe921a72010-12-20 23:36:19 +00003571 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3572 InputIterator Iter)
3573 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003574
Douglas Gregorfe921a72010-12-20 23:36:19 +00003575 TemplateArgumentLocInventIterator &operator++() {
3576 ++Iter;
3577 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003578 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003579
Douglas Gregorfe921a72010-12-20 23:36:19 +00003580 TemplateArgumentLocInventIterator operator++(int) {
3581 TemplateArgumentLocInventIterator Old(*this);
3582 ++(*this);
3583 return Old;
3584 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003585
Douglas Gregorfe921a72010-12-20 23:36:19 +00003586 reference operator*() const {
3587 TemplateArgumentLoc Result;
3588 Self.InventTemplateArgumentLoc(*Iter, Result);
3589 return Result;
3590 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003591
Douglas Gregorfe921a72010-12-20 23:36:19 +00003592 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003593
Douglas Gregorfe921a72010-12-20 23:36:19 +00003594 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3595 const TemplateArgumentLocInventIterator &Y) {
3596 return X.Iter == Y.Iter;
3597 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003598
Douglas Gregorfe921a72010-12-20 23:36:19 +00003599 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3600 const TemplateArgumentLocInventIterator &Y) {
3601 return X.Iter != Y.Iter;
3602 }
3603};
Chad Rosier1dcde962012-08-08 18:46:20 +00003604
Douglas Gregor42cafa82010-12-20 17:42:22 +00003605template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003606template<typename InputIterator>
3607bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3608 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003609 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003610 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003611 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003612 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003613
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003614 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3615 // Unpack argument packs, which we translate them into separate
3616 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003617 // FIXME: We could do much better if we could guarantee that the
3618 // TemplateArgumentLocInfo for the pack expansion would be usable for
3619 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003620 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003621 TemplateArgument::pack_iterator>
3622 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003623 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003624 In.getArgument().pack_begin()),
3625 PackLocIterator(*this,
3626 In.getArgument().pack_end()),
3627 Outputs))
3628 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003629
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003630 continue;
3631 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003632
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003633 if (In.getArgument().isPackExpansion()) {
3634 // We have a pack expansion, for which we will be substituting into
3635 // the pattern.
3636 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003637 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003638 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003639 = getSema().getTemplateArgumentPackExpansionPattern(
3640 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003641
Chris Lattner01cf8db2011-07-20 06:58:45 +00003642 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003643 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3644 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003645
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003646 // Determine whether the set of unexpanded parameter packs can and should
3647 // be expanded.
3648 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003649 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003650 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003651 if (getDerived().TryExpandParameterPacks(Ellipsis,
3652 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003653 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003654 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003655 RetainExpansion,
3656 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003657 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003658
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003659 if (!Expand) {
3660 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003661 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003662 // expansion.
3663 TemplateArgumentLoc OutPattern;
3664 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3665 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3666 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003667
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003668 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3669 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003670 if (Out.getArgument().isNull())
3671 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003672
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003673 Outputs.addArgument(Out);
3674 continue;
3675 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003676
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003677 // The transform has determined that we should perform an elementwise
3678 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003679 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003680 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3681
3682 if (getDerived().TransformTemplateArgument(Pattern, Out))
3683 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003684
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003685 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003686 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3687 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003688 if (Out.getArgument().isNull())
3689 return true;
3690 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003691
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003692 Outputs.addArgument(Out);
3693 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003694
Douglas Gregor48d24112011-01-10 20:53:55 +00003695 // If we're supposed to retain a pack expansion, do so by temporarily
3696 // forgetting the partially-substituted parameter pack.
3697 if (RetainExpansion) {
3698 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003699
Douglas Gregor48d24112011-01-10 20:53:55 +00003700 if (getDerived().TransformTemplateArgument(Pattern, Out))
3701 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003702
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003703 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3704 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003705 if (Out.getArgument().isNull())
3706 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003707
Douglas Gregor48d24112011-01-10 20:53:55 +00003708 Outputs.addArgument(Out);
3709 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003710
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003711 continue;
3712 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003713
3714 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003715 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003716 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003717
Douglas Gregor42cafa82010-12-20 17:42:22 +00003718 Outputs.addArgument(Out);
3719 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003720
Douglas Gregor42cafa82010-12-20 17:42:22 +00003721 return false;
3722
3723}
3724
Douglas Gregord6ff3322009-08-04 16:50:30 +00003725//===----------------------------------------------------------------------===//
3726// Type transformation
3727//===----------------------------------------------------------------------===//
3728
3729template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003730QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003731 if (getDerived().AlreadyTransformed(T))
3732 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003733
John McCall550e0c22009-10-21 00:40:46 +00003734 // Temporary workaround. All of these transformations should
3735 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003736 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3737 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003738
John McCall31f82722010-11-12 08:19:04 +00003739 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003740
John McCall550e0c22009-10-21 00:40:46 +00003741 if (!NewDI)
3742 return QualType();
3743
3744 return NewDI->getType();
3745}
3746
3747template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003748TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003749 // Refine the base location to the type's location.
3750 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3751 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003752 if (getDerived().AlreadyTransformed(DI->getType()))
3753 return DI;
3754
3755 TypeLocBuilder TLB;
3756
3757 TypeLoc TL = DI->getTypeLoc();
3758 TLB.reserve(TL.getFullDataSize());
3759
John McCall31f82722010-11-12 08:19:04 +00003760 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003761 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003762 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003763
John McCallbcd03502009-12-07 02:54:59 +00003764 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003765}
3766
3767template<typename Derived>
3768QualType
John McCall31f82722010-11-12 08:19:04 +00003769TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003770 switch (T.getTypeLocClass()) {
3771#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003772#define TYPELOC(CLASS, PARENT) \
3773 case TypeLoc::CLASS: \
3774 return getDerived().Transform##CLASS##Type(TLB, \
3775 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003776#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003777 }
Mike Stump11289f42009-09-09 15:08:12 +00003778
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003779 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003780}
3781
3782/// FIXME: By default, this routine adds type qualifiers only to types
3783/// that can have qualifiers, and silently suppresses those qualifiers
3784/// that are not permitted (e.g., qualifiers on reference or function
3785/// types). This is the right thing for template instantiation, but
3786/// probably not for other clients.
3787template<typename Derived>
3788QualType
3789TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003790 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003791 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003792
John McCall31f82722010-11-12 08:19:04 +00003793 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003794 if (Result.isNull())
3795 return QualType();
3796
3797 // Silently suppress qualifiers if the result type can't be qualified.
3798 // FIXME: this is the right thing for template instantiation, but
3799 // probably not for other clients.
3800 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003801 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003802
John McCall31168b02011-06-15 23:02:42 +00003803 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003804 // resulting type.
3805 if (Quals.hasObjCLifetime()) {
3806 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3807 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003808 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003809 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003810 // A lifetime qualifier applied to a substituted template parameter
3811 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003812 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003813 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003814 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3815 QualType Replacement = SubstTypeParam->getReplacementType();
3816 Qualifiers Qs = Replacement.getQualifiers();
3817 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003818 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003819 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3820 Qs);
3821 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003822 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003823 Replacement);
3824 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003825 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3826 // 'auto' types behave the same way as template parameters.
3827 QualType Deduced = AutoTy->getDeducedType();
3828 Qualifiers Qs = Deduced.getQualifiers();
3829 Qs.removeObjCLifetime();
3830 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3831 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003832 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3833 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003834 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003835 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003836 // Otherwise, complain about the addition of a qualifier to an
3837 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003838 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003839 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003840 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003841
Douglas Gregore46db902011-06-17 22:11:49 +00003842 Quals.removeObjCLifetime();
3843 }
3844 }
3845 }
John McCallcb0f89a2010-06-05 06:41:15 +00003846 if (!Quals.empty()) {
3847 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003848 // BuildQualifiedType might not add qualifiers if they are invalid.
3849 if (Result.hasLocalQualifiers())
3850 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003851 // No location information to preserve.
3852 }
John McCall550e0c22009-10-21 00:40:46 +00003853
3854 return Result;
3855}
3856
Douglas Gregor14454802011-02-25 02:25:35 +00003857template<typename Derived>
3858TypeLoc
3859TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3860 QualType ObjectType,
3861 NamedDecl *UnqualLookup,
3862 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003863 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003864 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003865
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003866 TypeSourceInfo *TSI =
3867 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3868 if (TSI)
3869 return TSI->getTypeLoc();
3870 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003871}
3872
Douglas Gregor579c15f2011-03-02 18:32:08 +00003873template<typename Derived>
3874TypeSourceInfo *
3875TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3876 QualType ObjectType,
3877 NamedDecl *UnqualLookup,
3878 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003879 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003880 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003881
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003882 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3883 UnqualLookup, SS);
3884}
3885
3886template <typename Derived>
3887TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3888 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3889 CXXScopeSpec &SS) {
3890 QualType T = TL.getType();
3891 assert(!getDerived().AlreadyTransformed(T));
3892
Douglas Gregor579c15f2011-03-02 18:32:08 +00003893 TypeLocBuilder TLB;
3894 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003895
Douglas Gregor579c15f2011-03-02 18:32:08 +00003896 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003897 TemplateSpecializationTypeLoc SpecTL =
3898 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003899
Douglas Gregor579c15f2011-03-02 18:32:08 +00003900 TemplateName Template
3901 = getDerived().TransformTemplateName(SS,
3902 SpecTL.getTypePtr()->getTemplateName(),
3903 SpecTL.getTemplateNameLoc(),
3904 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003905 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003906 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003907
3908 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003909 Template);
3910 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003911 DependentTemplateSpecializationTypeLoc SpecTL =
3912 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003913
Douglas Gregor579c15f2011-03-02 18:32:08 +00003914 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003915 = getDerived().RebuildTemplateName(SS,
3916 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003917 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003918 ObjectType, UnqualLookup);
3919 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003920 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003921
3922 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003923 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003924 Template,
3925 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003926 } else {
3927 // Nothing special needs to be done for these.
3928 Result = getDerived().TransformType(TLB, TL);
3929 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003930
3931 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003932 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003933
Douglas Gregor579c15f2011-03-02 18:32:08 +00003934 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3935}
3936
John McCall550e0c22009-10-21 00:40:46 +00003937template <class TyLoc> static inline
3938QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3939 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3940 NewT.setNameLoc(T.getNameLoc());
3941 return T.getType();
3942}
3943
John McCall550e0c22009-10-21 00:40:46 +00003944template<typename Derived>
3945QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003946 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003947 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3948 NewT.setBuiltinLoc(T.getBuiltinLoc());
3949 if (T.needsExtraLocalData())
3950 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3951 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003952}
Mike Stump11289f42009-09-09 15:08:12 +00003953
Douglas Gregord6ff3322009-08-04 16:50:30 +00003954template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003955QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003956 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003957 // FIXME: recurse?
3958 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003959}
Mike Stump11289f42009-09-09 15:08:12 +00003960
Reid Kleckner0503a872013-12-05 01:23:43 +00003961template <typename Derived>
3962QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3963 AdjustedTypeLoc TL) {
3964 // Adjustments applied during transformation are handled elsewhere.
3965 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3966}
3967
Douglas Gregord6ff3322009-08-04 16:50:30 +00003968template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003969QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3970 DecayedTypeLoc TL) {
3971 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3972 if (OriginalType.isNull())
3973 return QualType();
3974
3975 QualType Result = TL.getType();
3976 if (getDerived().AlwaysRebuild() ||
3977 OriginalType != TL.getOriginalLoc().getType())
3978 Result = SemaRef.Context.getDecayedType(OriginalType);
3979 TLB.push<DecayedTypeLoc>(Result);
3980 // Nothing to set for DecayedTypeLoc.
3981 return Result;
3982}
3983
3984template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003985QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003986 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003987 QualType PointeeType
3988 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003989 if (PointeeType.isNull())
3990 return QualType();
3991
3992 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003993 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003994 // A dependent pointer type 'T *' has is being transformed such
3995 // that an Objective-C class type is being replaced for 'T'. The
3996 // resulting pointer type is an ObjCObjectPointerType, not a
3997 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003998 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003999
John McCall8b07ec22010-05-15 11:32:37 +00004000 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4001 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004002 return Result;
4003 }
John McCall31f82722010-11-12 08:19:04 +00004004
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004005 if (getDerived().AlwaysRebuild() ||
4006 PointeeType != TL.getPointeeLoc().getType()) {
4007 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4008 if (Result.isNull())
4009 return QualType();
4010 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004011
John McCall31168b02011-06-15 23:02:42 +00004012 // Objective-C ARC can add lifetime qualifiers to the type that we're
4013 // pointing to.
4014 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004015
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004016 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4017 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004018 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004019}
Mike Stump11289f42009-09-09 15:08:12 +00004020
4021template<typename Derived>
4022QualType
John McCall550e0c22009-10-21 00:40:46 +00004023TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004024 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004025 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004026 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4027 if (PointeeType.isNull())
4028 return QualType();
4029
4030 QualType Result = TL.getType();
4031 if (getDerived().AlwaysRebuild() ||
4032 PointeeType != TL.getPointeeLoc().getType()) {
4033 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004034 TL.getSigilLoc());
4035 if (Result.isNull())
4036 return QualType();
4037 }
4038
Douglas Gregor049211a2010-04-22 16:50:51 +00004039 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004040 NewT.setSigilLoc(TL.getSigilLoc());
4041 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004042}
4043
John McCall70dd5f62009-10-30 00:06:24 +00004044/// Transforms a reference type. Note that somewhat paradoxically we
4045/// don't care whether the type itself is an l-value type or an r-value
4046/// type; we only care if the type was *written* as an l-value type
4047/// or an r-value type.
4048template<typename Derived>
4049QualType
4050TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004051 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004052 const ReferenceType *T = TL.getTypePtr();
4053
4054 // Note that this works with the pointee-as-written.
4055 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4056 if (PointeeType.isNull())
4057 return QualType();
4058
4059 QualType Result = TL.getType();
4060 if (getDerived().AlwaysRebuild() ||
4061 PointeeType != T->getPointeeTypeAsWritten()) {
4062 Result = getDerived().RebuildReferenceType(PointeeType,
4063 T->isSpelledAsLValue(),
4064 TL.getSigilLoc());
4065 if (Result.isNull())
4066 return QualType();
4067 }
4068
John McCall31168b02011-06-15 23:02:42 +00004069 // Objective-C ARC can add lifetime qualifiers to the type that we're
4070 // referring to.
4071 TLB.TypeWasModifiedSafely(
4072 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4073
John McCall70dd5f62009-10-30 00:06:24 +00004074 // r-value references can be rebuilt as l-value references.
4075 ReferenceTypeLoc NewTL;
4076 if (isa<LValueReferenceType>(Result))
4077 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4078 else
4079 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4080 NewTL.setSigilLoc(TL.getSigilLoc());
4081
4082 return Result;
4083}
4084
Mike Stump11289f42009-09-09 15:08:12 +00004085template<typename Derived>
4086QualType
John McCall550e0c22009-10-21 00:40:46 +00004087TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004088 LValueReferenceTypeLoc TL) {
4089 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004090}
4091
Mike Stump11289f42009-09-09 15:08:12 +00004092template<typename Derived>
4093QualType
John McCall550e0c22009-10-21 00:40:46 +00004094TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004095 RValueReferenceTypeLoc TL) {
4096 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004097}
Mike Stump11289f42009-09-09 15:08:12 +00004098
Douglas Gregord6ff3322009-08-04 16:50:30 +00004099template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004100QualType
John McCall550e0c22009-10-21 00:40:46 +00004101TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004102 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004103 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004104 if (PointeeType.isNull())
4105 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004106
Abramo Bagnara509357842011-03-05 14:42:21 +00004107 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004108 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004109 if (OldClsTInfo) {
4110 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4111 if (!NewClsTInfo)
4112 return QualType();
4113 }
4114
4115 const MemberPointerType *T = TL.getTypePtr();
4116 QualType OldClsType = QualType(T->getClass(), 0);
4117 QualType NewClsType;
4118 if (NewClsTInfo)
4119 NewClsType = NewClsTInfo->getType();
4120 else {
4121 NewClsType = getDerived().TransformType(OldClsType);
4122 if (NewClsType.isNull())
4123 return QualType();
4124 }
Mike Stump11289f42009-09-09 15:08:12 +00004125
John McCall550e0c22009-10-21 00:40:46 +00004126 QualType Result = TL.getType();
4127 if (getDerived().AlwaysRebuild() ||
4128 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004129 NewClsType != OldClsType) {
4130 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004131 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004132 if (Result.isNull())
4133 return QualType();
4134 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004135
Reid Kleckner0503a872013-12-05 01:23:43 +00004136 // If we had to adjust the pointee type when building a member pointer, make
4137 // sure to push TypeLoc info for it.
4138 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4139 if (MPT && PointeeType != MPT->getPointeeType()) {
4140 assert(isa<AdjustedType>(MPT->getPointeeType()));
4141 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4142 }
4143
John McCall550e0c22009-10-21 00:40:46 +00004144 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4145 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004146 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004147
4148 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004149}
4150
Mike Stump11289f42009-09-09 15:08:12 +00004151template<typename Derived>
4152QualType
John McCall550e0c22009-10-21 00:40:46 +00004153TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004154 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004155 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004156 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004157 if (ElementType.isNull())
4158 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004159
John McCall550e0c22009-10-21 00:40:46 +00004160 QualType Result = TL.getType();
4161 if (getDerived().AlwaysRebuild() ||
4162 ElementType != T->getElementType()) {
4163 Result = getDerived().RebuildConstantArrayType(ElementType,
4164 T->getSizeModifier(),
4165 T->getSize(),
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 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004171
4172 // We might have either a ConstantArrayType or a VariableArrayType now:
4173 // a ConstantArrayType is allowed to have an element type which is a
4174 // VariableArrayType if the type is dependent. Fortunately, all array
4175 // types have the same location layout.
4176 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004177 NewTL.setLBracketLoc(TL.getLBracketLoc());
4178 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004179
John McCall550e0c22009-10-21 00:40:46 +00004180 Expr *Size = TL.getSizeExpr();
4181 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004182 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4183 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004184 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4185 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004186 }
4187 NewTL.setSizeExpr(Size);
4188
4189 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004190}
Mike Stump11289f42009-09-09 15:08:12 +00004191
Douglas Gregord6ff3322009-08-04 16:50:30 +00004192template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004193QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004194 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004195 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004196 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004197 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004198 if (ElementType.isNull())
4199 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004200
John McCall550e0c22009-10-21 00:40:46 +00004201 QualType Result = TL.getType();
4202 if (getDerived().AlwaysRebuild() ||
4203 ElementType != T->getElementType()) {
4204 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004205 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004206 T->getIndexTypeCVRQualifiers(),
4207 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004208 if (Result.isNull())
4209 return QualType();
4210 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004211
John McCall550e0c22009-10-21 00:40:46 +00004212 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4213 NewTL.setLBracketLoc(TL.getLBracketLoc());
4214 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004215 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004216
4217 return Result;
4218}
4219
4220template<typename Derived>
4221QualType
4222TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004223 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004224 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004225 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4226 if (ElementType.isNull())
4227 return QualType();
4228
John McCalldadc5752010-08-24 06:29:42 +00004229 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004230 = getDerived().TransformExpr(T->getSizeExpr());
4231 if (SizeResult.isInvalid())
4232 return QualType();
4233
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004234 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004235
4236 QualType Result = TL.getType();
4237 if (getDerived().AlwaysRebuild() ||
4238 ElementType != T->getElementType() ||
4239 Size != T->getSizeExpr()) {
4240 Result = getDerived().RebuildVariableArrayType(ElementType,
4241 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004242 Size,
John McCall550e0c22009-10-21 00:40:46 +00004243 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004244 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004245 if (Result.isNull())
4246 return QualType();
4247 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004248
Serge Pavlov774c6d02014-02-06 03:49:11 +00004249 // We might have constant size array now, but fortunately it has the same
4250 // location layout.
4251 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004252 NewTL.setLBracketLoc(TL.getLBracketLoc());
4253 NewTL.setRBracketLoc(TL.getRBracketLoc());
4254 NewTL.setSizeExpr(Size);
4255
4256 return Result;
4257}
4258
4259template<typename Derived>
4260QualType
4261TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004262 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004263 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004264 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4265 if (ElementType.isNull())
4266 return QualType();
4267
Richard Smith764d2fe2011-12-20 02:08:33 +00004268 // Array bounds are constant expressions.
4269 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4270 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004271
John McCall33ddac02011-01-19 10:06:00 +00004272 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4273 Expr *origSize = TL.getSizeExpr();
4274 if (!origSize) origSize = T->getSizeExpr();
4275
4276 ExprResult sizeResult
4277 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004278 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004279 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004280 return QualType();
4281
John McCall33ddac02011-01-19 10:06:00 +00004282 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004283
4284 QualType Result = TL.getType();
4285 if (getDerived().AlwaysRebuild() ||
4286 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004287 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004288 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4289 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004290 size,
John McCall550e0c22009-10-21 00:40:46 +00004291 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004292 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004293 if (Result.isNull())
4294 return QualType();
4295 }
John McCall550e0c22009-10-21 00:40:46 +00004296
4297 // We might have any sort of array type now, but fortunately they
4298 // all have the same location layout.
4299 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4300 NewTL.setLBracketLoc(TL.getLBracketLoc());
4301 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004302 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004303
4304 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004305}
Mike Stump11289f42009-09-09 15:08:12 +00004306
4307template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004308QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004309 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004310 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004311 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004312
4313 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004314 QualType ElementType = getDerived().TransformType(T->getElementType());
4315 if (ElementType.isNull())
4316 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004317
Richard Smith764d2fe2011-12-20 02:08:33 +00004318 // Vector sizes are constant expressions.
4319 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4320 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004321
John McCalldadc5752010-08-24 06:29:42 +00004322 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004323 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004324 if (Size.isInvalid())
4325 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004326
John McCall550e0c22009-10-21 00:40:46 +00004327 QualType Result = TL.getType();
4328 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004329 ElementType != T->getElementType() ||
4330 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004331 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004332 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004333 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004334 if (Result.isNull())
4335 return QualType();
4336 }
John McCall550e0c22009-10-21 00:40:46 +00004337
4338 // Result might be dependent or not.
4339 if (isa<DependentSizedExtVectorType>(Result)) {
4340 DependentSizedExtVectorTypeLoc NewTL
4341 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4342 NewTL.setNameLoc(TL.getNameLoc());
4343 } else {
4344 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4345 NewTL.setNameLoc(TL.getNameLoc());
4346 }
4347
4348 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004349}
Mike Stump11289f42009-09-09 15:08:12 +00004350
4351template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004352QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004353 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004354 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004355 QualType ElementType = getDerived().TransformType(T->getElementType());
4356 if (ElementType.isNull())
4357 return QualType();
4358
John McCall550e0c22009-10-21 00:40:46 +00004359 QualType Result = TL.getType();
4360 if (getDerived().AlwaysRebuild() ||
4361 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004362 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004363 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004364 if (Result.isNull())
4365 return QualType();
4366 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004367
John McCall550e0c22009-10-21 00:40:46 +00004368 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4369 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004370
John McCall550e0c22009-10-21 00:40:46 +00004371 return Result;
4372}
4373
4374template<typename Derived>
4375QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004376 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004377 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004378 QualType ElementType = getDerived().TransformType(T->getElementType());
4379 if (ElementType.isNull())
4380 return QualType();
4381
4382 QualType Result = TL.getType();
4383 if (getDerived().AlwaysRebuild() ||
4384 ElementType != T->getElementType()) {
4385 Result = getDerived().RebuildExtVectorType(ElementType,
4386 T->getNumElements(),
4387 /*FIXME*/ SourceLocation());
4388 if (Result.isNull())
4389 return QualType();
4390 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004391
John McCall550e0c22009-10-21 00:40:46 +00004392 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4393 NewTL.setNameLoc(TL.getNameLoc());
4394
4395 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004396}
Mike Stump11289f42009-09-09 15:08:12 +00004397
David Blaikie05785d12013-02-20 22:23:23 +00004398template <typename Derived>
4399ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4400 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4401 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004402 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004403 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004404
Douglas Gregor715e4612011-01-14 22:40:04 +00004405 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004406 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004407 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004408 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004409 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004410
Douglas Gregor715e4612011-01-14 22:40:04 +00004411 TypeLocBuilder TLB;
4412 TypeLoc NewTL = OldDI->getTypeLoc();
4413 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004414
4415 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004416 OldExpansionTL.getPatternLoc());
4417 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004418 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004419
4420 Result = RebuildPackExpansionType(Result,
4421 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004422 OldExpansionTL.getEllipsisLoc(),
4423 NumExpansions);
4424 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004425 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004426
Douglas Gregor715e4612011-01-14 22:40:04 +00004427 PackExpansionTypeLoc NewExpansionTL
4428 = TLB.push<PackExpansionTypeLoc>(Result);
4429 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4430 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4431 } else
4432 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004433 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004434 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004435
John McCall8fb0d9d2011-05-01 22:35:37 +00004436 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004437 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004438
4439 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4440 OldParm->getDeclContext(),
4441 OldParm->getInnerLocStart(),
4442 OldParm->getLocation(),
4443 OldParm->getIdentifier(),
4444 NewDI->getType(),
4445 NewDI,
4446 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004447 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004448 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4449 OldParm->getFunctionScopeIndex() + indexAdjustment);
4450 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004451}
4452
4453template<typename Derived>
4454bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004455 TransformFunctionTypeParams(SourceLocation Loc,
4456 ParmVarDecl **Params, unsigned NumParams,
4457 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004458 SmallVectorImpl<QualType> &OutParamTypes,
4459 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004460 int indexAdjustment = 0;
4461
Douglas Gregordd472162011-01-07 00:20:55 +00004462 for (unsigned i = 0; i != NumParams; ++i) {
4463 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004464 assert(OldParm->getFunctionScopeIndex() == i);
4465
David Blaikie05785d12013-02-20 22:23:23 +00004466 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004467 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004468 if (OldParm->isParameterPack()) {
4469 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004470 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004471
Douglas Gregor5499af42011-01-05 23:12:31 +00004472 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004473 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004474 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004475 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4476 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004477 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4478
Douglas Gregor5499af42011-01-05 23:12:31 +00004479 // Determine whether we should expand the parameter packs.
4480 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004481 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004482 Optional<unsigned> OrigNumExpansions =
4483 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004484 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004485 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4486 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004487 Unexpanded,
4488 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004489 RetainExpansion,
4490 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004491 return true;
4492 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004493
Douglas Gregor5499af42011-01-05 23:12:31 +00004494 if (ShouldExpand) {
4495 // Expand the function parameter pack into multiple, separate
4496 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004497 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004498 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004499 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004500 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004501 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004502 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004503 OrigNumExpansions,
4504 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004505 if (!NewParm)
4506 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004507
Douglas Gregordd472162011-01-07 00:20:55 +00004508 OutParamTypes.push_back(NewParm->getType());
4509 if (PVars)
4510 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004511 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004512
4513 // If we're supposed to retain a pack expansion, do so by temporarily
4514 // forgetting the partially-substituted parameter pack.
4515 if (RetainExpansion) {
4516 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004517 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004518 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004519 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004520 OrigNumExpansions,
4521 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004522 if (!NewParm)
4523 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004524
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004525 OutParamTypes.push_back(NewParm->getType());
4526 if (PVars)
4527 PVars->push_back(NewParm);
4528 }
4529
John McCall8fb0d9d2011-05-01 22:35:37 +00004530 // The next parameter should have the same adjustment as the
4531 // last thing we pushed, but we post-incremented indexAdjustment
4532 // on every push. Also, if we push nothing, the adjustment should
4533 // go down by one.
4534 indexAdjustment--;
4535
Douglas Gregor5499af42011-01-05 23:12:31 +00004536 // We're done with the pack expansion.
4537 continue;
4538 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004539
4540 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004541 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004542 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4543 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004544 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004545 NumExpansions,
4546 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004547 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004548 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004549 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004550 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004551
John McCall58f10c32010-03-11 09:03:00 +00004552 if (!NewParm)
4553 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004554
Douglas Gregordd472162011-01-07 00:20:55 +00004555 OutParamTypes.push_back(NewParm->getType());
4556 if (PVars)
4557 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004558 continue;
4559 }
John McCall58f10c32010-03-11 09:03:00 +00004560
4561 // Deal with the possibility that we don't have a parameter
4562 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004563 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004564 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004565 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004566 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004567 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004568 = dyn_cast<PackExpansionType>(OldType)) {
4569 // We have a function parameter pack that may need to be expanded.
4570 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004571 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004572 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004573
Douglas Gregor5499af42011-01-05 23:12:31 +00004574 // Determine whether we should expand the parameter packs.
4575 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004576 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004577 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004578 Unexpanded,
4579 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004580 RetainExpansion,
4581 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004582 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004583 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004584
Douglas Gregor5499af42011-01-05 23:12:31 +00004585 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004586 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004587 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004588 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004589 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4590 QualType NewType = getDerived().TransformType(Pattern);
4591 if (NewType.isNull())
4592 return true;
John McCall58f10c32010-03-11 09:03:00 +00004593
Douglas Gregordd472162011-01-07 00:20:55 +00004594 OutParamTypes.push_back(NewType);
4595 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004596 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004597 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004598
Douglas Gregor5499af42011-01-05 23:12:31 +00004599 // We're done with the pack expansion.
4600 continue;
4601 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004602
Douglas Gregor48d24112011-01-10 20:53:55 +00004603 // If we're supposed to retain a pack expansion, do so by temporarily
4604 // forgetting the partially-substituted parameter pack.
4605 if (RetainExpansion) {
4606 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4607 QualType NewType = getDerived().TransformType(Pattern);
4608 if (NewType.isNull())
4609 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004610
Douglas Gregor48d24112011-01-10 20:53:55 +00004611 OutParamTypes.push_back(NewType);
4612 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004613 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004614 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004615
Chad Rosier1dcde962012-08-08 18:46:20 +00004616 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004617 // expansion.
4618 OldType = Expansion->getPattern();
4619 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004620 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4621 NewType = getDerived().TransformType(OldType);
4622 } else {
4623 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004624 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004625
Douglas Gregor5499af42011-01-05 23:12:31 +00004626 if (NewType.isNull())
4627 return true;
4628
4629 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004630 NewType = getSema().Context.getPackExpansionType(NewType,
4631 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004632
Douglas Gregordd472162011-01-07 00:20:55 +00004633 OutParamTypes.push_back(NewType);
4634 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004635 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004636 }
4637
John McCall8fb0d9d2011-05-01 22:35:37 +00004638#ifndef NDEBUG
4639 if (PVars) {
4640 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4641 if (ParmVarDecl *parm = (*PVars)[i])
4642 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004643 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004644#endif
4645
4646 return false;
4647}
John McCall58f10c32010-03-11 09:03:00 +00004648
4649template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004650QualType
John McCall550e0c22009-10-21 00:40:46 +00004651TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004652 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004653 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004654 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004655 return getDerived().TransformFunctionProtoType(
4656 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004657 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4658 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4659 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004660 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004661}
4662
Richard Smith2e321552014-11-12 02:00:47 +00004663template<typename Derived> template<typename Fn>
4664QualType TreeTransform<Derived>::TransformFunctionProtoType(
4665 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4666 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004667 // Transform the parameters and return type.
4668 //
Richard Smithf623c962012-04-17 00:58:00 +00004669 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004670 // When the function has a trailing return type, we instantiate the
4671 // parameters before the return type, since the return type can then refer
4672 // to the parameters themselves (via decltype, sizeof, etc.).
4673 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004674 SmallVector<QualType, 4> ParamTypes;
4675 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004676 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004677
Douglas Gregor7fb25412010-10-01 18:44:50 +00004678 QualType ResultType;
4679
Richard Smith1226c602012-08-14 22:51:13 +00004680 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004681 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004682 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004683 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004684 return QualType();
4685
Douglas Gregor3024f072012-04-16 07:05:22 +00004686 {
4687 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004688 // If a declaration declares a member function or member function
4689 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004690 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004691 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004692 // declarator.
4693 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004694
Alp Toker42a16a62014-01-25 23:51:36 +00004695 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004696 if (ResultType.isNull())
4697 return QualType();
4698 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004699 }
4700 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004701 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004702 if (ResultType.isNull())
4703 return QualType();
4704
Alp Toker9cacbab2014-01-20 20:26:09 +00004705 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004706 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004707 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004708 return QualType();
4709 }
4710
Richard Smith2e321552014-11-12 02:00:47 +00004711 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4712
4713 bool EPIChanged = false;
4714 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4715 return QualType();
4716
4717 // FIXME: Need to transform ConsumedParameters for variadic template
4718 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004719
John McCall550e0c22009-10-21 00:40:46 +00004720 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004721 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004722 T->getNumParams() != ParamTypes.size() ||
4723 !std::equal(T->param_type_begin(), T->param_type_end(),
Richard Smith2e321552014-11-12 02:00:47 +00004724 ParamTypes.begin()) || EPIChanged) {
4725 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004726 if (Result.isNull())
4727 return QualType();
4728 }
Mike Stump11289f42009-09-09 15:08:12 +00004729
John McCall550e0c22009-10-21 00:40:46 +00004730 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004731 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004732 NewTL.setLParenLoc(TL.getLParenLoc());
4733 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004734 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004735 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4736 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004737
4738 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004739}
Mike Stump11289f42009-09-09 15:08:12 +00004740
Douglas Gregord6ff3322009-08-04 16:50:30 +00004741template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004742bool TreeTransform<Derived>::TransformExceptionSpec(
4743 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4744 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4745 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4746
4747 // Instantiate a dynamic noexcept expression, if any.
4748 if (ESI.Type == EST_ComputedNoexcept) {
4749 EnterExpressionEvaluationContext Unevaluated(getSema(),
4750 Sema::ConstantEvaluated);
4751 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4752 if (NoexceptExpr.isInvalid())
4753 return true;
4754
4755 NoexceptExpr = getSema().CheckBooleanCondition(
4756 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4757 if (NoexceptExpr.isInvalid())
4758 return true;
4759
4760 if (!NoexceptExpr.get()->isValueDependent()) {
4761 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4762 NoexceptExpr.get(), nullptr,
4763 diag::err_noexcept_needs_constant_expression,
4764 /*AllowFold*/false);
4765 if (NoexceptExpr.isInvalid())
4766 return true;
4767 }
4768
4769 if (ESI.NoexceptExpr != NoexceptExpr.get())
4770 Changed = true;
4771 ESI.NoexceptExpr = NoexceptExpr.get();
4772 }
4773
4774 if (ESI.Type != EST_Dynamic)
4775 return false;
4776
4777 // Instantiate a dynamic exception specification's type.
4778 for (QualType T : ESI.Exceptions) {
4779 if (const PackExpansionType *PackExpansion =
4780 T->getAs<PackExpansionType>()) {
4781 Changed = true;
4782
4783 // We have a pack expansion. Instantiate it.
4784 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4785 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4786 Unexpanded);
4787 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4788
4789 // Determine whether the set of unexpanded parameter packs can and
4790 // should
4791 // be expanded.
4792 bool Expand = false;
4793 bool RetainExpansion = false;
4794 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4795 // FIXME: Track the location of the ellipsis (and track source location
4796 // information for the types in the exception specification in general).
4797 if (getDerived().TryExpandParameterPacks(
4798 Loc, SourceRange(), Unexpanded, Expand,
4799 RetainExpansion, NumExpansions))
4800 return true;
4801
4802 if (!Expand) {
4803 // We can't expand this pack expansion into separate arguments yet;
4804 // just substitute into the pattern and create a new pack expansion
4805 // type.
4806 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4807 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4808 if (U.isNull())
4809 return true;
4810
4811 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4812 Exceptions.push_back(U);
4813 continue;
4814 }
4815
4816 // Substitute into the pack expansion pattern for each slice of the
4817 // pack.
4818 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4819 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4820
4821 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4822 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4823 return true;
4824
4825 Exceptions.push_back(U);
4826 }
4827 } else {
4828 QualType U = getDerived().TransformType(T);
4829 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4830 return true;
4831 if (T != U)
4832 Changed = true;
4833
4834 Exceptions.push_back(U);
4835 }
4836 }
4837
4838 ESI.Exceptions = Exceptions;
4839 return false;
4840}
4841
4842template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004843QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004844 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004845 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004846 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004847 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004848 if (ResultType.isNull())
4849 return QualType();
4850
4851 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004852 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004853 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4854
4855 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004856 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004857 NewTL.setLParenLoc(TL.getLParenLoc());
4858 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004859 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004860
4861 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004862}
Mike Stump11289f42009-09-09 15:08:12 +00004863
John McCallb96ec562009-12-04 22:46:56 +00004864template<typename Derived> QualType
4865TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004866 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004867 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004868 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004869 if (!D)
4870 return QualType();
4871
4872 QualType Result = TL.getType();
4873 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4874 Result = getDerived().RebuildUnresolvedUsingType(D);
4875 if (Result.isNull())
4876 return QualType();
4877 }
4878
4879 // We might get an arbitrary type spec type back. We should at
4880 // least always get a type spec type, though.
4881 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4882 NewTL.setNameLoc(TL.getNameLoc());
4883
4884 return Result;
4885}
4886
Douglas Gregord6ff3322009-08-04 16:50:30 +00004887template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004888QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004889 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004890 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004891 TypedefNameDecl *Typedef
4892 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4893 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004894 if (!Typedef)
4895 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004896
John McCall550e0c22009-10-21 00:40:46 +00004897 QualType Result = TL.getType();
4898 if (getDerived().AlwaysRebuild() ||
4899 Typedef != T->getDecl()) {
4900 Result = getDerived().RebuildTypedefType(Typedef);
4901 if (Result.isNull())
4902 return QualType();
4903 }
Mike Stump11289f42009-09-09 15:08:12 +00004904
John McCall550e0c22009-10-21 00:40:46 +00004905 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4906 NewTL.setNameLoc(TL.getNameLoc());
4907
4908 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004909}
Mike Stump11289f42009-09-09 15:08:12 +00004910
Douglas Gregord6ff3322009-08-04 16:50:30 +00004911template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004912QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004913 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004914 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004915 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4916 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004917
John McCalldadc5752010-08-24 06:29:42 +00004918 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004919 if (E.isInvalid())
4920 return QualType();
4921
Eli Friedmane4f22df2012-02-29 04:03:55 +00004922 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4923 if (E.isInvalid())
4924 return QualType();
4925
John McCall550e0c22009-10-21 00:40:46 +00004926 QualType Result = TL.getType();
4927 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004928 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004929 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004930 if (Result.isNull())
4931 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004932 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004933 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004934
John McCall550e0c22009-10-21 00:40:46 +00004935 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004936 NewTL.setTypeofLoc(TL.getTypeofLoc());
4937 NewTL.setLParenLoc(TL.getLParenLoc());
4938 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004939
4940 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004941}
Mike Stump11289f42009-09-09 15:08:12 +00004942
4943template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004944QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004945 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004946 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4947 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4948 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004949 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004950
John McCall550e0c22009-10-21 00:40:46 +00004951 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004952 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4953 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004954 if (Result.isNull())
4955 return QualType();
4956 }
Mike Stump11289f42009-09-09 15:08:12 +00004957
John McCall550e0c22009-10-21 00:40:46 +00004958 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004959 NewTL.setTypeofLoc(TL.getTypeofLoc());
4960 NewTL.setLParenLoc(TL.getLParenLoc());
4961 NewTL.setRParenLoc(TL.getRParenLoc());
4962 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004963
4964 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004965}
Mike Stump11289f42009-09-09 15:08:12 +00004966
4967template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004968QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004969 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004970 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004971
Douglas Gregore922c772009-08-04 22:27:00 +00004972 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004973 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4974 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004975
John McCalldadc5752010-08-24 06:29:42 +00004976 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004977 if (E.isInvalid())
4978 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004979
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004980 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004981 if (E.isInvalid())
4982 return QualType();
4983
John McCall550e0c22009-10-21 00:40:46 +00004984 QualType Result = TL.getType();
4985 if (getDerived().AlwaysRebuild() ||
4986 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004987 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004988 if (Result.isNull())
4989 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004990 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004991 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004992
John McCall550e0c22009-10-21 00:40:46 +00004993 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4994 NewTL.setNameLoc(TL.getNameLoc());
4995
4996 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004997}
4998
4999template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005000QualType TreeTransform<Derived>::TransformUnaryTransformType(
5001 TypeLocBuilder &TLB,
5002 UnaryTransformTypeLoc TL) {
5003 QualType Result = TL.getType();
5004 if (Result->isDependentType()) {
5005 const UnaryTransformType *T = TL.getTypePtr();
5006 QualType NewBase =
5007 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5008 Result = getDerived().RebuildUnaryTransformType(NewBase,
5009 T->getUTTKind(),
5010 TL.getKWLoc());
5011 if (Result.isNull())
5012 return QualType();
5013 }
5014
5015 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5016 NewTL.setKWLoc(TL.getKWLoc());
5017 NewTL.setParensRange(TL.getParensRange());
5018 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5019 return Result;
5020}
5021
5022template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005023QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5024 AutoTypeLoc TL) {
5025 const AutoType *T = TL.getTypePtr();
5026 QualType OldDeduced = T->getDeducedType();
5027 QualType NewDeduced;
5028 if (!OldDeduced.isNull()) {
5029 NewDeduced = getDerived().TransformType(OldDeduced);
5030 if (NewDeduced.isNull())
5031 return QualType();
5032 }
5033
5034 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005035 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5036 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00005037 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00005038 if (Result.isNull())
5039 return QualType();
5040 }
5041
5042 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5043 NewTL.setNameLoc(TL.getNameLoc());
5044
5045 return Result;
5046}
5047
5048template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005049QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005050 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005051 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005052 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005053 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5054 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005055 if (!Record)
5056 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005057
John McCall550e0c22009-10-21 00:40:46 +00005058 QualType Result = TL.getType();
5059 if (getDerived().AlwaysRebuild() ||
5060 Record != T->getDecl()) {
5061 Result = getDerived().RebuildRecordType(Record);
5062 if (Result.isNull())
5063 return QualType();
5064 }
Mike Stump11289f42009-09-09 15:08:12 +00005065
John McCall550e0c22009-10-21 00:40:46 +00005066 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5067 NewTL.setNameLoc(TL.getNameLoc());
5068
5069 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005070}
Mike Stump11289f42009-09-09 15:08:12 +00005071
5072template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005073QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005074 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005075 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005076 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005077 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5078 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005079 if (!Enum)
5080 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005081
John McCall550e0c22009-10-21 00:40:46 +00005082 QualType Result = TL.getType();
5083 if (getDerived().AlwaysRebuild() ||
5084 Enum != T->getDecl()) {
5085 Result = getDerived().RebuildEnumType(Enum);
5086 if (Result.isNull())
5087 return QualType();
5088 }
Mike Stump11289f42009-09-09 15:08:12 +00005089
John McCall550e0c22009-10-21 00:40:46 +00005090 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5091 NewTL.setNameLoc(TL.getNameLoc());
5092
5093 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005094}
John McCallfcc33b02009-09-05 00:15:47 +00005095
John McCalle78aac42010-03-10 03:28:59 +00005096template<typename Derived>
5097QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5098 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005099 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005100 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5101 TL.getTypePtr()->getDecl());
5102 if (!D) return QualType();
5103
5104 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5105 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5106 return T;
5107}
5108
Douglas Gregord6ff3322009-08-04 16:50:30 +00005109template<typename Derived>
5110QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005111 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005112 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005113 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005114}
5115
Mike Stump11289f42009-09-09 15:08:12 +00005116template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005117QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005118 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005119 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005120 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005121
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005122 // Substitute into the replacement type, which itself might involve something
5123 // that needs to be transformed. This only tends to occur with default
5124 // template arguments of template template parameters.
5125 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5126 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5127 if (Replacement.isNull())
5128 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005129
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005130 // Always canonicalize the replacement type.
5131 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5132 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005133 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005134 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005135
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005136 // Propagate type-source information.
5137 SubstTemplateTypeParmTypeLoc NewTL
5138 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5139 NewTL.setNameLoc(TL.getNameLoc());
5140 return Result;
5141
John McCallcebee162009-10-18 09:09:24 +00005142}
5143
5144template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005145QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5146 TypeLocBuilder &TLB,
5147 SubstTemplateTypeParmPackTypeLoc TL) {
5148 return TransformTypeSpecType(TLB, TL);
5149}
5150
5151template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005152QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005153 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005154 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005155 const TemplateSpecializationType *T = TL.getTypePtr();
5156
Douglas Gregordf846d12011-03-02 18:46:51 +00005157 // The nested-name-specifier never matters in a TemplateSpecializationType,
5158 // because we can't have a dependent nested-name-specifier anyway.
5159 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005160 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005161 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5162 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005163 if (Template.isNull())
5164 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005165
John McCall31f82722010-11-12 08:19:04 +00005166 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5167}
5168
Eli Friedman0dfb8892011-10-06 23:00:33 +00005169template<typename Derived>
5170QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5171 AtomicTypeLoc TL) {
5172 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5173 if (ValueType.isNull())
5174 return QualType();
5175
5176 QualType Result = TL.getType();
5177 if (getDerived().AlwaysRebuild() ||
5178 ValueType != TL.getValueLoc().getType()) {
5179 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5180 if (Result.isNull())
5181 return QualType();
5182 }
5183
5184 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5185 NewTL.setKWLoc(TL.getKWLoc());
5186 NewTL.setLParenLoc(TL.getLParenLoc());
5187 NewTL.setRParenLoc(TL.getRParenLoc());
5188
5189 return Result;
5190}
5191
Chad Rosier1dcde962012-08-08 18:46:20 +00005192 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005193 /// container that provides a \c getArgLoc() member function.
5194 ///
5195 /// This iterator is intended to be used with the iterator form of
5196 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5197 template<typename ArgLocContainer>
5198 class TemplateArgumentLocContainerIterator {
5199 ArgLocContainer *Container;
5200 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005201
Douglas Gregorfe921a72010-12-20 23:36:19 +00005202 public:
5203 typedef TemplateArgumentLoc value_type;
5204 typedef TemplateArgumentLoc reference;
5205 typedef int difference_type;
5206 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005207
Douglas Gregorfe921a72010-12-20 23:36:19 +00005208 class pointer {
5209 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005210
Douglas Gregorfe921a72010-12-20 23:36:19 +00005211 public:
5212 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005213
Douglas Gregorfe921a72010-12-20 23:36:19 +00005214 const TemplateArgumentLoc *operator->() const {
5215 return &Arg;
5216 }
5217 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005218
5219
Douglas Gregorfe921a72010-12-20 23:36:19 +00005220 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005221
Douglas Gregorfe921a72010-12-20 23:36:19 +00005222 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5223 unsigned Index)
5224 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005225
Douglas Gregorfe921a72010-12-20 23:36:19 +00005226 TemplateArgumentLocContainerIterator &operator++() {
5227 ++Index;
5228 return *this;
5229 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005230
Douglas Gregorfe921a72010-12-20 23:36:19 +00005231 TemplateArgumentLocContainerIterator operator++(int) {
5232 TemplateArgumentLocContainerIterator Old(*this);
5233 ++(*this);
5234 return Old;
5235 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005236
Douglas Gregorfe921a72010-12-20 23:36:19 +00005237 TemplateArgumentLoc operator*() const {
5238 return Container->getArgLoc(Index);
5239 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005240
Douglas Gregorfe921a72010-12-20 23:36:19 +00005241 pointer operator->() const {
5242 return pointer(Container->getArgLoc(Index));
5243 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005244
Douglas Gregorfe921a72010-12-20 23:36:19 +00005245 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005246 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005247 return X.Container == Y.Container && X.Index == Y.Index;
5248 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005249
Douglas Gregorfe921a72010-12-20 23:36:19 +00005250 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005251 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005252 return !(X == Y);
5253 }
5254 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005255
5256
John McCall31f82722010-11-12 08:19:04 +00005257template <typename Derived>
5258QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5259 TypeLocBuilder &TLB,
5260 TemplateSpecializationTypeLoc TL,
5261 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005262 TemplateArgumentListInfo NewTemplateArgs;
5263 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5264 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005265 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5266 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005267 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005268 ArgIterator(TL, TL.getNumArgs()),
5269 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005270 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005271
John McCall0ad16662009-10-29 08:12:44 +00005272 // FIXME: maybe don't rebuild if all the template arguments are the same.
5273
5274 QualType Result =
5275 getDerived().RebuildTemplateSpecializationType(Template,
5276 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005277 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005278
5279 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005280 // Specializations of template template parameters are represented as
5281 // TemplateSpecializationTypes, and substitution of type alias templates
5282 // within a dependent context can transform them into
5283 // DependentTemplateSpecializationTypes.
5284 if (isa<DependentTemplateSpecializationType>(Result)) {
5285 DependentTemplateSpecializationTypeLoc NewTL
5286 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005287 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005288 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005289 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005290 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005291 NewTL.setLAngleLoc(TL.getLAngleLoc());
5292 NewTL.setRAngleLoc(TL.getRAngleLoc());
5293 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5294 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5295 return Result;
5296 }
5297
John McCall0ad16662009-10-29 08:12:44 +00005298 TemplateSpecializationTypeLoc NewTL
5299 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005300 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005301 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5302 NewTL.setLAngleLoc(TL.getLAngleLoc());
5303 NewTL.setRAngleLoc(TL.getRAngleLoc());
5304 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5305 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005306 }
Mike Stump11289f42009-09-09 15:08:12 +00005307
John McCall0ad16662009-10-29 08:12:44 +00005308 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005309}
Mike Stump11289f42009-09-09 15:08:12 +00005310
Douglas Gregor5a064722011-02-28 17:23:35 +00005311template <typename Derived>
5312QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5313 TypeLocBuilder &TLB,
5314 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005315 TemplateName Template,
5316 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005317 TemplateArgumentListInfo NewTemplateArgs;
5318 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5319 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5320 typedef TemplateArgumentLocContainerIterator<
5321 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005322 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005323 ArgIterator(TL, TL.getNumArgs()),
5324 NewTemplateArgs))
5325 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005326
Douglas Gregor5a064722011-02-28 17:23:35 +00005327 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005328
Douglas Gregor5a064722011-02-28 17:23:35 +00005329 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5330 QualType Result
5331 = getSema().Context.getDependentTemplateSpecializationType(
5332 TL.getTypePtr()->getKeyword(),
5333 DTN->getQualifier(),
5334 DTN->getIdentifier(),
5335 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005336
Douglas Gregor5a064722011-02-28 17:23:35 +00005337 DependentTemplateSpecializationTypeLoc NewTL
5338 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005339 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005340 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005341 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005342 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005343 NewTL.setLAngleLoc(TL.getLAngleLoc());
5344 NewTL.setRAngleLoc(TL.getRAngleLoc());
5345 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5346 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5347 return Result;
5348 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005349
5350 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005351 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005352 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005353 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005354
Douglas Gregor5a064722011-02-28 17:23:35 +00005355 if (!Result.isNull()) {
5356 /// FIXME: Wrap this in an elaborated-type-specifier?
5357 TemplateSpecializationTypeLoc NewTL
5358 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005359 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005360 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005361 NewTL.setLAngleLoc(TL.getLAngleLoc());
5362 NewTL.setRAngleLoc(TL.getRAngleLoc());
5363 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5364 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5365 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005366
Douglas Gregor5a064722011-02-28 17:23:35 +00005367 return Result;
5368}
5369
Mike Stump11289f42009-09-09 15:08:12 +00005370template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005371QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005372TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005373 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005374 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005375
Douglas Gregor844cb502011-03-01 18:12:44 +00005376 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005377 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005378 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005379 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005380 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5381 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005382 return QualType();
5383 }
Mike Stump11289f42009-09-09 15:08:12 +00005384
John McCall31f82722010-11-12 08:19:04 +00005385 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5386 if (NamedT.isNull())
5387 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005388
Richard Smith3f1b5d02011-05-05 21:57:07 +00005389 // C++0x [dcl.type.elab]p2:
5390 // If the identifier resolves to a typedef-name or the simple-template-id
5391 // resolves to an alias template specialization, the
5392 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005393 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5394 if (const TemplateSpecializationType *TST =
5395 NamedT->getAs<TemplateSpecializationType>()) {
5396 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005397 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5398 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005399 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5400 diag::err_tag_reference_non_tag) << 4;
5401 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5402 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005403 }
5404 }
5405
John McCall550e0c22009-10-21 00:40:46 +00005406 QualType Result = TL.getType();
5407 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005408 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005409 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005410 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005411 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005412 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005413 if (Result.isNull())
5414 return QualType();
5415 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005416
Abramo Bagnara6150c882010-05-11 21:36:43 +00005417 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005418 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005419 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005420 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005421}
Mike Stump11289f42009-09-09 15:08:12 +00005422
5423template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005424QualType TreeTransform<Derived>::TransformAttributedType(
5425 TypeLocBuilder &TLB,
5426 AttributedTypeLoc TL) {
5427 const AttributedType *oldType = TL.getTypePtr();
5428 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5429 if (modifiedType.isNull())
5430 return QualType();
5431
5432 QualType result = TL.getType();
5433
5434 // FIXME: dependent operand expressions?
5435 if (getDerived().AlwaysRebuild() ||
5436 modifiedType != oldType->getModifiedType()) {
5437 // TODO: this is really lame; we should really be rebuilding the
5438 // equivalent type from first principles.
5439 QualType equivalentType
5440 = getDerived().TransformType(oldType->getEquivalentType());
5441 if (equivalentType.isNull())
5442 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005443
5444 // Check whether we can add nullability; it is only represented as
5445 // type sugar, and therefore cannot be diagnosed in any other way.
5446 if (auto nullability = oldType->getImmediateNullability()) {
5447 if (!modifiedType->canHaveNullability()) {
5448 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005449 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005450 return QualType();
5451 }
5452 }
5453
John McCall81904512011-01-06 01:58:22 +00005454 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5455 modifiedType,
5456 equivalentType);
5457 }
5458
5459 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5460 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5461 if (TL.hasAttrOperand())
5462 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5463 if (TL.hasAttrExprOperand())
5464 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5465 else if (TL.hasAttrEnumOperand())
5466 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5467
5468 return result;
5469}
5470
5471template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005472QualType
5473TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5474 ParenTypeLoc TL) {
5475 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5476 if (Inner.isNull())
5477 return QualType();
5478
5479 QualType Result = TL.getType();
5480 if (getDerived().AlwaysRebuild() ||
5481 Inner != TL.getInnerLoc().getType()) {
5482 Result = getDerived().RebuildParenType(Inner);
5483 if (Result.isNull())
5484 return QualType();
5485 }
5486
5487 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5488 NewTL.setLParenLoc(TL.getLParenLoc());
5489 NewTL.setRParenLoc(TL.getRParenLoc());
5490 return Result;
5491}
5492
5493template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005494QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005495 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005496 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005497
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005498 NestedNameSpecifierLoc QualifierLoc
5499 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5500 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005501 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005502
John McCallc392f372010-06-11 00:33:02 +00005503 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005504 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005505 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005506 QualifierLoc,
5507 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005508 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005509 if (Result.isNull())
5510 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005511
Abramo Bagnarad7548482010-05-19 21:37:53 +00005512 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5513 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005514 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5515
Abramo Bagnarad7548482010-05-19 21:37:53 +00005516 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005517 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005518 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005519 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005520 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005521 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005522 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005523 NewTL.setNameLoc(TL.getNameLoc());
5524 }
John McCall550e0c22009-10-21 00:40:46 +00005525 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005526}
Mike Stump11289f42009-09-09 15:08:12 +00005527
Douglas Gregord6ff3322009-08-04 16:50:30 +00005528template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005529QualType TreeTransform<Derived>::
5530 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005531 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005532 NestedNameSpecifierLoc QualifierLoc;
5533 if (TL.getQualifierLoc()) {
5534 QualifierLoc
5535 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5536 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005537 return QualType();
5538 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005539
John McCall31f82722010-11-12 08:19:04 +00005540 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005541 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005542}
5543
5544template<typename Derived>
5545QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005546TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5547 DependentTemplateSpecializationTypeLoc TL,
5548 NestedNameSpecifierLoc QualifierLoc) {
5549 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005550
Douglas Gregora7a795b2011-03-01 20:11:18 +00005551 TemplateArgumentListInfo NewTemplateArgs;
5552 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5553 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005554
Douglas Gregora7a795b2011-03-01 20:11:18 +00005555 typedef TemplateArgumentLocContainerIterator<
5556 DependentTemplateSpecializationTypeLoc> ArgIterator;
5557 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5558 ArgIterator(TL, TL.getNumArgs()),
5559 NewTemplateArgs))
5560 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005561
Douglas Gregora7a795b2011-03-01 20:11:18 +00005562 QualType Result
5563 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5564 QualifierLoc,
5565 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005566 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005567 NewTemplateArgs);
5568 if (Result.isNull())
5569 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005570
Douglas Gregora7a795b2011-03-01 20:11:18 +00005571 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5572 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005573
Douglas Gregora7a795b2011-03-01 20:11:18 +00005574 // Copy information relevant to the template specialization.
5575 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005576 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005577 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005578 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005579 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5580 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005581 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005582 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005583
Douglas Gregora7a795b2011-03-01 20:11:18 +00005584 // Copy information relevant to the elaborated type.
5585 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005586 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005587 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005588 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5589 DependentTemplateSpecializationTypeLoc SpecTL
5590 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005591 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005592 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005593 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005594 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005595 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5596 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005597 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005598 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005599 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005600 TemplateSpecializationTypeLoc SpecTL
5601 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005602 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005603 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005604 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5605 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005606 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005607 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005608 }
5609 return Result;
5610}
5611
5612template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005613QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5614 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005615 QualType Pattern
5616 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005617 if (Pattern.isNull())
5618 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005619
5620 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005621 if (getDerived().AlwaysRebuild() ||
5622 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005623 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005624 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005625 TL.getEllipsisLoc(),
5626 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005627 if (Result.isNull())
5628 return QualType();
5629 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005630
Douglas Gregor822d0302011-01-12 17:07:58 +00005631 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5632 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5633 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005634}
5635
5636template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005637QualType
5638TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005639 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005640 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005641 TLB.pushFullCopy(TL);
5642 return TL.getType();
5643}
5644
5645template<typename Derived>
5646QualType
5647TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005648 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005649 // Transform base type.
5650 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5651 if (BaseType.isNull())
5652 return QualType();
5653
5654 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5655
5656 // Transform type arguments.
5657 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5658 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5659 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5660 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5661 QualType TypeArg = TypeArgInfo->getType();
5662 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5663 AnyChanged = true;
5664
5665 // We have a pack expansion. Instantiate it.
5666 const auto *PackExpansion = PackExpansionLoc.getType()
5667 ->castAs<PackExpansionType>();
5668 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5669 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5670 Unexpanded);
5671 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5672
5673 // Determine whether the set of unexpanded parameter packs can
5674 // and should be expanded.
5675 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5676 bool Expand = false;
5677 bool RetainExpansion = false;
5678 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5679 if (getDerived().TryExpandParameterPacks(
5680 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5681 Unexpanded, Expand, RetainExpansion, NumExpansions))
5682 return QualType();
5683
5684 if (!Expand) {
5685 // We can't expand this pack expansion into separate arguments yet;
5686 // just substitute into the pattern and create a new pack expansion
5687 // type.
5688 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5689
5690 TypeLocBuilder TypeArgBuilder;
5691 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5692 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5693 PatternLoc);
5694 if (NewPatternType.isNull())
5695 return QualType();
5696
5697 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5698 NewPatternType, NumExpansions);
5699 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5700 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5701 NewTypeArgInfos.push_back(
5702 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5703 continue;
5704 }
5705
5706 // Substitute into the pack expansion pattern for each slice of the
5707 // pack.
5708 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5709 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5710
5711 TypeLocBuilder TypeArgBuilder;
5712 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5713
5714 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5715 PatternLoc);
5716 if (NewTypeArg.isNull())
5717 return QualType();
5718
5719 NewTypeArgInfos.push_back(
5720 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5721 }
5722
5723 continue;
5724 }
5725
5726 TypeLocBuilder TypeArgBuilder;
5727 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
5728 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
5729 if (NewTypeArg.isNull())
5730 return QualType();
5731
5732 // If nothing changed, just keep the old TypeSourceInfo.
5733 if (NewTypeArg == TypeArg) {
5734 NewTypeArgInfos.push_back(TypeArgInfo);
5735 continue;
5736 }
5737
5738 NewTypeArgInfos.push_back(
5739 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5740 AnyChanged = true;
5741 }
5742
5743 QualType Result = TL.getType();
5744 if (getDerived().AlwaysRebuild() || AnyChanged) {
5745 // Rebuild the type.
5746 Result = getDerived().RebuildObjCObjectType(
5747 BaseType,
5748 TL.getLocStart(),
5749 TL.getTypeArgsLAngleLoc(),
5750 NewTypeArgInfos,
5751 TL.getTypeArgsRAngleLoc(),
5752 TL.getProtocolLAngleLoc(),
5753 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5754 TL.getNumProtocols()),
5755 TL.getProtocolLocs(),
5756 TL.getProtocolRAngleLoc());
5757
5758 if (Result.isNull())
5759 return QualType();
5760 }
5761
5762 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
5763 assert(TL.hasBaseTypeAsWritten() && "Can't be dependent");
5764 NewT.setHasBaseTypeAsWritten(true);
5765 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
5766 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
5767 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
5768 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
5769 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5770 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5771 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
5772 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5773 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005774}
Mike Stump11289f42009-09-09 15:08:12 +00005775
5776template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005777QualType
5778TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005779 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005780 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5781 if (PointeeType.isNull())
5782 return QualType();
5783
5784 QualType Result = TL.getType();
5785 if (getDerived().AlwaysRebuild() ||
5786 PointeeType != TL.getPointeeLoc().getType()) {
5787 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
5788 TL.getStarLoc());
5789 if (Result.isNull())
5790 return QualType();
5791 }
5792
5793 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5794 NewT.setStarLoc(TL.getStarLoc());
5795 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005796}
5797
Douglas Gregord6ff3322009-08-04 16:50:30 +00005798//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005799// Statement transformation
5800//===----------------------------------------------------------------------===//
5801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005802StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005803TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005804 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005805}
5806
5807template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005808StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005809TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5810 return getDerived().TransformCompoundStmt(S, false);
5811}
5812
5813template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005814StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005815TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005816 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005817 Sema::CompoundScopeRAII CompoundScope(getSema());
5818
John McCall1ababa62010-08-27 19:56:05 +00005819 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005820 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005821 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005822 for (auto *B : S->body()) {
5823 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005824 if (Result.isInvalid()) {
5825 // Immediately fail if this was a DeclStmt, since it's very
5826 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005827 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005828 return StmtError();
5829
5830 // Otherwise, just keep processing substatements and fail later.
5831 SubStmtInvalid = true;
5832 continue;
5833 }
Mike Stump11289f42009-09-09 15:08:12 +00005834
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005835 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005836 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005837 }
Mike Stump11289f42009-09-09 15:08:12 +00005838
John McCall1ababa62010-08-27 19:56:05 +00005839 if (SubStmtInvalid)
5840 return StmtError();
5841
Douglas Gregorebe10102009-08-20 07:17:43 +00005842 if (!getDerived().AlwaysRebuild() &&
5843 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005844 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005845
5846 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005847 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005848 S->getRBracLoc(),
5849 IsStmtExpr);
5850}
Mike Stump11289f42009-09-09 15:08:12 +00005851
Douglas Gregorebe10102009-08-20 07:17:43 +00005852template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005853StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005854TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005855 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005856 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005857 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5858 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005859
Eli Friedman06577382009-11-19 03:14:00 +00005860 // Transform the left-hand case value.
5861 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005862 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005863 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005864 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005865
Eli Friedman06577382009-11-19 03:14:00 +00005866 // Transform the right-hand case value (for the GNU case-range extension).
5867 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005868 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005869 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005870 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005871 }
Mike Stump11289f42009-09-09 15:08:12 +00005872
Douglas Gregorebe10102009-08-20 07:17:43 +00005873 // Build the case statement.
5874 // Case statements are always rebuilt so that they will attached to their
5875 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005876 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005877 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005878 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005879 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005880 S->getColonLoc());
5881 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005882 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005883
Douglas Gregorebe10102009-08-20 07:17:43 +00005884 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005885 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005886 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005887 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005888
Douglas Gregorebe10102009-08-20 07:17:43 +00005889 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005890 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005891}
5892
5893template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005894StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005895TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005896 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005897 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005898 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005899 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005900
Douglas Gregorebe10102009-08-20 07:17:43 +00005901 // Default statements are always rebuilt
5902 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005903 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005904}
Mike Stump11289f42009-09-09 15:08:12 +00005905
Douglas Gregorebe10102009-08-20 07:17:43 +00005906template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005907StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005908TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005909 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005910 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005911 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005912
Chris Lattnercab02a62011-02-17 20:34:02 +00005913 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5914 S->getDecl());
5915 if (!LD)
5916 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005917
5918
Douglas Gregorebe10102009-08-20 07:17:43 +00005919 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005920 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005921 cast<LabelDecl>(LD), SourceLocation(),
5922 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005923}
Mike Stump11289f42009-09-09 15:08:12 +00005924
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005925template <typename Derived>
5926const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
5927 if (!R)
5928 return R;
5929
5930 switch (R->getKind()) {
5931// Transform attributes with a pragma spelling by calling TransformXXXAttr.
5932#define ATTR(X)
5933#define PRAGMA_SPELLING_ATTR(X) \
5934 case attr::X: \
5935 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
5936#include "clang/Basic/AttrList.inc"
5937 default:
5938 return R;
5939 }
5940}
5941
5942template <typename Derived>
5943StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5944 bool AttrsChanged = false;
5945 SmallVector<const Attr *, 1> Attrs;
5946
5947 // Visit attributes and keep track if any are transformed.
5948 for (const auto *I : S->getAttrs()) {
5949 const Attr *R = getDerived().TransformAttr(I);
5950 AttrsChanged |= (I != R);
5951 Attrs.push_back(R);
5952 }
5953
Richard Smithc202b282012-04-14 00:33:13 +00005954 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5955 if (SubStmt.isInvalid())
5956 return StmtError();
5957
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005958 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00005959 return S;
5960
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005961 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00005962 SubStmt.get());
5963}
5964
5965template<typename Derived>
5966StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005967TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005968 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005969 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005970 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005971 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005972 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005973 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005974 getDerived().TransformDefinition(
5975 S->getConditionVariable()->getLocation(),
5976 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005977 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005978 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005979 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005980 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005981
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005982 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005983 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005984
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005985 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005986 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005987 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005988 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005989 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005990 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005991
John McCallb268a282010-08-23 23:25:46 +00005992 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005993 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005994 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005995
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005996 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005997 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005998 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005999
Douglas Gregorebe10102009-08-20 07:17:43 +00006000 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00006001 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00006002 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006003 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006004
Douglas Gregorebe10102009-08-20 07:17:43 +00006005 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00006006 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00006007 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006008 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006009
Douglas Gregorebe10102009-08-20 07:17:43 +00006010 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006011 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006012 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006013 Then.get() == S->getThen() &&
6014 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006015 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006016
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006017 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00006018 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00006019 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006020}
6021
6022template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006023StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006024TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006025 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00006026 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006027 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00006028 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006029 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00006030 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006031 getDerived().TransformDefinition(
6032 S->getConditionVariable()->getLocation(),
6033 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00006034 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006035 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006036 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00006037 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006038
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006039 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006040 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006041 }
Mike Stump11289f42009-09-09 15:08:12 +00006042
Douglas Gregorebe10102009-08-20 07:17:43 +00006043 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006044 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00006045 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00006046 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00006047 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006048 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006049
Douglas Gregorebe10102009-08-20 07:17:43 +00006050 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006051 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006052 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006053 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006054
Douglas Gregorebe10102009-08-20 07:17:43 +00006055 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006056 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6057 Body.get());
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>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006063 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006064 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006065 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00006066 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006067 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00006068 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006069 getDerived().TransformDefinition(
6070 S->getConditionVariable()->getLocation(),
6071 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00006072 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006073 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006074 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00006075 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006076
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006077 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006078 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006079
6080 if (S->getCond()) {
6081 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006082 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6083 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006084 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006085 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006086 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00006087 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00006088 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006089 }
Mike Stump11289f42009-09-09 15:08:12 +00006090
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006091 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006092 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006093 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006094
Douglas Gregorebe10102009-08-20 07:17:43 +00006095 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006096 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006097 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006098 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006099
Douglas Gregorebe10102009-08-20 07:17:43 +00006100 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006101 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006102 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006103 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006104 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006105
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006106 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00006107 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006108}
Mike Stump11289f42009-09-09 15:08:12 +00006109
Douglas Gregorebe10102009-08-20 07:17:43 +00006110template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006111StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006112TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006113 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006114 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006115 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006116 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006117
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006118 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006119 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006120 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006121 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006122
Douglas Gregorebe10102009-08-20 07:17:43 +00006123 if (!getDerived().AlwaysRebuild() &&
6124 Cond.get() == S->getCond() &&
6125 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006126 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006127
John McCallb268a282010-08-23 23:25:46 +00006128 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6129 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006130 S->getRParenLoc());
6131}
Mike Stump11289f42009-09-09 15:08:12 +00006132
Douglas Gregorebe10102009-08-20 07:17:43 +00006133template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006134StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006135TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006136 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006137 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006138 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006139 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006140
Douglas Gregorebe10102009-08-20 07:17:43 +00006141 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006142 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006143 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006144 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006145 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006146 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006147 getDerived().TransformDefinition(
6148 S->getConditionVariable()->getLocation(),
6149 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006150 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006151 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006152 } else {
6153 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006154
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006155 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006156 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006157
6158 if (S->getCond()) {
6159 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006160 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6161 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006162 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006163 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006164 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006165
John McCallb268a282010-08-23 23:25:46 +00006166 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006167 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006168 }
Mike Stump11289f42009-09-09 15:08:12 +00006169
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006170 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006171 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006172 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006173
Douglas Gregorebe10102009-08-20 07:17:43 +00006174 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006175 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006176 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006177 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006178
Richard Smith945f8d32013-01-14 22:39:08 +00006179 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006180 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006181 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006182
Douglas Gregorebe10102009-08-20 07:17:43 +00006183 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006184 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006185 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006186 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006187
Douglas Gregorebe10102009-08-20 07:17:43 +00006188 if (!getDerived().AlwaysRebuild() &&
6189 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00006190 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006191 Inc.get() == S->getInc() &&
6192 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006193 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006194
Douglas Gregorebe10102009-08-20 07:17:43 +00006195 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006196 Init.get(), FullCond, ConditionVar,
6197 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006198}
6199
6200template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006201StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006202TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006203 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6204 S->getLabel());
6205 if (!LD)
6206 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006207
Douglas Gregorebe10102009-08-20 07:17:43 +00006208 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006209 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006210 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006211}
6212
6213template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006214StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006215TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006216 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006217 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006218 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006219 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006220
Douglas Gregorebe10102009-08-20 07:17:43 +00006221 if (!getDerived().AlwaysRebuild() &&
6222 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006223 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006224
6225 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006226 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006227}
6228
6229template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006230StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006231TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006232 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006233}
Mike Stump11289f42009-09-09 15:08:12 +00006234
Douglas Gregorebe10102009-08-20 07:17:43 +00006235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006236StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006237TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006238 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006239}
Mike Stump11289f42009-09-09 15:08:12 +00006240
Douglas Gregorebe10102009-08-20 07:17:43 +00006241template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006242StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006243TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006244 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6245 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006246 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006247 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006248
Mike Stump11289f42009-09-09 15:08:12 +00006249 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006250 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006251 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006252}
Mike Stump11289f42009-09-09 15:08:12 +00006253
Douglas Gregorebe10102009-08-20 07:17:43 +00006254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006255StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006256TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006257 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006258 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006259 for (auto *D : S->decls()) {
6260 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006261 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006262 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006263
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006264 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006265 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006266
Douglas Gregorebe10102009-08-20 07:17:43 +00006267 Decls.push_back(Transformed);
6268 }
Mike Stump11289f42009-09-09 15:08:12 +00006269
Douglas Gregorebe10102009-08-20 07:17:43 +00006270 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006271 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006272
Rafael Espindolaab417692013-07-09 12:05:01 +00006273 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006274}
Mike Stump11289f42009-09-09 15:08:12 +00006275
Douglas Gregorebe10102009-08-20 07:17:43 +00006276template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006277StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006278TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006279
Benjamin Kramerf0623432012-08-23 22:51:59 +00006280 SmallVector<Expr*, 8> Constraints;
6281 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006282 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006283
John McCalldadc5752010-08-24 06:29:42 +00006284 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006285 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006286
6287 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006288
Anders Carlssonaaeef072010-01-24 05:50:09 +00006289 // Go through the outputs.
6290 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006291 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006292
Anders Carlssonaaeef072010-01-24 05:50:09 +00006293 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006294 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006295
Anders Carlssonaaeef072010-01-24 05:50:09 +00006296 // Transform the output expr.
6297 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006298 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006299 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006300 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006301
Anders Carlssonaaeef072010-01-24 05:50:09 +00006302 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006303
John McCallb268a282010-08-23 23:25:46 +00006304 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006305 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006306
Anders Carlssonaaeef072010-01-24 05:50:09 +00006307 // Go through the inputs.
6308 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006309 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006310
Anders Carlssonaaeef072010-01-24 05:50:09 +00006311 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006312 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006313
Anders Carlssonaaeef072010-01-24 05:50:09 +00006314 // Transform the input expr.
6315 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006316 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006317 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006318 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006319
Anders Carlssonaaeef072010-01-24 05:50:09 +00006320 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006321
John McCallb268a282010-08-23 23:25:46 +00006322 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006323 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006324
Anders Carlssonaaeef072010-01-24 05:50:09 +00006325 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006326 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006327
6328 // Go through the clobbers.
6329 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006330 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006331
6332 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006333 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006334 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6335 S->isVolatile(), S->getNumOutputs(),
6336 S->getNumInputs(), Names.data(),
6337 Constraints, Exprs, AsmString.get(),
6338 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006339}
6340
Chad Rosier32503022012-06-11 20:47:18 +00006341template<typename Derived>
6342StmtResult
6343TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006344 ArrayRef<Token> AsmToks =
6345 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006346
John McCallf413f5e2013-05-03 00:10:13 +00006347 bool HadError = false, HadChange = false;
6348
6349 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6350 SmallVector<Expr*, 8> TransformedExprs;
6351 TransformedExprs.reserve(SrcExprs.size());
6352 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6353 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6354 if (!Result.isUsable()) {
6355 HadError = true;
6356 } else {
6357 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006358 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006359 }
6360 }
6361
6362 if (HadError) return StmtError();
6363 if (!HadChange && !getDerived().AlwaysRebuild())
6364 return Owned(S);
6365
Chad Rosierb6f46c12012-08-15 16:53:30 +00006366 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006367 AsmToks, S->getAsmString(),
6368 S->getNumOutputs(), S->getNumInputs(),
6369 S->getAllConstraints(), S->getClobbers(),
6370 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006371}
Douglas Gregorebe10102009-08-20 07:17:43 +00006372
6373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006374StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006375TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006376 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006377 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006378 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006379 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006380
Douglas Gregor96c79492010-04-23 22:50:49 +00006381 // Transform the @catch statements (if present).
6382 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006383 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006384 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006385 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006386 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006387 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006388 if (Catch.get() != S->getCatchStmt(I))
6389 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006390 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006391 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006392
Douglas Gregor306de2f2010-04-22 23:59:56 +00006393 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006394 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006395 if (S->getFinallyStmt()) {
6396 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6397 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006398 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006399 }
6400
6401 // If nothing changed, just retain this statement.
6402 if (!getDerived().AlwaysRebuild() &&
6403 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006404 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006405 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006406 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006407
Douglas Gregor306de2f2010-04-22 23:59:56 +00006408 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006409 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006410 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006411}
Mike Stump11289f42009-09-09 15:08:12 +00006412
Douglas Gregorebe10102009-08-20 07:17:43 +00006413template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006414StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006415TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006416 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006417 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006418 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006419 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006420 if (FromVar->getTypeSourceInfo()) {
6421 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6422 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006423 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006424 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006425
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006426 QualType T;
6427 if (TSInfo)
6428 T = TSInfo->getType();
6429 else {
6430 T = getDerived().TransformType(FromVar->getType());
6431 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006432 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006433 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006434
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006435 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6436 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006437 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006438 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006439
John McCalldadc5752010-08-24 06:29:42 +00006440 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006441 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006442 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006443
6444 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006445 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006446 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006447}
Mike Stump11289f42009-09-09 15:08:12 +00006448
Douglas Gregorebe10102009-08-20 07:17:43 +00006449template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006450StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006451TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006452 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006453 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006454 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006455 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006456
Douglas Gregor306de2f2010-04-22 23:59:56 +00006457 // If nothing changed, just retain this statement.
6458 if (!getDerived().AlwaysRebuild() &&
6459 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006460 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006461
6462 // Build a new statement.
6463 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006464 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006465}
Mike Stump11289f42009-09-09 15:08:12 +00006466
Douglas Gregorebe10102009-08-20 07:17:43 +00006467template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006468StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006469TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006470 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006471 if (S->getThrowExpr()) {
6472 Operand = getDerived().TransformExpr(S->getThrowExpr());
6473 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006474 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006475 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006476
Douglas Gregor2900c162010-04-22 21:44:01 +00006477 if (!getDerived().AlwaysRebuild() &&
6478 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006479 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006480
John McCallb268a282010-08-23 23:25:46 +00006481 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006482}
Mike Stump11289f42009-09-09 15:08:12 +00006483
Douglas Gregorebe10102009-08-20 07:17:43 +00006484template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006485StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006486TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006487 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006488 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006489 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006490 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006491 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006492 Object =
6493 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6494 Object.get());
6495 if (Object.isInvalid())
6496 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006497
Douglas Gregor6148de72010-04-22 22:01:21 +00006498 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006499 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006500 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006501 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006502
Douglas Gregor6148de72010-04-22 22:01:21 +00006503 // If nothing change, just retain the current statement.
6504 if (!getDerived().AlwaysRebuild() &&
6505 Object.get() == S->getSynchExpr() &&
6506 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006507 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006508
6509 // Build a new statement.
6510 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006511 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006512}
6513
6514template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006515StmtResult
John McCall31168b02011-06-15 23:02:42 +00006516TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6517 ObjCAutoreleasePoolStmt *S) {
6518 // Transform the body.
6519 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6520 if (Body.isInvalid())
6521 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006522
John McCall31168b02011-06-15 23:02:42 +00006523 // If nothing changed, just retain this statement.
6524 if (!getDerived().AlwaysRebuild() &&
6525 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006526 return S;
John McCall31168b02011-06-15 23:02:42 +00006527
6528 // Build a new statement.
6529 return getDerived().RebuildObjCAutoreleasePoolStmt(
6530 S->getAtLoc(), Body.get());
6531}
6532
6533template<typename Derived>
6534StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006535TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006536 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006537 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006538 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006539 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006540 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006541
Douglas Gregorf68a5082010-04-22 23:10:45 +00006542 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006543 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006544 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006545 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006546
Douglas Gregorf68a5082010-04-22 23:10:45 +00006547 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006548 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006549 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006550 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006551
Douglas Gregorf68a5082010-04-22 23:10:45 +00006552 // If nothing changed, just retain this statement.
6553 if (!getDerived().AlwaysRebuild() &&
6554 Element.get() == S->getElement() &&
6555 Collection.get() == S->getCollection() &&
6556 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006557 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006558
Douglas Gregorf68a5082010-04-22 23:10:45 +00006559 // Build a new statement.
6560 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006561 Element.get(),
6562 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006563 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006564 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006565}
6566
David Majnemer5f7efef2013-10-15 09:50:08 +00006567template <typename Derived>
6568StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006569 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006570 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006571 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6572 TypeSourceInfo *T =
6573 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006574 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006575 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006576
David Majnemer5f7efef2013-10-15 09:50:08 +00006577 Var = getDerived().RebuildExceptionDecl(
6578 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6579 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006580 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006581 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006582 }
Mike Stump11289f42009-09-09 15:08:12 +00006583
Douglas Gregorebe10102009-08-20 07:17:43 +00006584 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006585 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006586 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006587 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006588
David Majnemer5f7efef2013-10-15 09:50:08 +00006589 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006590 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006591 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006592
David Majnemer5f7efef2013-10-15 09:50:08 +00006593 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006594}
Mike Stump11289f42009-09-09 15:08:12 +00006595
David Majnemer5f7efef2013-10-15 09:50:08 +00006596template <typename Derived>
6597StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006598 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006599 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006600 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006601 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006602
Douglas Gregorebe10102009-08-20 07:17:43 +00006603 // Transform the handlers.
6604 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006605 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006606 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006607 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006608 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006609 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006610
Douglas Gregorebe10102009-08-20 07:17:43 +00006611 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006612 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006613 }
Mike Stump11289f42009-09-09 15:08:12 +00006614
David Majnemer5f7efef2013-10-15 09:50:08 +00006615 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006616 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006617 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006618
John McCallb268a282010-08-23 23:25:46 +00006619 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006620 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006621}
Mike Stump11289f42009-09-09 15:08:12 +00006622
Richard Smith02e85f32011-04-14 22:09:26 +00006623template<typename Derived>
6624StmtResult
6625TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6626 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6627 if (Range.isInvalid())
6628 return StmtError();
6629
6630 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6631 if (BeginEnd.isInvalid())
6632 return StmtError();
6633
6634 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6635 if (Cond.isInvalid())
6636 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006637 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006638 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006639 if (Cond.isInvalid())
6640 return StmtError();
6641 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006642 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006643
6644 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6645 if (Inc.isInvalid())
6646 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006647 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006648 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006649
6650 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6651 if (LoopVar.isInvalid())
6652 return StmtError();
6653
6654 StmtResult NewStmt = S;
6655 if (getDerived().AlwaysRebuild() ||
6656 Range.get() != S->getRangeStmt() ||
6657 BeginEnd.get() != S->getBeginEndStmt() ||
6658 Cond.get() != S->getCond() ||
6659 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006660 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006661 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6662 S->getColonLoc(), Range.get(),
6663 BeginEnd.get(), Cond.get(),
6664 Inc.get(), LoopVar.get(),
6665 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006666 if (NewStmt.isInvalid())
6667 return StmtError();
6668 }
Richard Smith02e85f32011-04-14 22:09:26 +00006669
6670 StmtResult Body = getDerived().TransformStmt(S->getBody());
6671 if (Body.isInvalid())
6672 return StmtError();
6673
6674 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6675 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006676 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006677 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6678 S->getColonLoc(), Range.get(),
6679 BeginEnd.get(), Cond.get(),
6680 Inc.get(), LoopVar.get(),
6681 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006682 if (NewStmt.isInvalid())
6683 return StmtError();
6684 }
Richard Smith02e85f32011-04-14 22:09:26 +00006685
6686 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006687 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006688
6689 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6690}
6691
John Wiegley1c0675e2011-04-28 01:08:34 +00006692template<typename Derived>
6693StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006694TreeTransform<Derived>::TransformMSDependentExistsStmt(
6695 MSDependentExistsStmt *S) {
6696 // Transform the nested-name-specifier, if any.
6697 NestedNameSpecifierLoc QualifierLoc;
6698 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006699 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006700 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6701 if (!QualifierLoc)
6702 return StmtError();
6703 }
6704
6705 // Transform the declaration name.
6706 DeclarationNameInfo NameInfo = S->getNameInfo();
6707 if (NameInfo.getName()) {
6708 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6709 if (!NameInfo.getName())
6710 return StmtError();
6711 }
6712
6713 // Check whether anything changed.
6714 if (!getDerived().AlwaysRebuild() &&
6715 QualifierLoc == S->getQualifierLoc() &&
6716 NameInfo.getName() == S->getNameInfo().getName())
6717 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006718
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006719 // Determine whether this name exists, if we can.
6720 CXXScopeSpec SS;
6721 SS.Adopt(QualifierLoc);
6722 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006723 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006724 case Sema::IER_Exists:
6725 if (S->isIfExists())
6726 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006727
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006728 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6729
6730 case Sema::IER_DoesNotExist:
6731 if (S->isIfNotExists())
6732 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006733
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006734 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006735
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006736 case Sema::IER_Dependent:
6737 Dependent = true;
6738 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006739
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006740 case Sema::IER_Error:
6741 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006742 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006743
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006744 // We need to continue with the instantiation, so do so now.
6745 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6746 if (SubStmt.isInvalid())
6747 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006748
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006749 // If we have resolved the name, just transform to the substatement.
6750 if (!Dependent)
6751 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006752
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006753 // The name is still dependent, so build a dependent expression again.
6754 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6755 S->isIfExists(),
6756 QualifierLoc,
6757 NameInfo,
6758 SubStmt.get());
6759}
6760
6761template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006762ExprResult
6763TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6764 NestedNameSpecifierLoc QualifierLoc;
6765 if (E->getQualifierLoc()) {
6766 QualifierLoc
6767 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6768 if (!QualifierLoc)
6769 return ExprError();
6770 }
6771
6772 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6773 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6774 if (!PD)
6775 return ExprError();
6776
6777 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6778 if (Base.isInvalid())
6779 return ExprError();
6780
6781 return new (SemaRef.getASTContext())
6782 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6783 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6784 QualifierLoc, E->getMemberLoc());
6785}
6786
David Majnemerfad8f482013-10-15 09:33:02 +00006787template <typename Derived>
6788StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006789 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006790 if (TryBlock.isInvalid())
6791 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006792
6793 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006794 if (Handler.isInvalid())
6795 return StmtError();
6796
David Majnemerfad8f482013-10-15 09:33:02 +00006797 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6798 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006799 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006800
Warren Huntf6be4cb2014-07-25 20:52:51 +00006801 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6802 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006803}
6804
David Majnemerfad8f482013-10-15 09:33:02 +00006805template <typename Derived>
6806StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006807 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006808 if (Block.isInvalid())
6809 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006810
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006811 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006812}
6813
David Majnemerfad8f482013-10-15 09:33:02 +00006814template <typename Derived>
6815StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006816 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006817 if (FilterExpr.isInvalid())
6818 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006819
David Majnemer7e755502013-10-15 09:30:14 +00006820 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006821 if (Block.isInvalid())
6822 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006823
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006824 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6825 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006826}
6827
David Majnemerfad8f482013-10-15 09:33:02 +00006828template <typename Derived>
6829StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6830 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006831 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6832 else
6833 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6834}
6835
Nico Weber9b982072014-07-07 00:12:30 +00006836template<typename Derived>
6837StmtResult
6838TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6839 return S;
6840}
6841
Alexander Musman64d33f12014-06-04 07:53:32 +00006842//===----------------------------------------------------------------------===//
6843// OpenMP directive transformation
6844//===----------------------------------------------------------------------===//
6845template <typename Derived>
6846StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6847 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006848
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006849 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006850 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006851 ArrayRef<OMPClause *> Clauses = D->clauses();
6852 TClauses.reserve(Clauses.size());
6853 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6854 I != E; ++I) {
6855 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00006856 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006857 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00006858 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00006859 if (Clause)
6860 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006861 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006862 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006863 }
6864 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006865 StmtResult AssociatedStmt;
6866 if (D->hasAssociatedStmt()) {
6867 if (!D->getAssociatedStmt()) {
6868 return StmtError();
6869 }
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00006870 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
6871 /*CurScope=*/nullptr);
6872 StmtResult Body;
6873 {
6874 Sema::CompoundScopeRAII CompoundScope(getSema());
6875 Body = getDerived().TransformStmt(
6876 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
6877 }
6878 AssociatedStmt =
6879 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00006880 if (AssociatedStmt.isInvalid()) {
6881 return StmtError();
6882 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006883 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006884 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006885 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006886 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006887
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006888 // Transform directive name for 'omp critical' directive.
6889 DeclarationNameInfo DirName;
6890 if (D->getDirectiveKind() == OMPD_critical) {
6891 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6892 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6893 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006894 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
6895 if (D->getDirectiveKind() == OMPD_cancellation_point) {
6896 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00006897 } else if (D->getDirectiveKind() == OMPD_cancel) {
6898 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006899 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006900
Alexander Musman64d33f12014-06-04 07:53:32 +00006901 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006902 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
6903 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006904}
6905
Alexander Musman64d33f12014-06-04 07:53:32 +00006906template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006907StmtResult
6908TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6909 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006910 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6911 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006912 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6913 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6914 return Res;
6915}
6916
Alexander Musman64d33f12014-06-04 07:53:32 +00006917template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006918StmtResult
6919TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6920 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006921 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6922 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006923 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6924 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006925 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006926}
6927
Alexey Bataevf29276e2014-06-18 04:14:57 +00006928template <typename Derived>
6929StmtResult
6930TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6931 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006932 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6933 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006934 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6935 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6936 return Res;
6937}
6938
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006939template <typename Derived>
6940StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00006941TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
6942 DeclarationNameInfo DirName;
6943 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
6944 D->getLocStart());
6945 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6946 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6947 return Res;
6948}
6949
6950template <typename Derived>
6951StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006952TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6953 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006954 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6955 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006956 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6957 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6958 return Res;
6959}
6960
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006961template <typename Derived>
6962StmtResult
6963TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6964 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006965 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6966 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006967 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6968 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6969 return Res;
6970}
6971
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006972template <typename Derived>
6973StmtResult
6974TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6975 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006976 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6977 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006978 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6979 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6980 return Res;
6981}
6982
Alexey Bataev4acb8592014-07-07 13:01:15 +00006983template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006984StmtResult
6985TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6986 DeclarationNameInfo DirName;
6987 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6988 D->getLocStart());
6989 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6990 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6991 return Res;
6992}
6993
6994template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006995StmtResult
6996TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6997 getDerived().getSema().StartOpenMPDSABlock(
6998 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
6999 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7000 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7001 return Res;
7002}
7003
7004template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007005StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7006 OMPParallelForDirective *D) {
7007 DeclarationNameInfo DirName;
7008 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7009 nullptr, D->getLocStart());
7010 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7011 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7012 return Res;
7013}
7014
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007015template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007016StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7017 OMPParallelForSimdDirective *D) {
7018 DeclarationNameInfo DirName;
7019 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7020 nullptr, D->getLocStart());
7021 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7022 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7023 return Res;
7024}
7025
7026template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007027StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7028 OMPParallelSectionsDirective *D) {
7029 DeclarationNameInfo DirName;
7030 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7031 nullptr, D->getLocStart());
7032 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7033 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7034 return Res;
7035}
7036
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007037template <typename Derived>
7038StmtResult
7039TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7040 DeclarationNameInfo DirName;
7041 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7042 D->getLocStart());
7043 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7044 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7045 return Res;
7046}
7047
Alexey Bataev68446b72014-07-18 07:47:19 +00007048template <typename Derived>
7049StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7050 OMPTaskyieldDirective *D) {
7051 DeclarationNameInfo DirName;
7052 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7053 D->getLocStart());
7054 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7055 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7056 return Res;
7057}
7058
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007059template <typename Derived>
7060StmtResult
7061TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7062 DeclarationNameInfo DirName;
7063 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7064 D->getLocStart());
7065 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7066 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7067 return Res;
7068}
7069
Alexey Bataev2df347a2014-07-18 10:17:07 +00007070template <typename Derived>
7071StmtResult
7072TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7073 DeclarationNameInfo DirName;
7074 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7075 D->getLocStart());
7076 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7077 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7078 return Res;
7079}
7080
Alexey Bataev6125da92014-07-21 11:26:11 +00007081template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007082StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7083 OMPTaskgroupDirective *D) {
7084 DeclarationNameInfo DirName;
7085 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7086 D->getLocStart());
7087 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7088 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7089 return Res;
7090}
7091
7092template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007093StmtResult
7094TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7095 DeclarationNameInfo DirName;
7096 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7097 D->getLocStart());
7098 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7099 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7100 return Res;
7101}
7102
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007103template <typename Derived>
7104StmtResult
7105TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7106 DeclarationNameInfo DirName;
7107 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7108 D->getLocStart());
7109 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7110 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7111 return Res;
7112}
7113
Alexey Bataev0162e452014-07-22 10:10:35 +00007114template <typename Derived>
7115StmtResult
7116TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7117 DeclarationNameInfo DirName;
7118 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7119 D->getLocStart());
7120 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7121 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7122 return Res;
7123}
7124
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007125template <typename Derived>
7126StmtResult
7127TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7128 DeclarationNameInfo DirName;
7129 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7130 D->getLocStart());
7131 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7132 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7133 return Res;
7134}
7135
Alexey Bataev13314bf2014-10-09 04:18:56 +00007136template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007137StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7138 OMPTargetDataDirective *D) {
7139 DeclarationNameInfo DirName;
7140 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7141 D->getLocStart());
7142 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7143 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7144 return Res;
7145}
7146
7147template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007148StmtResult
7149TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7150 DeclarationNameInfo DirName;
7151 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7152 D->getLocStart());
7153 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7154 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7155 return Res;
7156}
7157
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007158template <typename Derived>
7159StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7160 OMPCancellationPointDirective *D) {
7161 DeclarationNameInfo DirName;
7162 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7163 nullptr, D->getLocStart());
7164 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7165 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7166 return Res;
7167}
7168
Alexey Bataev80909872015-07-02 11:25:17 +00007169template <typename Derived>
7170StmtResult
7171TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7172 DeclarationNameInfo DirName;
7173 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7174 D->getLocStart());
7175 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7176 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7177 return Res;
7178}
7179
Alexander Musman64d33f12014-06-04 07:53:32 +00007180//===----------------------------------------------------------------------===//
7181// OpenMP clause transformation
7182//===----------------------------------------------------------------------===//
7183template <typename Derived>
7184OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007185 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7186 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007187 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007188 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007189 C->getLParenLoc(), C->getLocEnd());
7190}
7191
Alexander Musman64d33f12014-06-04 07:53:32 +00007192template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007193OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7194 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7195 if (Cond.isInvalid())
7196 return nullptr;
7197 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7198 C->getLParenLoc(), C->getLocEnd());
7199}
7200
7201template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007202OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007203TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7204 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7205 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007206 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007207 return getDerived().RebuildOMPNumThreadsClause(
7208 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007209}
7210
Alexey Bataev62c87d22014-03-21 04:51:18 +00007211template <typename Derived>
7212OMPClause *
7213TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7214 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7215 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007216 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007217 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007218 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007219}
7220
Alexander Musman8bd31e62014-05-27 15:12:19 +00007221template <typename Derived>
7222OMPClause *
7223TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7224 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7225 if (E.isInvalid())
7226 return 0;
7227 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007228 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007229}
7230
Alexander Musman64d33f12014-06-04 07:53:32 +00007231template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007232OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007233TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007234 return getDerived().RebuildOMPDefaultClause(
7235 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7236 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007237}
7238
Alexander Musman64d33f12014-06-04 07:53:32 +00007239template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007240OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007241TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007242 return getDerived().RebuildOMPProcBindClause(
7243 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7244 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007245}
7246
Alexander Musman64d33f12014-06-04 07:53:32 +00007247template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007248OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007249TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7250 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7251 if (E.isInvalid())
7252 return nullptr;
7253 return getDerived().RebuildOMPScheduleClause(
7254 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7255 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7256}
7257
7258template <typename Derived>
7259OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007260TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007261 ExprResult E;
7262 if (auto *Num = C->getNumForLoops()) {
7263 E = getDerived().TransformExpr(Num);
7264 if (E.isInvalid())
7265 return nullptr;
7266 }
7267 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7268 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007269}
7270
7271template <typename Derived>
7272OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007273TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7274 // No need to rebuild this clause, no template-dependent parameters.
7275 return C;
7276}
7277
7278template <typename Derived>
7279OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007280TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7281 // No need to rebuild this clause, no template-dependent parameters.
7282 return C;
7283}
7284
7285template <typename Derived>
7286OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007287TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7288 // No need to rebuild this clause, no template-dependent parameters.
7289 return C;
7290}
7291
7292template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007293OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7294 // No need to rebuild this clause, no template-dependent parameters.
7295 return C;
7296}
7297
7298template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007299OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7300 // No need to rebuild this clause, no template-dependent parameters.
7301 return C;
7302}
7303
7304template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007305OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007306TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7307 // No need to rebuild this clause, no template-dependent parameters.
7308 return C;
7309}
7310
7311template <typename Derived>
7312OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007313TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7314 // No need to rebuild this clause, no template-dependent parameters.
7315 return C;
7316}
7317
7318template <typename Derived>
7319OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007320TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7321 // No need to rebuild this clause, no template-dependent parameters.
7322 return C;
7323}
7324
7325template <typename Derived>
7326OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007327TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007328 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007329 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007330 for (auto *VE : C->varlists()) {
7331 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007332 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007333 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007334 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007335 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007336 return getDerived().RebuildOMPPrivateClause(
7337 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007338}
7339
Alexander Musman64d33f12014-06-04 07:53:32 +00007340template <typename Derived>
7341OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7342 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007343 llvm::SmallVector<Expr *, 16> Vars;
7344 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007345 for (auto *VE : C->varlists()) {
7346 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007347 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007348 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007349 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007350 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007351 return getDerived().RebuildOMPFirstprivateClause(
7352 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007353}
7354
Alexander Musman64d33f12014-06-04 07:53:32 +00007355template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007356OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007357TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7358 llvm::SmallVector<Expr *, 16> Vars;
7359 Vars.reserve(C->varlist_size());
7360 for (auto *VE : C->varlists()) {
7361 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7362 if (EVar.isInvalid())
7363 return nullptr;
7364 Vars.push_back(EVar.get());
7365 }
7366 return getDerived().RebuildOMPLastprivateClause(
7367 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7368}
7369
7370template <typename Derived>
7371OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007372TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7373 llvm::SmallVector<Expr *, 16> Vars;
7374 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007375 for (auto *VE : C->varlists()) {
7376 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007377 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007378 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007379 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007380 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007381 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7382 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007383}
7384
Alexander Musman64d33f12014-06-04 07:53:32 +00007385template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007386OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007387TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7388 llvm::SmallVector<Expr *, 16> Vars;
7389 Vars.reserve(C->varlist_size());
7390 for (auto *VE : C->varlists()) {
7391 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7392 if (EVar.isInvalid())
7393 return nullptr;
7394 Vars.push_back(EVar.get());
7395 }
7396 CXXScopeSpec ReductionIdScopeSpec;
7397 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7398
7399 DeclarationNameInfo NameInfo = C->getNameInfo();
7400 if (NameInfo.getName()) {
7401 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7402 if (!NameInfo.getName())
7403 return nullptr;
7404 }
7405 return getDerived().RebuildOMPReductionClause(
7406 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7407 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7408}
7409
7410template <typename Derived>
7411OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007412TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7413 llvm::SmallVector<Expr *, 16> Vars;
7414 Vars.reserve(C->varlist_size());
7415 for (auto *VE : C->varlists()) {
7416 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7417 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007418 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007419 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007420 }
7421 ExprResult Step = getDerived().TransformExpr(C->getStep());
7422 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007423 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007424 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
7425 C->getLParenLoc(),
7426 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007427}
7428
Alexander Musman64d33f12014-06-04 07:53:32 +00007429template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007430OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007431TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7432 llvm::SmallVector<Expr *, 16> Vars;
7433 Vars.reserve(C->varlist_size());
7434 for (auto *VE : C->varlists()) {
7435 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7436 if (EVar.isInvalid())
7437 return nullptr;
7438 Vars.push_back(EVar.get());
7439 }
7440 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7441 if (Alignment.isInvalid())
7442 return nullptr;
7443 return getDerived().RebuildOMPAlignedClause(
7444 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7445 C->getColonLoc(), C->getLocEnd());
7446}
7447
Alexander Musman64d33f12014-06-04 07:53:32 +00007448template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007449OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007450TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7451 llvm::SmallVector<Expr *, 16> Vars;
7452 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007453 for (auto *VE : C->varlists()) {
7454 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007455 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007456 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007457 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007458 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007459 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7460 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007461}
7462
Alexey Bataevbae9a792014-06-27 10:37:06 +00007463template <typename Derived>
7464OMPClause *
7465TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7466 llvm::SmallVector<Expr *, 16> Vars;
7467 Vars.reserve(C->varlist_size());
7468 for (auto *VE : C->varlists()) {
7469 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7470 if (EVar.isInvalid())
7471 return nullptr;
7472 Vars.push_back(EVar.get());
7473 }
7474 return getDerived().RebuildOMPCopyprivateClause(
7475 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7476}
7477
Alexey Bataev6125da92014-07-21 11:26:11 +00007478template <typename Derived>
7479OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7480 llvm::SmallVector<Expr *, 16> Vars;
7481 Vars.reserve(C->varlist_size());
7482 for (auto *VE : C->varlists()) {
7483 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7484 if (EVar.isInvalid())
7485 return nullptr;
7486 Vars.push_back(EVar.get());
7487 }
7488 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7489 C->getLParenLoc(), C->getLocEnd());
7490}
7491
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007492template <typename Derived>
7493OMPClause *
7494TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7495 llvm::SmallVector<Expr *, 16> Vars;
7496 Vars.reserve(C->varlist_size());
7497 for (auto *VE : C->varlists()) {
7498 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7499 if (EVar.isInvalid())
7500 return nullptr;
7501 Vars.push_back(EVar.get());
7502 }
7503 return getDerived().RebuildOMPDependClause(
7504 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7505 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7506}
7507
Michael Wonge710d542015-08-07 16:16:36 +00007508template <typename Derived>
7509OMPClause *
7510TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7511 ExprResult E = getDerived().TransformExpr(C->getDevice());
7512 if (E.isInvalid())
7513 return nullptr;
7514 return getDerived().RebuildOMPDeviceClause(
7515 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7516}
7517
Douglas Gregorebe10102009-08-20 07:17:43 +00007518//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007519// Expression transformation
7520//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007521template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007522ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007523TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007524 if (!E->isTypeDependent())
7525 return E;
7526
7527 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7528 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007529}
Mike Stump11289f42009-09-09 15:08:12 +00007530
7531template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007532ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007533TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007534 NestedNameSpecifierLoc QualifierLoc;
7535 if (E->getQualifierLoc()) {
7536 QualifierLoc
7537 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7538 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007539 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007540 }
John McCallce546572009-12-08 09:08:17 +00007541
7542 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007543 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7544 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007545 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007546 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007547
John McCall815039a2010-08-17 21:27:17 +00007548 DeclarationNameInfo NameInfo = E->getNameInfo();
7549 if (NameInfo.getName()) {
7550 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7551 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007552 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007553 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007554
7555 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007556 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007557 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007558 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007559 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007560
7561 // Mark it referenced in the new context regardless.
7562 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007563 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007564
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007565 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007566 }
John McCallce546572009-12-08 09:08:17 +00007567
Craig Topperc3ec1492014-05-26 06:22:03 +00007568 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007569 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007570 TemplateArgs = &TransArgs;
7571 TransArgs.setLAngleLoc(E->getLAngleLoc());
7572 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007573 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7574 E->getNumTemplateArgs(),
7575 TransArgs))
7576 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007577 }
7578
Chad Rosier1dcde962012-08-08 18:46:20 +00007579 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007580 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007581}
Mike Stump11289f42009-09-09 15:08:12 +00007582
Douglas Gregora16548e2009-08-11 05:31:07 +00007583template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007584ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007585TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007586 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007587}
Mike Stump11289f42009-09-09 15:08:12 +00007588
Douglas Gregora16548e2009-08-11 05:31:07 +00007589template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007590ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007591TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007592 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007593}
Mike Stump11289f42009-09-09 15:08:12 +00007594
Douglas Gregora16548e2009-08-11 05:31:07 +00007595template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007596ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007597TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007598 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007599}
Mike Stump11289f42009-09-09 15:08:12 +00007600
Douglas Gregora16548e2009-08-11 05:31:07 +00007601template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007602ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007603TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007604 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007605}
Mike Stump11289f42009-09-09 15:08:12 +00007606
Douglas Gregora16548e2009-08-11 05:31:07 +00007607template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007608ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007609TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007610 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007611}
7612
7613template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007614ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007615TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007616 if (FunctionDecl *FD = E->getDirectCallee())
7617 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007618 return SemaRef.MaybeBindToTemporary(E);
7619}
7620
7621template<typename Derived>
7622ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007623TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7624 ExprResult ControllingExpr =
7625 getDerived().TransformExpr(E->getControllingExpr());
7626 if (ControllingExpr.isInvalid())
7627 return ExprError();
7628
Chris Lattner01cf8db2011-07-20 06:58:45 +00007629 SmallVector<Expr *, 4> AssocExprs;
7630 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007631 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7632 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7633 if (TS) {
7634 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7635 if (!AssocType)
7636 return ExprError();
7637 AssocTypes.push_back(AssocType);
7638 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007639 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007640 }
7641
7642 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7643 if (AssocExpr.isInvalid())
7644 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007645 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007646 }
7647
7648 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7649 E->getDefaultLoc(),
7650 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007651 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007652 AssocTypes,
7653 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007654}
7655
7656template<typename Derived>
7657ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007658TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007659 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007660 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007661 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007662
Douglas Gregora16548e2009-08-11 05:31:07 +00007663 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007664 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007665
John McCallb268a282010-08-23 23:25:46 +00007666 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007667 E->getRParen());
7668}
7669
Richard Smithdb2630f2012-10-21 03:28:35 +00007670/// \brief The operand of a unary address-of operator has special rules: it's
7671/// allowed to refer to a non-static member of a class even if there's no 'this'
7672/// object available.
7673template<typename Derived>
7674ExprResult
7675TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7676 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007677 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007678 else
7679 return getDerived().TransformExpr(E);
7680}
7681
Mike Stump11289f42009-09-09 15:08:12 +00007682template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007683ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007684TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007685 ExprResult SubExpr;
7686 if (E->getOpcode() == UO_AddrOf)
7687 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7688 else
7689 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007690 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007691 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007692
Douglas Gregora16548e2009-08-11 05:31:07 +00007693 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007694 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007695
Douglas Gregora16548e2009-08-11 05:31:07 +00007696 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7697 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007698 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007699}
Mike Stump11289f42009-09-09 15:08:12 +00007700
Douglas Gregora16548e2009-08-11 05:31:07 +00007701template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007702ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007703TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7704 // Transform the type.
7705 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7706 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007707 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007708
Douglas Gregor882211c2010-04-28 22:16:22 +00007709 // Transform all of the components into components similar to what the
7710 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007711 // FIXME: It would be slightly more efficient in the non-dependent case to
7712 // just map FieldDecls, rather than requiring the rebuilder to look for
7713 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007714 // template code that we don't care.
7715 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007716 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007717 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007718 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007719 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7720 const Node &ON = E->getComponent(I);
7721 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007722 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007723 Comp.LocStart = ON.getSourceRange().getBegin();
7724 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007725 switch (ON.getKind()) {
7726 case Node::Array: {
7727 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007728 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007729 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007730 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007731
Douglas Gregor882211c2010-04-28 22:16:22 +00007732 ExprChanged = ExprChanged || Index.get() != FromIndex;
7733 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007734 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007735 break;
7736 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007737
Douglas Gregor882211c2010-04-28 22:16:22 +00007738 case Node::Field:
7739 case Node::Identifier:
7740 Comp.isBrackets = false;
7741 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007742 if (!Comp.U.IdentInfo)
7743 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007744
Douglas Gregor882211c2010-04-28 22:16:22 +00007745 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007746
Douglas Gregord1702062010-04-29 00:18:15 +00007747 case Node::Base:
7748 // Will be recomputed during the rebuild.
7749 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007750 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007751
Douglas Gregor882211c2010-04-28 22:16:22 +00007752 Components.push_back(Comp);
7753 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007754
Douglas Gregor882211c2010-04-28 22:16:22 +00007755 // If nothing changed, retain the existing expression.
7756 if (!getDerived().AlwaysRebuild() &&
7757 Type == E->getTypeSourceInfo() &&
7758 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007759 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007760
Douglas Gregor882211c2010-04-28 22:16:22 +00007761 // Build a new offsetof expression.
7762 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7763 Components.data(), Components.size(),
7764 E->getRParenLoc());
7765}
7766
7767template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007768ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007769TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7770 assert(getDerived().AlreadyTransformed(E->getType()) &&
7771 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007772 return E;
John McCall8d69a212010-11-15 23:31:06 +00007773}
7774
7775template<typename Derived>
7776ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00007777TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
7778 return E;
7779}
7780
7781template<typename Derived>
7782ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007783TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007784 // Rebuild the syntactic form. The original syntactic form has
7785 // opaque-value expressions in it, so strip those away and rebuild
7786 // the result. This is a really awful way of doing this, but the
7787 // better solution (rebuilding the semantic expressions and
7788 // rebinding OVEs as necessary) doesn't work; we'd need
7789 // TreeTransform to not strip away implicit conversions.
7790 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7791 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007792 if (result.isInvalid()) return ExprError();
7793
7794 // If that gives us a pseudo-object result back, the pseudo-object
7795 // expression must have been an lvalue-to-rvalue conversion which we
7796 // should reapply.
7797 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007798 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007799
7800 return result;
7801}
7802
7803template<typename Derived>
7804ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007805TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7806 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007807 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007808 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007809
John McCallbcd03502009-12-07 02:54:59 +00007810 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007811 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007812 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007813
John McCall4c98fd82009-11-04 07:28:41 +00007814 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007815 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007816
Peter Collingbournee190dee2011-03-11 19:24:49 +00007817 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7818 E->getKind(),
7819 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007820 }
Mike Stump11289f42009-09-09 15:08:12 +00007821
Eli Friedmane4f22df2012-02-29 04:03:55 +00007822 // C++0x [expr.sizeof]p1:
7823 // The operand is either an expression, which is an unevaluated operand
7824 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007825 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7826 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007827
Reid Kleckner32506ed2014-06-12 23:03:48 +00007828 // Try to recover if we have something like sizeof(T::X) where X is a type.
7829 // Notably, there must be *exactly* one set of parens if X is a type.
7830 TypeSourceInfo *RecoveryTSI = nullptr;
7831 ExprResult SubExpr;
7832 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7833 if (auto *DRE =
7834 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7835 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7836 PE, DRE, false, &RecoveryTSI);
7837 else
7838 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7839
7840 if (RecoveryTSI) {
7841 return getDerived().RebuildUnaryExprOrTypeTrait(
7842 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7843 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007844 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007845
Eli Friedmane4f22df2012-02-29 04:03:55 +00007846 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007847 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007848
Peter Collingbournee190dee2011-03-11 19:24:49 +00007849 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7850 E->getOperatorLoc(),
7851 E->getKind(),
7852 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007853}
Mike Stump11289f42009-09-09 15:08:12 +00007854
Douglas Gregora16548e2009-08-11 05:31:07 +00007855template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007856ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007857TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007858 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007859 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007860 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007861
John McCalldadc5752010-08-24 06:29:42 +00007862 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007863 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007864 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007865
7866
Douglas Gregora16548e2009-08-11 05:31:07 +00007867 if (!getDerived().AlwaysRebuild() &&
7868 LHS.get() == E->getLHS() &&
7869 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007870 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007871
John McCallb268a282010-08-23 23:25:46 +00007872 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007873 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007874 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007875 E->getRBracketLoc());
7876}
Mike Stump11289f42009-09-09 15:08:12 +00007877
7878template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007879ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007880TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007881 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007882 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007883 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007884 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007885
7886 // Transform arguments.
7887 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007888 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007889 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007890 &ArgChanged))
7891 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007892
Douglas Gregora16548e2009-08-11 05:31:07 +00007893 if (!getDerived().AlwaysRebuild() &&
7894 Callee.get() == E->getCallee() &&
7895 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007896 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007897
Douglas Gregora16548e2009-08-11 05:31:07 +00007898 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007899 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007900 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007901 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007902 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007903 E->getRParenLoc());
7904}
Mike Stump11289f42009-09-09 15:08:12 +00007905
7906template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007907ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007908TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007909 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007910 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007911 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007912
Douglas Gregorea972d32011-02-28 21:54:11 +00007913 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007914 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007915 QualifierLoc
7916 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007917
Douglas Gregorea972d32011-02-28 21:54:11 +00007918 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007919 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007920 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007921 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007922
Eli Friedman2cfcef62009-12-04 06:40:45 +00007923 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007924 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7925 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007926 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007927 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007928
John McCall16df1e52010-03-30 21:47:33 +00007929 NamedDecl *FoundDecl = E->getFoundDecl();
7930 if (FoundDecl == E->getMemberDecl()) {
7931 FoundDecl = Member;
7932 } else {
7933 FoundDecl = cast_or_null<NamedDecl>(
7934 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7935 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007936 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007937 }
7938
Douglas Gregora16548e2009-08-11 05:31:07 +00007939 if (!getDerived().AlwaysRebuild() &&
7940 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007941 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007942 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007943 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007944 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007945
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007946 // Mark it referenced in the new context regardless.
7947 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007948 SemaRef.MarkMemberReferenced(E);
7949
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007950 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007951 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007952
John McCall6b51f282009-11-23 01:53:49 +00007953 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007954 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007955 TransArgs.setLAngleLoc(E->getLAngleLoc());
7956 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007957 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7958 E->getNumTemplateArgs(),
7959 TransArgs))
7960 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007961 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007962
Douglas Gregora16548e2009-08-11 05:31:07 +00007963 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007964 SourceLocation FakeOperatorLoc =
7965 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007966
John McCall38836f02010-01-15 08:34:02 +00007967 // FIXME: to do this check properly, we will need to preserve the
7968 // first-qualifier-in-scope here, just in case we had a dependent
7969 // base (and therefore couldn't do the check) and a
7970 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007971 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007972
John McCallb268a282010-08-23 23:25:46 +00007973 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007974 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007975 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007976 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007977 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007978 Member,
John McCall16df1e52010-03-30 21:47:33 +00007979 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007980 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007981 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007982 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007983}
Mike Stump11289f42009-09-09 15:08:12 +00007984
Douglas Gregora16548e2009-08-11 05:31:07 +00007985template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007986ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007987TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007988 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007989 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007990 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007991
John McCalldadc5752010-08-24 06:29:42 +00007992 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007993 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007994 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007995
Douglas Gregora16548e2009-08-11 05:31:07 +00007996 if (!getDerived().AlwaysRebuild() &&
7997 LHS.get() == E->getLHS() &&
7998 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007999 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008000
Lang Hames5de91cc2012-10-02 04:45:10 +00008001 Sema::FPContractStateRAII FPContractState(getSema());
8002 getSema().FPFeatures.fp_contract = E->isFPContractable();
8003
Douglas Gregora16548e2009-08-11 05:31:07 +00008004 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008005 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008006}
8007
Mike Stump11289f42009-09-09 15:08:12 +00008008template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008009ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008010TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008011 CompoundAssignOperator *E) {
8012 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008013}
Mike Stump11289f42009-09-09 15:08:12 +00008014
Douglas Gregora16548e2009-08-11 05:31:07 +00008015template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008016ExprResult TreeTransform<Derived>::
8017TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8018 // Just rebuild the common and RHS expressions and see whether we
8019 // get any changes.
8020
8021 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8022 if (commonExpr.isInvalid())
8023 return ExprError();
8024
8025 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8026 if (rhs.isInvalid())
8027 return ExprError();
8028
8029 if (!getDerived().AlwaysRebuild() &&
8030 commonExpr.get() == e->getCommon() &&
8031 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008032 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008033
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008034 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008035 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008036 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008037 e->getColonLoc(),
8038 rhs.get());
8039}
8040
8041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008042ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008043TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008044 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008045 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008046 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008047
John McCalldadc5752010-08-24 06:29:42 +00008048 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008049 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008050 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008051
John McCalldadc5752010-08-24 06:29:42 +00008052 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008053 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008054 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008055
Douglas Gregora16548e2009-08-11 05:31:07 +00008056 if (!getDerived().AlwaysRebuild() &&
8057 Cond.get() == E->getCond() &&
8058 LHS.get() == E->getLHS() &&
8059 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008060 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008061
John McCallb268a282010-08-23 23:25:46 +00008062 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008063 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008064 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008065 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008066 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008067}
Mike Stump11289f42009-09-09 15:08:12 +00008068
8069template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008070ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008071TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008072 // Implicit casts are eliminated during transformation, since they
8073 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008074 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008075}
Mike Stump11289f42009-09-09 15:08:12 +00008076
Douglas Gregora16548e2009-08-11 05:31:07 +00008077template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008078ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008079TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008080 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8081 if (!Type)
8082 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008083
John McCalldadc5752010-08-24 06:29:42 +00008084 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008085 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008086 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008087 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008088
Douglas Gregora16548e2009-08-11 05:31:07 +00008089 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008090 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008091 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008092 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008093
John McCall97513962010-01-15 18:39:57 +00008094 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008095 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008096 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008097 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008098}
Mike Stump11289f42009-09-09 15:08:12 +00008099
Douglas Gregora16548e2009-08-11 05:31:07 +00008100template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008101ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008102TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008103 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8104 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8105 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008106 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008107
John McCalldadc5752010-08-24 06:29:42 +00008108 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008109 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008110 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008111
Douglas Gregora16548e2009-08-11 05:31:07 +00008112 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008113 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008114 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008115 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008116
John McCall5d7aa7f2010-01-19 22:33:45 +00008117 // Note: the expression type doesn't necessarily match the
8118 // type-as-written, but that's okay, because it should always be
8119 // derivable from the initializer.
8120
John McCalle15bbff2010-01-18 19:35:47 +00008121 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008122 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008123 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008124}
Mike Stump11289f42009-09-09 15:08:12 +00008125
Douglas Gregora16548e2009-08-11 05:31:07 +00008126template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008127ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008128TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008129 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008130 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008131 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008132
Douglas Gregora16548e2009-08-11 05:31:07 +00008133 if (!getDerived().AlwaysRebuild() &&
8134 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008135 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008136
Douglas Gregora16548e2009-08-11 05:31:07 +00008137 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008138 SourceLocation FakeOperatorLoc =
8139 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008140 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008141 E->getAccessorLoc(),
8142 E->getAccessor());
8143}
Mike Stump11289f42009-09-09 15:08:12 +00008144
Douglas Gregora16548e2009-08-11 05:31:07 +00008145template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008146ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008147TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008148 if (InitListExpr *Syntactic = E->getSyntacticForm())
8149 E = Syntactic;
8150
Douglas Gregora16548e2009-08-11 05:31:07 +00008151 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008152
Benjamin Kramerf0623432012-08-23 22:51:59 +00008153 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008154 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008155 Inits, &InitChanged))
8156 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008157
Richard Smith520449d2015-02-05 06:15:50 +00008158 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8159 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8160 // in some cases. We can't reuse it in general, because the syntactic and
8161 // semantic forms are linked, and we can't know that semantic form will
8162 // match even if the syntactic form does.
8163 }
Mike Stump11289f42009-09-09 15:08:12 +00008164
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008165 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008166 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008167}
Mike Stump11289f42009-09-09 15:08:12 +00008168
Douglas Gregora16548e2009-08-11 05:31:07 +00008169template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008170ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008171TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008172 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008173
Douglas Gregorebe10102009-08-20 07:17:43 +00008174 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008175 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008176 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008177 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008178
Douglas Gregorebe10102009-08-20 07:17:43 +00008179 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008180 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008181 bool ExprChanged = false;
8182 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
8183 DEnd = E->designators_end();
8184 D != DEnd; ++D) {
8185 if (D->isFieldDesignator()) {
8186 Desig.AddDesignator(Designator::getField(D->getFieldName(),
8187 D->getDotLoc(),
8188 D->getFieldLoc()));
8189 continue;
8190 }
Mike Stump11289f42009-09-09 15:08:12 +00008191
Douglas Gregora16548e2009-08-11 05:31:07 +00008192 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00008193 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008194 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008195 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008196
8197 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008198 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008199
Douglas Gregora16548e2009-08-11 05:31:07 +00008200 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008201 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008202 continue;
8203 }
Mike Stump11289f42009-09-09 15:08:12 +00008204
Douglas Gregora16548e2009-08-11 05:31:07 +00008205 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008206 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00008207 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
8208 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008209 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008210
John McCalldadc5752010-08-24 06:29:42 +00008211 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008212 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008213 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008214
8215 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008216 End.get(),
8217 D->getLBracketLoc(),
8218 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008219
Douglas Gregora16548e2009-08-11 05:31:07 +00008220 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8221 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00008222
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008223 ArrayExprs.push_back(Start.get());
8224 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008225 }
Mike Stump11289f42009-09-09 15:08:12 +00008226
Douglas Gregora16548e2009-08-11 05:31:07 +00008227 if (!getDerived().AlwaysRebuild() &&
8228 Init.get() == E->getInit() &&
8229 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008230 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008231
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008232 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008233 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008234 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008235}
Mike Stump11289f42009-09-09 15:08:12 +00008236
Yunzhong Gaocb779302015-06-10 00:27:52 +00008237// Seems that if TransformInitListExpr() only works on the syntactic form of an
8238// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8239template<typename Derived>
8240ExprResult
8241TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8242 DesignatedInitUpdateExpr *E) {
8243 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8244 "initializer");
8245 return ExprError();
8246}
8247
8248template<typename Derived>
8249ExprResult
8250TreeTransform<Derived>::TransformNoInitExpr(
8251 NoInitExpr *E) {
8252 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8253 return ExprError();
8254}
8255
Douglas Gregora16548e2009-08-11 05:31:07 +00008256template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008257ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008258TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008259 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008260 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008261
Douglas Gregor3da3c062009-10-28 00:29:27 +00008262 // FIXME: Will we ever have proper type location here? Will we actually
8263 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008264 QualType T = getDerived().TransformType(E->getType());
8265 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008266 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008267
Douglas Gregora16548e2009-08-11 05:31:07 +00008268 if (!getDerived().AlwaysRebuild() &&
8269 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008270 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008271
Douglas Gregora16548e2009-08-11 05:31:07 +00008272 return getDerived().RebuildImplicitValueInitExpr(T);
8273}
Mike Stump11289f42009-09-09 15:08:12 +00008274
Douglas Gregora16548e2009-08-11 05:31:07 +00008275template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008276ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008277TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008278 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8279 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008280 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008281
John McCalldadc5752010-08-24 06:29:42 +00008282 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008283 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008284 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008285
Douglas Gregora16548e2009-08-11 05:31:07 +00008286 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008287 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008288 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008289 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008290
John McCallb268a282010-08-23 23:25:46 +00008291 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008292 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008293}
8294
8295template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008296ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008297TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008298 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008299 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008300 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8301 &ArgumentChanged))
8302 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008303
Douglas Gregora16548e2009-08-11 05:31:07 +00008304 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008305 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008306 E->getRParenLoc());
8307}
Mike Stump11289f42009-09-09 15:08:12 +00008308
Douglas Gregora16548e2009-08-11 05:31:07 +00008309/// \brief Transform an address-of-label expression.
8310///
8311/// By default, the transformation of an address-of-label expression always
8312/// rebuilds the expression, so that the label identifier can be resolved to
8313/// the corresponding label statement by semantic analysis.
8314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008315ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008316TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008317 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8318 E->getLabel());
8319 if (!LD)
8320 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008321
Douglas Gregora16548e2009-08-11 05:31:07 +00008322 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008323 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008324}
Mike Stump11289f42009-09-09 15:08:12 +00008325
8326template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008327ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008328TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008329 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008330 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008331 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008332 if (SubStmt.isInvalid()) {
8333 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008334 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008335 }
Mike Stump11289f42009-09-09 15:08:12 +00008336
Douglas Gregora16548e2009-08-11 05:31:07 +00008337 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008338 SubStmt.get() == E->getSubStmt()) {
8339 // Calling this an 'error' is unintuitive, but it does the right thing.
8340 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008341 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008342 }
Mike Stump11289f42009-09-09 15:08:12 +00008343
8344 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008345 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008346 E->getRParenLoc());
8347}
Mike Stump11289f42009-09-09 15:08:12 +00008348
Douglas Gregora16548e2009-08-11 05:31:07 +00008349template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008350ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008351TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008352 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008353 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008354 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008355
John McCalldadc5752010-08-24 06:29:42 +00008356 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008357 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008358 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008359
John McCalldadc5752010-08-24 06:29:42 +00008360 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008361 if (RHS.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() &&
8365 Cond.get() == E->getCond() &&
8366 LHS.get() == E->getLHS() &&
8367 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008368 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008369
Douglas Gregora16548e2009-08-11 05:31:07 +00008370 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008371 Cond.get(), LHS.get(), RHS.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>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008378 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008379}
8380
8381template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008382ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008383TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008384 switch (E->getOperator()) {
8385 case OO_New:
8386 case OO_Delete:
8387 case OO_Array_New:
8388 case OO_Array_Delete:
8389 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008390
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008391 case OO_Call: {
8392 // This is a call to an object's operator().
8393 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8394
8395 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008396 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008397 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008398 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008399
8400 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008401 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8402 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008403
8404 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008405 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008406 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008407 Args))
8408 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008409
John McCallb268a282010-08-23 23:25:46 +00008410 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008411 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008412 E->getLocEnd());
8413 }
8414
8415#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8416 case OO_##Name:
8417#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8418#include "clang/Basic/OperatorKinds.def"
8419 case OO_Subscript:
8420 // Handled below.
8421 break;
8422
8423 case OO_Conditional:
8424 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008425
8426 case OO_None:
8427 case NUM_OVERLOADED_OPERATORS:
8428 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008429 }
8430
John McCalldadc5752010-08-24 06:29:42 +00008431 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008432 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008433 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008434
Richard Smithdb2630f2012-10-21 03:28:35 +00008435 ExprResult First;
8436 if (E->getOperator() == OO_Amp)
8437 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8438 else
8439 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008440 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008441 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008442
John McCalldadc5752010-08-24 06:29:42 +00008443 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008444 if (E->getNumArgs() == 2) {
8445 Second = getDerived().TransformExpr(E->getArg(1));
8446 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008447 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008448 }
Mike Stump11289f42009-09-09 15:08:12 +00008449
Douglas Gregora16548e2009-08-11 05:31:07 +00008450 if (!getDerived().AlwaysRebuild() &&
8451 Callee.get() == E->getCallee() &&
8452 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008453 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008454 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008455
Lang Hames5de91cc2012-10-02 04:45:10 +00008456 Sema::FPContractStateRAII FPContractState(getSema());
8457 getSema().FPFeatures.fp_contract = E->isFPContractable();
8458
Douglas Gregora16548e2009-08-11 05:31:07 +00008459 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8460 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008461 Callee.get(),
8462 First.get(),
8463 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008464}
Mike Stump11289f42009-09-09 15:08:12 +00008465
Douglas Gregora16548e2009-08-11 05:31:07 +00008466template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008467ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008468TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8469 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008470}
Mike Stump11289f42009-09-09 15:08:12 +00008471
Douglas Gregora16548e2009-08-11 05:31:07 +00008472template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008473ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008474TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8475 // Transform the callee.
8476 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8477 if (Callee.isInvalid())
8478 return ExprError();
8479
8480 // Transform exec config.
8481 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8482 if (EC.isInvalid())
8483 return ExprError();
8484
8485 // Transform arguments.
8486 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008487 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008488 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008489 &ArgChanged))
8490 return ExprError();
8491
8492 if (!getDerived().AlwaysRebuild() &&
8493 Callee.get() == E->getCallee() &&
8494 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008495 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008496
8497 // FIXME: Wrong source location information for the '('.
8498 SourceLocation FakeLParenLoc
8499 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8500 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008501 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008502 E->getRParenLoc(), EC.get());
8503}
8504
8505template<typename Derived>
8506ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008507TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008508 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8509 if (!Type)
8510 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008511
John McCalldadc5752010-08-24 06:29:42 +00008512 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008513 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008514 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008515 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008516
Douglas Gregora16548e2009-08-11 05:31:07 +00008517 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008518 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008519 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008520 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008521 return getDerived().RebuildCXXNamedCastExpr(
8522 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8523 Type, E->getAngleBrackets().getEnd(),
8524 // FIXME. this should be '(' location
8525 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008526}
Mike Stump11289f42009-09-09 15:08:12 +00008527
Douglas Gregora16548e2009-08-11 05:31:07 +00008528template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008529ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008530TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8531 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008532}
Mike Stump11289f42009-09-09 15:08:12 +00008533
8534template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008535ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008536TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8537 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008538}
8539
Douglas Gregora16548e2009-08-11 05:31:07 +00008540template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008541ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008542TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008543 CXXReinterpretCastExpr *E) {
8544 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008545}
Mike Stump11289f42009-09-09 15:08:12 +00008546
Douglas Gregora16548e2009-08-11 05:31:07 +00008547template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008548ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008549TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8550 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008551}
Mike Stump11289f42009-09-09 15:08:12 +00008552
Douglas Gregora16548e2009-08-11 05:31:07 +00008553template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008554ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008555TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008556 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008557 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8558 if (!Type)
8559 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008560
John McCalldadc5752010-08-24 06:29:42 +00008561 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008562 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008563 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008564 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008565
Douglas Gregora16548e2009-08-11 05:31:07 +00008566 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008567 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008568 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008569 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008570
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008571 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008572 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008573 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008574 E->getRParenLoc());
8575}
Mike Stump11289f42009-09-09 15:08:12 +00008576
Douglas Gregora16548e2009-08-11 05:31:07 +00008577template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008578ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008579TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008580 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008581 TypeSourceInfo *TInfo
8582 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8583 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008584 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008585
Douglas Gregora16548e2009-08-11 05:31:07 +00008586 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008587 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008588 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008589
Douglas Gregor9da64192010-04-26 22:37:10 +00008590 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8591 E->getLocStart(),
8592 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008593 E->getLocEnd());
8594 }
Mike Stump11289f42009-09-09 15:08:12 +00008595
Eli Friedman456f0182012-01-20 01:26:23 +00008596 // We don't know whether the subexpression is potentially evaluated until
8597 // after we perform semantic analysis. We speculatively assume it is
8598 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008599 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008600 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8601 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008602
John McCalldadc5752010-08-24 06:29:42 +00008603 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008604 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008605 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008606
Douglas Gregora16548e2009-08-11 05:31:07 +00008607 if (!getDerived().AlwaysRebuild() &&
8608 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008609 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008610
Douglas Gregor9da64192010-04-26 22:37:10 +00008611 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8612 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008613 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008614 E->getLocEnd());
8615}
8616
8617template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008618ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008619TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8620 if (E->isTypeOperand()) {
8621 TypeSourceInfo *TInfo
8622 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8623 if (!TInfo)
8624 return ExprError();
8625
8626 if (!getDerived().AlwaysRebuild() &&
8627 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008628 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008629
Douglas Gregor69735112011-03-06 17:40:41 +00008630 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008631 E->getLocStart(),
8632 TInfo,
8633 E->getLocEnd());
8634 }
8635
Francois Pichet9f4f2072010-09-08 12:20:18 +00008636 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8637
8638 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8639 if (SubExpr.isInvalid())
8640 return ExprError();
8641
8642 if (!getDerived().AlwaysRebuild() &&
8643 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008644 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008645
8646 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8647 E->getLocStart(),
8648 SubExpr.get(),
8649 E->getLocEnd());
8650}
8651
8652template<typename Derived>
8653ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008654TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008655 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008656}
Mike Stump11289f42009-09-09 15:08:12 +00008657
Douglas Gregora16548e2009-08-11 05:31:07 +00008658template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008659ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008660TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008661 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008662 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008663}
Mike Stump11289f42009-09-09 15:08:12 +00008664
Douglas Gregora16548e2009-08-11 05:31:07 +00008665template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008666ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008667TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008668 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008669
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008670 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8671 // Make sure that we capture 'this'.
8672 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008673 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008674 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008675
Douglas Gregorb15af892010-01-07 23:12:05 +00008676 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008677}
Mike Stump11289f42009-09-09 15:08:12 +00008678
Douglas Gregora16548e2009-08-11 05:31:07 +00008679template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008680ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008681TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008682 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008683 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008684 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008685
Douglas Gregora16548e2009-08-11 05:31:07 +00008686 if (!getDerived().AlwaysRebuild() &&
8687 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008688 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008689
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008690 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8691 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008692}
Mike Stump11289f42009-09-09 15:08:12 +00008693
Douglas Gregora16548e2009-08-11 05:31:07 +00008694template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008695ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008696TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008697 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008698 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8699 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008700 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008701 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008702
Chandler Carruth794da4c2010-02-08 06:42:49 +00008703 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008704 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008705 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008706
Douglas Gregor033f6752009-12-23 23:03:06 +00008707 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008708}
Mike Stump11289f42009-09-09 15:08:12 +00008709
Douglas Gregora16548e2009-08-11 05:31:07 +00008710template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008711ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008712TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8713 FieldDecl *Field
8714 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8715 E->getField()));
8716 if (!Field)
8717 return ExprError();
8718
8719 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008720 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008721
8722 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8723}
8724
8725template<typename Derived>
8726ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008727TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8728 CXXScalarValueInitExpr *E) {
8729 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8730 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008731 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008732
Douglas Gregora16548e2009-08-11 05:31:07 +00008733 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008734 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008735 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008736
Chad Rosier1dcde962012-08-08 18:46:20 +00008737 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008738 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008739 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008740}
Mike Stump11289f42009-09-09 15:08:12 +00008741
Douglas Gregora16548e2009-08-11 05:31:07 +00008742template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008743ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008744TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008745 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008746 TypeSourceInfo *AllocTypeInfo
8747 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8748 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008749 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008750
Douglas Gregora16548e2009-08-11 05:31:07 +00008751 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008752 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008753 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008754 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008755
Douglas Gregora16548e2009-08-11 05:31:07 +00008756 // Transform the placement arguments (if any).
8757 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008758 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008759 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008760 E->getNumPlacementArgs(), true,
8761 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008762 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008763
Sebastian Redl6047f072012-02-16 12:22:20 +00008764 // Transform the initializer (if any).
8765 Expr *OldInit = E->getInitializer();
8766 ExprResult NewInit;
8767 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008768 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008769 if (NewInit.isInvalid())
8770 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008771
Sebastian Redl6047f072012-02-16 12:22:20 +00008772 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008773 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008774 if (E->getOperatorNew()) {
8775 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008776 getDerived().TransformDecl(E->getLocStart(),
8777 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008778 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008779 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008780 }
8781
Craig Topperc3ec1492014-05-26 06:22:03 +00008782 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008783 if (E->getOperatorDelete()) {
8784 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008785 getDerived().TransformDecl(E->getLocStart(),
8786 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008787 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008788 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008789 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008790
Douglas Gregora16548e2009-08-11 05:31:07 +00008791 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008792 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008793 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008794 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008795 OperatorNew == E->getOperatorNew() &&
8796 OperatorDelete == E->getOperatorDelete() &&
8797 !ArgumentChanged) {
8798 // Mark any declarations we need as referenced.
8799 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008800 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008801 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008802 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008803 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008804
Sebastian Redl6047f072012-02-16 12:22:20 +00008805 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008806 QualType ElementType
8807 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8808 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8809 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8810 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008811 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008812 }
8813 }
8814 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008815
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008816 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008817 }
Mike Stump11289f42009-09-09 15:08:12 +00008818
Douglas Gregor0744ef62010-09-07 21:49:58 +00008819 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008820 if (!ArraySize.get()) {
8821 // If no array size was specified, but the new expression was
8822 // instantiated with an array type (e.g., "new T" where T is
8823 // instantiated with "int[4]"), extract the outer bound from the
8824 // array type as our array size. We do this with constant and
8825 // dependently-sized array types.
8826 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8827 if (!ArrayT) {
8828 // Do nothing
8829 } else if (const ConstantArrayType *ConsArrayT
8830 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008831 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8832 SemaRef.Context.getSizeType(),
8833 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008834 AllocType = ConsArrayT->getElementType();
8835 } else if (const DependentSizedArrayType *DepArrayT
8836 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8837 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008838 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008839 AllocType = DepArrayT->getElementType();
8840 }
8841 }
8842 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008843
Douglas Gregora16548e2009-08-11 05:31:07 +00008844 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8845 E->isGlobalNew(),
8846 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008847 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008848 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008849 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008850 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008851 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008852 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008853 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008854 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008855}
Mike Stump11289f42009-09-09 15:08:12 +00008856
Douglas Gregora16548e2009-08-11 05:31:07 +00008857template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008858ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008859TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008860 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008861 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008862 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008863
Douglas Gregord2d9da02010-02-26 00:38:10 +00008864 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008865 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008866 if (E->getOperatorDelete()) {
8867 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008868 getDerived().TransformDecl(E->getLocStart(),
8869 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008870 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008871 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008872 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008873
Douglas Gregora16548e2009-08-11 05:31:07 +00008874 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008875 Operand.get() == E->getArgument() &&
8876 OperatorDelete == E->getOperatorDelete()) {
8877 // Mark any declarations we need as referenced.
8878 // FIXME: instantiation-specific.
8879 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008880 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008881
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008882 if (!E->getArgument()->isTypeDependent()) {
8883 QualType Destroyed = SemaRef.Context.getBaseElementType(
8884 E->getDestroyedType());
8885 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8886 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008887 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008888 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008889 }
8890 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008891
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008892 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008893 }
Mike Stump11289f42009-09-09 15:08:12 +00008894
Douglas Gregora16548e2009-08-11 05:31:07 +00008895 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8896 E->isGlobalDelete(),
8897 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008898 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008899}
Mike Stump11289f42009-09-09 15:08:12 +00008900
Douglas Gregora16548e2009-08-11 05:31:07 +00008901template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008902ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008903TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008904 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008905 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008906 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008907 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008908
John McCallba7bf592010-08-24 05:47:05 +00008909 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008910 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008911 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008912 E->getOperatorLoc(),
8913 E->isArrow()? tok::arrow : tok::period,
8914 ObjectTypePtr,
8915 MayBePseudoDestructor);
8916 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008917 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008918
John McCallba7bf592010-08-24 05:47:05 +00008919 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008920 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8921 if (QualifierLoc) {
8922 QualifierLoc
8923 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8924 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008925 return ExprError();
8926 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008927 CXXScopeSpec SS;
8928 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008929
Douglas Gregor678f90d2010-02-25 01:56:36 +00008930 PseudoDestructorTypeStorage Destroyed;
8931 if (E->getDestroyedTypeInfo()) {
8932 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008933 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008934 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008935 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008936 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008937 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008938 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008939 // We aren't likely to be able to resolve the identifier down to a type
8940 // now anyway, so just retain the identifier.
8941 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8942 E->getDestroyedTypeLoc());
8943 } else {
8944 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008945 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008946 *E->getDestroyedTypeIdentifier(),
8947 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008948 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008949 SS, ObjectTypePtr,
8950 false);
8951 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008952 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008953
Douglas Gregor678f90d2010-02-25 01:56:36 +00008954 Destroyed
8955 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8956 E->getDestroyedTypeLoc());
8957 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008958
Craig Topperc3ec1492014-05-26 06:22:03 +00008959 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008960 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008961 CXXScopeSpec EmptySS;
8962 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008963 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008964 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008965 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008966 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008967
John McCallb268a282010-08-23 23:25:46 +00008968 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008969 E->getOperatorLoc(),
8970 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008971 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008972 ScopeTypeInfo,
8973 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008974 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008975 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008976}
Mike Stump11289f42009-09-09 15:08:12 +00008977
Douglas Gregorad8a3362009-09-04 17:36:40 +00008978template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008979ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008980TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008981 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008982 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8983 Sema::LookupOrdinaryName);
8984
8985 // Transform all the decls.
8986 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8987 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008988 NamedDecl *InstD = static_cast<NamedDecl*>(
8989 getDerived().TransformDecl(Old->getNameLoc(),
8990 *I));
John McCall84d87672009-12-10 09:41:52 +00008991 if (!InstD) {
8992 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8993 // This can happen because of dependent hiding.
8994 if (isa<UsingShadowDecl>(*I))
8995 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008996 else {
8997 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008998 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008999 }
John McCall84d87672009-12-10 09:41:52 +00009000 }
John McCalle66edc12009-11-24 19:00:30 +00009001
9002 // Expand using declarations.
9003 if (isa<UsingDecl>(InstD)) {
9004 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009005 for (auto *I : UD->shadows())
9006 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009007 continue;
9008 }
9009
9010 R.addDecl(InstD);
9011 }
9012
9013 // Resolve a kind, but don't do any further analysis. If it's
9014 // ambiguous, the callee needs to deal with it.
9015 R.resolveKind();
9016
9017 // Rebuild the nested-name qualifier, if present.
9018 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009019 if (Old->getQualifierLoc()) {
9020 NestedNameSpecifierLoc QualifierLoc
9021 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9022 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009023 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009024
Douglas Gregor0da1d432011-02-28 20:01:57 +00009025 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009026 }
9027
Douglas Gregor9262f472010-04-27 18:19:34 +00009028 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009029 CXXRecordDecl *NamingClass
9030 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9031 Old->getNameLoc(),
9032 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009033 if (!NamingClass) {
9034 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009035 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009036 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009037
Douglas Gregorda7be082010-04-27 16:10:10 +00009038 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009039 }
9040
Abramo Bagnara7945c982012-01-27 09:46:47 +00009041 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9042
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009043 // If we have neither explicit template arguments, nor the template keyword,
9044 // it's a normal declaration name.
9045 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00009046 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
9047
9048 // If we have template arguments, rebuild them, then rebuild the
9049 // templateid expression.
9050 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009051 if (Old->hasExplicitTemplateArgs() &&
9052 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009053 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009054 TransArgs)) {
9055 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009056 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009057 }
John McCalle66edc12009-11-24 19:00:30 +00009058
Abramo Bagnara7945c982012-01-27 09:46:47 +00009059 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009060 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009061}
Mike Stump11289f42009-09-09 15:08:12 +00009062
Douglas Gregora16548e2009-08-11 05:31:07 +00009063template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009064ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009065TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9066 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009067 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009068 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9069 TypeSourceInfo *From = E->getArg(I);
9070 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009071 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009072 TypeLocBuilder TLB;
9073 TLB.reserve(FromTL.getFullDataSize());
9074 QualType To = getDerived().TransformType(TLB, FromTL);
9075 if (To.isNull())
9076 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009077
Douglas Gregor29c42f22012-02-24 07:38:34 +00009078 if (To == From->getType())
9079 Args.push_back(From);
9080 else {
9081 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9082 ArgChanged = true;
9083 }
9084 continue;
9085 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009086
Douglas Gregor29c42f22012-02-24 07:38:34 +00009087 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009088
Douglas Gregor29c42f22012-02-24 07:38:34 +00009089 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009090 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009091 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9092 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9093 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009094
Douglas Gregor29c42f22012-02-24 07:38:34 +00009095 // Determine whether the set of unexpanded parameter packs can and should
9096 // be expanded.
9097 bool Expand = true;
9098 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009099 Optional<unsigned> OrigNumExpansions =
9100 ExpansionTL.getTypePtr()->getNumExpansions();
9101 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009102 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9103 PatternTL.getSourceRange(),
9104 Unexpanded,
9105 Expand, RetainExpansion,
9106 NumExpansions))
9107 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009108
Douglas Gregor29c42f22012-02-24 07:38:34 +00009109 if (!Expand) {
9110 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009111 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009112 // expansion.
9113 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009114
Douglas Gregor29c42f22012-02-24 07:38:34 +00009115 TypeLocBuilder TLB;
9116 TLB.reserve(From->getTypeLoc().getFullDataSize());
9117
9118 QualType To = getDerived().TransformType(TLB, PatternTL);
9119 if (To.isNull())
9120 return ExprError();
9121
Chad Rosier1dcde962012-08-08 18:46:20 +00009122 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009123 PatternTL.getSourceRange(),
9124 ExpansionTL.getEllipsisLoc(),
9125 NumExpansions);
9126 if (To.isNull())
9127 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009128
Douglas Gregor29c42f22012-02-24 07:38:34 +00009129 PackExpansionTypeLoc ToExpansionTL
9130 = TLB.push<PackExpansionTypeLoc>(To);
9131 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9132 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9133 continue;
9134 }
9135
9136 // Expand the pack expansion by substituting for each argument in the
9137 // pack(s).
9138 for (unsigned I = 0; I != *NumExpansions; ++I) {
9139 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9140 TypeLocBuilder TLB;
9141 TLB.reserve(PatternTL.getFullDataSize());
9142 QualType To = getDerived().TransformType(TLB, PatternTL);
9143 if (To.isNull())
9144 return ExprError();
9145
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009146 if (To->containsUnexpandedParameterPack()) {
9147 To = getDerived().RebuildPackExpansionType(To,
9148 PatternTL.getSourceRange(),
9149 ExpansionTL.getEllipsisLoc(),
9150 NumExpansions);
9151 if (To.isNull())
9152 return ExprError();
9153
9154 PackExpansionTypeLoc ToExpansionTL
9155 = TLB.push<PackExpansionTypeLoc>(To);
9156 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9157 }
9158
Douglas Gregor29c42f22012-02-24 07:38:34 +00009159 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9160 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009161
Douglas Gregor29c42f22012-02-24 07:38:34 +00009162 if (!RetainExpansion)
9163 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009164
Douglas Gregor29c42f22012-02-24 07:38:34 +00009165 // If we're supposed to retain a pack expansion, do so by temporarily
9166 // forgetting the partially-substituted parameter pack.
9167 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9168
9169 TypeLocBuilder TLB;
9170 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009171
Douglas Gregor29c42f22012-02-24 07:38:34 +00009172 QualType To = getDerived().TransformType(TLB, PatternTL);
9173 if (To.isNull())
9174 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009175
9176 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009177 PatternTL.getSourceRange(),
9178 ExpansionTL.getEllipsisLoc(),
9179 NumExpansions);
9180 if (To.isNull())
9181 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009182
Douglas Gregor29c42f22012-02-24 07:38:34 +00009183 PackExpansionTypeLoc ToExpansionTL
9184 = TLB.push<PackExpansionTypeLoc>(To);
9185 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9186 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9187 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009188
Douglas Gregor29c42f22012-02-24 07:38:34 +00009189 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009190 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009191
9192 return getDerived().RebuildTypeTrait(E->getTrait(),
9193 E->getLocStart(),
9194 Args,
9195 E->getLocEnd());
9196}
9197
9198template<typename Derived>
9199ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009200TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9201 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9202 if (!T)
9203 return ExprError();
9204
9205 if (!getDerived().AlwaysRebuild() &&
9206 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009207 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009208
9209 ExprResult SubExpr;
9210 {
9211 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9212 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9213 if (SubExpr.isInvalid())
9214 return ExprError();
9215
9216 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009217 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009218 }
9219
9220 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9221 E->getLocStart(),
9222 T,
9223 SubExpr.get(),
9224 E->getLocEnd());
9225}
9226
9227template<typename Derived>
9228ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009229TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9230 ExprResult SubExpr;
9231 {
9232 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9233 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9234 if (SubExpr.isInvalid())
9235 return ExprError();
9236
9237 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009238 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009239 }
9240
9241 return getDerived().RebuildExpressionTrait(
9242 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9243}
9244
Reid Kleckner32506ed2014-06-12 23:03:48 +00009245template <typename Derived>
9246ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9247 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9248 TypeSourceInfo **RecoveryTSI) {
9249 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9250 DRE, AddrTaken, RecoveryTSI);
9251
9252 // Propagate both errors and recovered types, which return ExprEmpty.
9253 if (!NewDRE.isUsable())
9254 return NewDRE;
9255
9256 // We got an expr, wrap it up in parens.
9257 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9258 return PE;
9259 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9260 PE->getRParen());
9261}
9262
9263template <typename Derived>
9264ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9265 DependentScopeDeclRefExpr *E) {
9266 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9267 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009268}
9269
9270template<typename Derived>
9271ExprResult
9272TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9273 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009274 bool IsAddressOfOperand,
9275 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009276 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009277 NestedNameSpecifierLoc QualifierLoc
9278 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9279 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009280 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009281 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009282
John McCall31f82722010-11-12 08:19:04 +00009283 // TODO: If this is a conversion-function-id, verify that the
9284 // destination type name (if present) resolves the same way after
9285 // instantiation as it did in the local scope.
9286
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009287 DeclarationNameInfo NameInfo
9288 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9289 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009290 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009291
John McCalle66edc12009-11-24 19:00:30 +00009292 if (!E->hasExplicitTemplateArgs()) {
9293 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009294 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009295 // Note: it is sufficient to compare the Name component of NameInfo:
9296 // if name has not changed, DNLoc has not changed either.
9297 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009298 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009299
Reid Kleckner32506ed2014-06-12 23:03:48 +00009300 return getDerived().RebuildDependentScopeDeclRefExpr(
9301 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9302 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009303 }
John McCall6b51f282009-11-23 01:53:49 +00009304
9305 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009306 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9307 E->getNumTemplateArgs(),
9308 TransArgs))
9309 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009310
Reid Kleckner32506ed2014-06-12 23:03:48 +00009311 return getDerived().RebuildDependentScopeDeclRefExpr(
9312 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9313 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009314}
9315
9316template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009317ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009318TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009319 // CXXConstructExprs other than for list-initialization and
9320 // CXXTemporaryObjectExpr are always implicit, so when we have
9321 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009322 if ((E->getNumArgs() == 1 ||
9323 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009324 (!getDerived().DropCallArgument(E->getArg(0))) &&
9325 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009326 return getDerived().TransformExpr(E->getArg(0));
9327
Douglas Gregora16548e2009-08-11 05:31:07 +00009328 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9329
9330 QualType T = getDerived().TransformType(E->getType());
9331 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009332 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009333
9334 CXXConstructorDecl *Constructor
9335 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009336 getDerived().TransformDecl(E->getLocStart(),
9337 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009338 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009339 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009340
Douglas Gregora16548e2009-08-11 05:31:07 +00009341 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009342 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009343 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009344 &ArgumentChanged))
9345 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009346
Douglas Gregora16548e2009-08-11 05:31:07 +00009347 if (!getDerived().AlwaysRebuild() &&
9348 T == E->getType() &&
9349 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009350 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009351 // Mark the constructor as referenced.
9352 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009353 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009354 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009355 }
Mike Stump11289f42009-09-09 15:08:12 +00009356
Douglas Gregordb121ba2009-12-14 16:27:04 +00009357 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9358 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009359 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009360 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009361 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009362 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009363 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009364 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009365 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009366}
Mike Stump11289f42009-09-09 15:08:12 +00009367
Douglas Gregora16548e2009-08-11 05:31:07 +00009368/// \brief Transform a C++ temporary-binding expression.
9369///
Douglas Gregor363b1512009-12-24 18:51:59 +00009370/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9371/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009372template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009373ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009374TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009375 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009376}
Mike Stump11289f42009-09-09 15:08:12 +00009377
John McCall5d413782010-12-06 08:20:24 +00009378/// \brief Transform a C++ expression that contains cleanups that should
9379/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009380///
John McCall5d413782010-12-06 08:20:24 +00009381/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009382/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009383template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009384ExprResult
John McCall5d413782010-12-06 08:20:24 +00009385TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009386 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009387}
Mike Stump11289f42009-09-09 15:08:12 +00009388
Douglas Gregora16548e2009-08-11 05:31:07 +00009389template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009390ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009391TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009392 CXXTemporaryObjectExpr *E) {
9393 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9394 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009395 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009396
Douglas Gregora16548e2009-08-11 05:31:07 +00009397 CXXConstructorDecl *Constructor
9398 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009399 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009400 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009401 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009402 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009403
Douglas Gregora16548e2009-08-11 05:31:07 +00009404 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009405 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009406 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009407 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009408 &ArgumentChanged))
9409 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009410
Douglas Gregora16548e2009-08-11 05:31:07 +00009411 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009412 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009413 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009414 !ArgumentChanged) {
9415 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009416 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009417 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009418 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009419
Richard Smithd59b8322012-12-19 01:39:02 +00009420 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009421 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9422 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009423 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009424 E->getLocEnd());
9425}
Mike Stump11289f42009-09-09 15:08:12 +00009426
Douglas Gregora16548e2009-08-11 05:31:07 +00009427template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009428ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009429TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009430 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009431 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009432 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009433 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9434 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009435 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009436 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009437 CEnd = E->capture_end();
9438 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009439 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009440 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009441 EnterExpressionEvaluationContext EEEC(getSema(),
9442 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009443 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9444 C->getCapturedVar()->getInit(),
9445 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009446
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009447 if (NewExprInitResult.isInvalid())
9448 return ExprError();
9449 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009450
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009451 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009452 QualType NewInitCaptureType =
9453 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
9454 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009455 NewExprInit);
9456 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009457 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9458 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009459 }
9460
Faisal Vali2cba1332013-10-23 06:44:28 +00009461 // Transform the template parameters, and add them to the current
9462 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009463 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009464 E->getTemplateParameterList());
9465
Richard Smith01014ce2014-11-20 23:53:14 +00009466 // Transform the type of the original lambda's call operator.
9467 // The transformation MUST be done in the CurrentInstantiationScope since
9468 // it introduces a mapping of the original to the newly created
9469 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009470 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009471 {
9472 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9473 FunctionProtoTypeLoc OldCallOpFPTL =
9474 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009475
9476 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009477 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009478 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009479 QualType NewCallOpType = TransformFunctionProtoType(
9480 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009481 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9482 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9483 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009484 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009485 if (NewCallOpType.isNull())
9486 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009487 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9488 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009489 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009490
Richard Smithc38498f2015-04-27 21:27:54 +00009491 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9492 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9493 LSI->GLTemplateParameterList = TPL;
9494
Eli Friedmand564afb2012-09-19 01:18:11 +00009495 // Create the local class that will describe the lambda.
9496 CXXRecordDecl *Class
9497 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009498 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009499 /*KnownDependent=*/false,
9500 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009501 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9502
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009503 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009504 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9505 Class, E->getIntroducerRange(), NewCallOpTSI,
9506 E->getCallOperator()->getLocEnd(),
9507 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009508 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009509
Faisal Vali2cba1332013-10-23 06:44:28 +00009510 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009511 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009512
Douglas Gregorb4328232012-02-14 00:00:48 +00009513 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009514 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009515 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009516
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009517 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009518 getSema().buildLambdaScope(LSI, NewCallOperator,
9519 E->getIntroducerRange(),
9520 E->getCaptureDefault(),
9521 E->getCaptureDefaultLoc(),
9522 E->hasExplicitParameters(),
9523 E->hasExplicitResultType(),
9524 E->isMutable());
9525
9526 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009527
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009528 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009529 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009530 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009531 CEnd = E->capture_end();
9532 C != CEnd; ++C) {
9533 // When we hit the first implicit capture, tell Sema that we've finished
9534 // the list of explicit captures.
9535 if (!FinishedExplicitCaptures && C->isImplicit()) {
9536 getSema().finishLambdaExplicitCaptures(LSI);
9537 FinishedExplicitCaptures = true;
9538 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009539
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009540 // Capturing 'this' is trivial.
9541 if (C->capturesThis()) {
9542 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9543 continue;
9544 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009545 // Captured expression will be recaptured during captured variables
9546 // rebuilding.
9547 if (C->capturesVLAType())
9548 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009549
Richard Smithba71c082013-05-16 06:20:58 +00009550 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +00009551 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009552 InitCaptureInfoTy InitExprTypePair =
9553 InitCaptureExprsAndTypes[C - E->capture_begin()];
9554 ExprResult Init = InitExprTypePair.first;
9555 QualType InitQualType = InitExprTypePair.second;
9556 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009557 Invalid = true;
9558 continue;
9559 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009560 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009561 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9562 OldVD->getLocation(), InitExprTypePair.second,
9563 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009564 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009565 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009566 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009567 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009568 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009569 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009570 continue;
9571 }
9572
9573 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9574
Douglas Gregor3e308b12012-02-14 19:27:52 +00009575 // Determine the capture kind for Sema.
9576 Sema::TryCaptureKind Kind
9577 = C->isImplicit()? Sema::TryCapture_Implicit
9578 : C->getCaptureKind() == LCK_ByCopy
9579 ? Sema::TryCapture_ExplicitByVal
9580 : Sema::TryCapture_ExplicitByRef;
9581 SourceLocation EllipsisLoc;
9582 if (C->isPackExpansion()) {
9583 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9584 bool ShouldExpand = false;
9585 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009586 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009587 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9588 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009589 Unexpanded,
9590 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009591 NumExpansions)) {
9592 Invalid = true;
9593 continue;
9594 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009595
Douglas Gregor3e308b12012-02-14 19:27:52 +00009596 if (ShouldExpand) {
9597 // The transform has determined that we should perform an expansion;
9598 // transform and capture each of the arguments.
9599 // expansion of the pattern. Do so.
9600 VarDecl *Pack = C->getCapturedVar();
9601 for (unsigned I = 0; I != *NumExpansions; ++I) {
9602 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9603 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009604 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009605 Pack));
9606 if (!CapturedVar) {
9607 Invalid = true;
9608 continue;
9609 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009610
Douglas Gregor3e308b12012-02-14 19:27:52 +00009611 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009612 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9613 }
Richard Smith9467be42014-06-06 17:33:35 +00009614
9615 // FIXME: Retain a pack expansion if RetainExpansion is true.
9616
Douglas Gregor3e308b12012-02-14 19:27:52 +00009617 continue;
9618 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009619
Douglas Gregor3e308b12012-02-14 19:27:52 +00009620 EllipsisLoc = C->getEllipsisLoc();
9621 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009622
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009623 // Transform the captured variable.
9624 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009625 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009626 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009627 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009628 Invalid = true;
9629 continue;
9630 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009631
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009632 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +00009633 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
9634 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009635 }
9636 if (!FinishedExplicitCaptures)
9637 getSema().finishLambdaExplicitCaptures(LSI);
9638
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009639 // Enter a new evaluation context to insulate the lambda from any
9640 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009641 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009642
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009643 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +00009644 StmtResult Body =
9645 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
9646
9647 // ActOnLambda* will pop the function scope for us.
9648 FuncScopeCleanup.disable();
9649
Douglas Gregorb4328232012-02-14 00:00:48 +00009650 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +00009651 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +00009652 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009653 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009654 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009655 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009656
Richard Smithc38498f2015-04-27 21:27:54 +00009657 // Copy the LSI before ActOnFinishFunctionBody removes it.
9658 // FIXME: This is dumb. Store the lambda information somewhere that outlives
9659 // the call operator.
9660 auto LSICopy = *LSI;
9661 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
9662 /*IsInstantiation*/ true);
9663 SavedContext.pop();
9664
9665 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
9666 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +00009667}
9668
9669template<typename Derived>
9670ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009671TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009672 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009673 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9674 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009675 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009676
Douglas Gregora16548e2009-08-11 05:31:07 +00009677 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009678 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009679 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009680 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009681 &ArgumentChanged))
9682 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009683
Douglas Gregora16548e2009-08-11 05:31:07 +00009684 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009685 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009686 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009687 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009688
Douglas Gregora16548e2009-08-11 05:31:07 +00009689 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009690 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009691 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009692 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009693 E->getRParenLoc());
9694}
Mike Stump11289f42009-09-09 15:08:12 +00009695
Douglas Gregora16548e2009-08-11 05:31:07 +00009696template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009697ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009698TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009699 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009700 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009701 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009702 Expr *OldBase;
9703 QualType BaseType;
9704 QualType ObjectType;
9705 if (!E->isImplicitAccess()) {
9706 OldBase = E->getBase();
9707 Base = getDerived().TransformExpr(OldBase);
9708 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009709 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009710
John McCall2d74de92009-12-01 22:10:20 +00009711 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009712 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009713 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009714 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009715 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009716 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009717 ObjectTy,
9718 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009719 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009720 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009721
John McCallba7bf592010-08-24 05:47:05 +00009722 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009723 BaseType = ((Expr*) Base.get())->getType();
9724 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009725 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009726 BaseType = getDerived().TransformType(E->getBaseType());
9727 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9728 }
Mike Stump11289f42009-09-09 15:08:12 +00009729
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009730 // Transform the first part of the nested-name-specifier that qualifies
9731 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009732 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009733 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009734 E->getFirstQualifierFoundInScope(),
9735 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009736
Douglas Gregore16af532011-02-28 18:50:33 +00009737 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009738 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009739 QualifierLoc
9740 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9741 ObjectType,
9742 FirstQualifierInScope);
9743 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009744 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009745 }
Mike Stump11289f42009-09-09 15:08:12 +00009746
Abramo Bagnara7945c982012-01-27 09:46:47 +00009747 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9748
John McCall31f82722010-11-12 08:19:04 +00009749 // TODO: If this is a conversion-function-id, verify that the
9750 // destination type name (if present) resolves the same way after
9751 // instantiation as it did in the local scope.
9752
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009753 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009754 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009755 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009756 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009757
John McCall2d74de92009-12-01 22:10:20 +00009758 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009759 // This is a reference to a member without an explicitly-specified
9760 // template argument list. Optimize for this common case.
9761 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009762 Base.get() == OldBase &&
9763 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009764 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009765 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009766 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009767 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009768
John McCallb268a282010-08-23 23:25:46 +00009769 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009770 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009771 E->isArrow(),
9772 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009773 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009774 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009775 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009776 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009777 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009778 }
9779
John McCall6b51f282009-11-23 01:53:49 +00009780 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009781 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9782 E->getNumTemplateArgs(),
9783 TransArgs))
9784 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009785
John McCallb268a282010-08-23 23:25:46 +00009786 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009787 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009788 E->isArrow(),
9789 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009790 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009791 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009792 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009793 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009794 &TransArgs);
9795}
9796
9797template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009798ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009799TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009800 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009801 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009802 QualType BaseType;
9803 if (!Old->isImplicitAccess()) {
9804 Base = getDerived().TransformExpr(Old->getBase());
9805 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009806 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009807 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009808 Old->isArrow());
9809 if (Base.isInvalid())
9810 return ExprError();
9811 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009812 } else {
9813 BaseType = getDerived().TransformType(Old->getBaseType());
9814 }
John McCall10eae182009-11-30 22:42:35 +00009815
Douglas Gregor0da1d432011-02-28 20:01:57 +00009816 NestedNameSpecifierLoc QualifierLoc;
9817 if (Old->getQualifierLoc()) {
9818 QualifierLoc
9819 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9820 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009821 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009822 }
9823
Abramo Bagnara7945c982012-01-27 09:46:47 +00009824 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9825
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009826 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009827 Sema::LookupOrdinaryName);
9828
9829 // Transform all the decls.
9830 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9831 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009832 NamedDecl *InstD = static_cast<NamedDecl*>(
9833 getDerived().TransformDecl(Old->getMemberLoc(),
9834 *I));
John McCall84d87672009-12-10 09:41:52 +00009835 if (!InstD) {
9836 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9837 // This can happen because of dependent hiding.
9838 if (isa<UsingShadowDecl>(*I))
9839 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009840 else {
9841 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009842 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009843 }
John McCall84d87672009-12-10 09:41:52 +00009844 }
John McCall10eae182009-11-30 22:42:35 +00009845
9846 // Expand using declarations.
9847 if (isa<UsingDecl>(InstD)) {
9848 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009849 for (auto *I : UD->shadows())
9850 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009851 continue;
9852 }
9853
9854 R.addDecl(InstD);
9855 }
9856
9857 R.resolveKind();
9858
Douglas Gregor9262f472010-04-27 18:19:34 +00009859 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009860 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009861 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009862 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009863 Old->getMemberLoc(),
9864 Old->getNamingClass()));
9865 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009866 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009867
Douglas Gregorda7be082010-04-27 16:10:10 +00009868 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009869 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009870
John McCall10eae182009-11-30 22:42:35 +00009871 TemplateArgumentListInfo TransArgs;
9872 if (Old->hasExplicitTemplateArgs()) {
9873 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9874 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009875 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9876 Old->getNumTemplateArgs(),
9877 TransArgs))
9878 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009879 }
John McCall38836f02010-01-15 08:34:02 +00009880
9881 // FIXME: to do this check properly, we will need to preserve the
9882 // first-qualifier-in-scope here, just in case we had a dependent
9883 // base (and therefore couldn't do the check) and a
9884 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009885 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009886
John McCallb268a282010-08-23 23:25:46 +00009887 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009888 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009889 Old->getOperatorLoc(),
9890 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009891 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009892 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009893 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009894 R,
9895 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009896 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009897}
9898
9899template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009900ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009901TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009902 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009903 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9904 if (SubExpr.isInvalid())
9905 return ExprError();
9906
9907 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009908 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009909
9910 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9911}
9912
9913template<typename Derived>
9914ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009915TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009916 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9917 if (Pattern.isInvalid())
9918 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009919
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009920 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009921 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009922
Douglas Gregorb8840002011-01-14 21:20:45 +00009923 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9924 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009925}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009926
9927template<typename Derived>
9928ExprResult
9929TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9930 // If E is not value-dependent, then nothing will change when we transform it.
9931 // Note: This is an instantiation-centric view.
9932 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009933 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009934
9935 // Note: None of the implementations of TryExpandParameterPacks can ever
9936 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009937 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009938 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9939 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009940 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009941 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009942 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009943 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009944 ShouldExpand, RetainExpansion,
9945 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009946 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009947
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009948 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009949 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009950
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009951 NamedDecl *Pack = E->getPack();
9952 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009953 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009954 Pack));
9955 if (!Pack)
9956 return ExprError();
9957 }
9958
Chad Rosier1dcde962012-08-08 18:46:20 +00009959
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009960 // We now know the length of the parameter pack, so build a new expression
9961 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009962 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9963 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009964 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009965}
9966
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009967template<typename Derived>
9968ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009969TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9970 SubstNonTypeTemplateParmPackExpr *E) {
9971 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009972 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009973}
9974
9975template<typename Derived>
9976ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009977TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9978 SubstNonTypeTemplateParmExpr *E) {
9979 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009980 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009981}
9982
9983template<typename Derived>
9984ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009985TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9986 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009987 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009988}
9989
9990template<typename Derived>
9991ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009992TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9993 MaterializeTemporaryExpr *E) {
9994 return getDerived().TransformExpr(E->GetTemporaryExpr());
9995}
Chad Rosier1dcde962012-08-08 18:46:20 +00009996
Douglas Gregorfe314812011-06-21 17:03:29 +00009997template<typename Derived>
9998ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +00009999TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10000 Expr *Pattern = E->getPattern();
10001
10002 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10003 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10004 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10005
10006 // Determine whether the set of unexpanded parameter packs can and should
10007 // be expanded.
10008 bool Expand = true;
10009 bool RetainExpansion = false;
10010 Optional<unsigned> NumExpansions;
10011 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10012 Pattern->getSourceRange(),
10013 Unexpanded,
10014 Expand, RetainExpansion,
10015 NumExpansions))
10016 return true;
10017
10018 if (!Expand) {
10019 // Do not expand any packs here, just transform and rebuild a fold
10020 // expression.
10021 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10022
10023 ExprResult LHS =
10024 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10025 if (LHS.isInvalid())
10026 return true;
10027
10028 ExprResult RHS =
10029 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10030 if (RHS.isInvalid())
10031 return true;
10032
10033 if (!getDerived().AlwaysRebuild() &&
10034 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10035 return E;
10036
10037 return getDerived().RebuildCXXFoldExpr(
10038 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10039 RHS.get(), E->getLocEnd());
10040 }
10041
10042 // The transform has determined that we should perform an elementwise
10043 // expansion of the pattern. Do so.
10044 ExprResult Result = getDerived().TransformExpr(E->getInit());
10045 if (Result.isInvalid())
10046 return true;
10047 bool LeftFold = E->isLeftFold();
10048
10049 // If we're retaining an expansion for a right fold, it is the innermost
10050 // component and takes the init (if any).
10051 if (!LeftFold && RetainExpansion) {
10052 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10053
10054 ExprResult Out = getDerived().TransformExpr(Pattern);
10055 if (Out.isInvalid())
10056 return true;
10057
10058 Result = getDerived().RebuildCXXFoldExpr(
10059 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10060 Result.get(), E->getLocEnd());
10061 if (Result.isInvalid())
10062 return true;
10063 }
10064
10065 for (unsigned I = 0; I != *NumExpansions; ++I) {
10066 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10067 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10068 ExprResult Out = getDerived().TransformExpr(Pattern);
10069 if (Out.isInvalid())
10070 return true;
10071
10072 if (Out.get()->containsUnexpandedParameterPack()) {
10073 // We still have a pack; retain a pack expansion for this slice.
10074 Result = getDerived().RebuildCXXFoldExpr(
10075 E->getLocStart(),
10076 LeftFold ? Result.get() : Out.get(),
10077 E->getOperator(), E->getEllipsisLoc(),
10078 LeftFold ? Out.get() : Result.get(),
10079 E->getLocEnd());
10080 } else if (Result.isUsable()) {
10081 // We've got down to a single element; build a binary operator.
10082 Result = getDerived().RebuildBinaryOperator(
10083 E->getEllipsisLoc(), E->getOperator(),
10084 LeftFold ? Result.get() : Out.get(),
10085 LeftFold ? Out.get() : Result.get());
10086 } else
10087 Result = Out;
10088
10089 if (Result.isInvalid())
10090 return true;
10091 }
10092
10093 // If we're retaining an expansion for a left fold, it is the outermost
10094 // component and takes the complete expansion so far as its init (if any).
10095 if (LeftFold && RetainExpansion) {
10096 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10097
10098 ExprResult Out = getDerived().TransformExpr(Pattern);
10099 if (Out.isInvalid())
10100 return true;
10101
10102 Result = getDerived().RebuildCXXFoldExpr(
10103 E->getLocStart(), Result.get(),
10104 E->getOperator(), E->getEllipsisLoc(),
10105 Out.get(), E->getLocEnd());
10106 if (Result.isInvalid())
10107 return true;
10108 }
10109
10110 // If we had no init and an empty pack, and we're not retaining an expansion,
10111 // then produce a fallback value or error.
10112 if (Result.isUnset())
10113 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10114 E->getOperator());
10115
10116 return Result;
10117}
10118
10119template<typename Derived>
10120ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010121TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10122 CXXStdInitializerListExpr *E) {
10123 return getDerived().TransformExpr(E->getSubExpr());
10124}
10125
10126template<typename Derived>
10127ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010128TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010129 return SemaRef.MaybeBindToTemporary(E);
10130}
10131
10132template<typename Derived>
10133ExprResult
10134TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010135 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010136}
10137
10138template<typename Derived>
10139ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010140TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10141 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10142 if (SubExpr.isInvalid())
10143 return ExprError();
10144
10145 if (!getDerived().AlwaysRebuild() &&
10146 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010147 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010148
10149 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010150}
10151
10152template<typename Derived>
10153ExprResult
10154TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10155 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010156 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010157 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010158 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010159 /*IsCall=*/false, Elements, &ArgChanged))
10160 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010161
Ted Kremeneke65b0862012-03-06 20:05:56 +000010162 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10163 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010164
Ted Kremeneke65b0862012-03-06 20:05:56 +000010165 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10166 Elements.data(),
10167 Elements.size());
10168}
10169
10170template<typename Derived>
10171ExprResult
10172TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010173 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010174 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010175 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010176 bool ArgChanged = false;
10177 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10178 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010179
Ted Kremeneke65b0862012-03-06 20:05:56 +000010180 if (OrigElement.isPackExpansion()) {
10181 // This key/value element is a pack expansion.
10182 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10183 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10184 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10185 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10186
10187 // Determine whether the set of unexpanded parameter packs can
10188 // and should be expanded.
10189 bool Expand = true;
10190 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010191 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10192 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010193 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10194 OrigElement.Value->getLocEnd());
10195 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10196 PatternRange,
10197 Unexpanded,
10198 Expand, RetainExpansion,
10199 NumExpansions))
10200 return ExprError();
10201
10202 if (!Expand) {
10203 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010204 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010205 // expansion.
10206 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10207 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10208 if (Key.isInvalid())
10209 return ExprError();
10210
10211 if (Key.get() != OrigElement.Key)
10212 ArgChanged = true;
10213
10214 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10215 if (Value.isInvalid())
10216 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010217
Ted Kremeneke65b0862012-03-06 20:05:56 +000010218 if (Value.get() != OrigElement.Value)
10219 ArgChanged = true;
10220
Chad Rosier1dcde962012-08-08 18:46:20 +000010221 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010222 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10223 };
10224 Elements.push_back(Expansion);
10225 continue;
10226 }
10227
10228 // Record right away that the argument was changed. This needs
10229 // to happen even if the array expands to nothing.
10230 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010231
Ted Kremeneke65b0862012-03-06 20:05:56 +000010232 // The transform has determined that we should perform an elementwise
10233 // expansion of the pattern. Do so.
10234 for (unsigned I = 0; I != *NumExpansions; ++I) {
10235 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10236 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10237 if (Key.isInvalid())
10238 return ExprError();
10239
10240 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10241 if (Value.isInvalid())
10242 return ExprError();
10243
Chad Rosier1dcde962012-08-08 18:46:20 +000010244 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010245 Key.get(), Value.get(), SourceLocation(), NumExpansions
10246 };
10247
10248 // If any unexpanded parameter packs remain, we still have a
10249 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010250 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010251 if (Key.get()->containsUnexpandedParameterPack() ||
10252 Value.get()->containsUnexpandedParameterPack())
10253 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010254
Ted Kremeneke65b0862012-03-06 20:05:56 +000010255 Elements.push_back(Element);
10256 }
10257
Richard Smith9467be42014-06-06 17:33:35 +000010258 // FIXME: Retain a pack expansion if RetainExpansion is true.
10259
Ted Kremeneke65b0862012-03-06 20:05:56 +000010260 // We've finished with this pack expansion.
10261 continue;
10262 }
10263
10264 // Transform and check key.
10265 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10266 if (Key.isInvalid())
10267 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010268
Ted Kremeneke65b0862012-03-06 20:05:56 +000010269 if (Key.get() != OrigElement.Key)
10270 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010271
Ted Kremeneke65b0862012-03-06 20:05:56 +000010272 // Transform and check value.
10273 ExprResult Value
10274 = getDerived().TransformExpr(OrigElement.Value);
10275 if (Value.isInvalid())
10276 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010277
Ted Kremeneke65b0862012-03-06 20:05:56 +000010278 if (Value.get() != OrigElement.Value)
10279 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010280
10281 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010282 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010283 };
10284 Elements.push_back(Element);
10285 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010286
Ted Kremeneke65b0862012-03-06 20:05:56 +000010287 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10288 return SemaRef.MaybeBindToTemporary(E);
10289
10290 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
10291 Elements.data(),
10292 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +000010293}
10294
Mike Stump11289f42009-09-09 15:08:12 +000010295template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010296ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010297TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010298 TypeSourceInfo *EncodedTypeInfo
10299 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10300 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010301 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010302
Douglas Gregora16548e2009-08-11 05:31:07 +000010303 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010304 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010305 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010306
10307 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010308 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010309 E->getRParenLoc());
10310}
Mike Stump11289f42009-09-09 15:08:12 +000010311
Douglas Gregora16548e2009-08-11 05:31:07 +000010312template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010313ExprResult TreeTransform<Derived>::
10314TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010315 // This is a kind of implicit conversion, and it needs to get dropped
10316 // and recomputed for the same general reasons that ImplicitCastExprs
10317 // do, as well a more specific one: this expression is only valid when
10318 // it appears *immediately* as an argument expression.
10319 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010320}
10321
10322template<typename Derived>
10323ExprResult TreeTransform<Derived>::
10324TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010325 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010326 = getDerived().TransformType(E->getTypeInfoAsWritten());
10327 if (!TSInfo)
10328 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010329
John McCall31168b02011-06-15 23:02:42 +000010330 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010331 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010332 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010333
John McCall31168b02011-06-15 23:02:42 +000010334 if (!getDerived().AlwaysRebuild() &&
10335 TSInfo == E->getTypeInfoAsWritten() &&
10336 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010337 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010338
John McCall31168b02011-06-15 23:02:42 +000010339 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010340 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010341 Result.get());
10342}
10343
10344template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010345ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010346TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010347 // Transform arguments.
10348 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010349 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010350 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010351 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010352 &ArgChanged))
10353 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010354
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010355 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10356 // Class message: transform the receiver type.
10357 TypeSourceInfo *ReceiverTypeInfo
10358 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10359 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010360 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010361
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010362 // If nothing changed, just retain the existing message send.
10363 if (!getDerived().AlwaysRebuild() &&
10364 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010365 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010366
10367 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010368 SmallVector<SourceLocation, 16> SelLocs;
10369 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010370 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10371 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010372 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010373 E->getMethodDecl(),
10374 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010375 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010376 E->getRightLoc());
10377 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010378 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10379 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10380 // Build a new class message send to 'super'.
10381 SmallVector<SourceLocation, 16> SelLocs;
10382 E->getSelectorLocs(SelLocs);
10383 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10384 E->getSelector(),
10385 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000010386 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010387 E->getMethodDecl(),
10388 E->getLeftLoc(),
10389 Args,
10390 E->getRightLoc());
10391 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010392
10393 // Instance message: transform the receiver
10394 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10395 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010396 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010397 = getDerived().TransformExpr(E->getInstanceReceiver());
10398 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010399 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010400
10401 // If nothing changed, just retain the existing message send.
10402 if (!getDerived().AlwaysRebuild() &&
10403 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010404 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010405
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010406 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010407 SmallVector<SourceLocation, 16> SelLocs;
10408 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010409 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010410 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010411 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010412 E->getMethodDecl(),
10413 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010414 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010415 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010416}
10417
Mike Stump11289f42009-09-09 15:08:12 +000010418template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010419ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010420TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010421 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010422}
10423
Mike Stump11289f42009-09-09 15:08:12 +000010424template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010425ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010426TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010427 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010428}
10429
Mike Stump11289f42009-09-09 15:08:12 +000010430template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010431ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010432TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010433 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010434 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010435 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010436 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010437
10438 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010439
Douglas Gregord51d90d2010-04-26 20:11:03 +000010440 // If nothing changed, just retain the existing expression.
10441 if (!getDerived().AlwaysRebuild() &&
10442 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010443 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010444
John McCallb268a282010-08-23 23:25:46 +000010445 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010446 E->getLocation(),
10447 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010448}
10449
Mike Stump11289f42009-09-09 15:08:12 +000010450template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010451ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010452TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010453 // 'super' and types never change. Property never changes. Just
10454 // retain the existing expression.
10455 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010456 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010457
Douglas Gregor9faee212010-04-26 20:47:02 +000010458 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010459 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010460 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010461 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010462
Douglas Gregor9faee212010-04-26 20:47:02 +000010463 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010464
Douglas Gregor9faee212010-04-26 20:47:02 +000010465 // If nothing changed, just retain the existing expression.
10466 if (!getDerived().AlwaysRebuild() &&
10467 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010468 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010469
John McCallb7bd14f2010-12-02 01:19:52 +000010470 if (E->isExplicitProperty())
10471 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10472 E->getExplicitProperty(),
10473 E->getLocation());
10474
10475 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010476 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010477 E->getImplicitPropertyGetter(),
10478 E->getImplicitPropertySetter(),
10479 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010480}
10481
Mike Stump11289f42009-09-09 15:08:12 +000010482template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010483ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010484TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10485 // Transform the base expression.
10486 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10487 if (Base.isInvalid())
10488 return ExprError();
10489
10490 // Transform the key expression.
10491 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10492 if (Key.isInvalid())
10493 return ExprError();
10494
10495 // If nothing changed, just retain the existing expression.
10496 if (!getDerived().AlwaysRebuild() &&
10497 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010498 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010499
Chad Rosier1dcde962012-08-08 18:46:20 +000010500 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010501 Base.get(), Key.get(),
10502 E->getAtIndexMethodDecl(),
10503 E->setAtIndexMethodDecl());
10504}
10505
10506template<typename Derived>
10507ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010508TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010509 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010510 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010511 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010512 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010513
Douglas Gregord51d90d2010-04-26 20:11:03 +000010514 // If nothing changed, just retain the existing expression.
10515 if (!getDerived().AlwaysRebuild() &&
10516 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010517 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010518
John McCallb268a282010-08-23 23:25:46 +000010519 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010520 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010521 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010522}
10523
Mike Stump11289f42009-09-09 15:08:12 +000010524template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010525ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010526TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010527 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010528 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010529 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010530 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010531 SubExprs, &ArgumentChanged))
10532 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010533
Douglas Gregora16548e2009-08-11 05:31:07 +000010534 if (!getDerived().AlwaysRebuild() &&
10535 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010536 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010537
Douglas Gregora16548e2009-08-11 05:31:07 +000010538 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010539 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010540 E->getRParenLoc());
10541}
10542
Mike Stump11289f42009-09-09 15:08:12 +000010543template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010544ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010545TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10546 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10547 if (SrcExpr.isInvalid())
10548 return ExprError();
10549
10550 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10551 if (!Type)
10552 return ExprError();
10553
10554 if (!getDerived().AlwaysRebuild() &&
10555 Type == E->getTypeSourceInfo() &&
10556 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010557 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010558
10559 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10560 SrcExpr.get(), Type,
10561 E->getRParenLoc());
10562}
10563
10564template<typename Derived>
10565ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010566TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010567 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010568
Craig Topperc3ec1492014-05-26 06:22:03 +000010569 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010570 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10571
10572 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010573 blockScope->TheDecl->setBlockMissingReturnType(
10574 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010575
Chris Lattner01cf8db2011-07-20 06:58:45 +000010576 SmallVector<ParmVarDecl*, 4> params;
10577 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010578
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010579 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010580 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
10581 oldBlock->param_begin(),
10582 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010583 nullptr, paramTypes, &params)) {
10584 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010585 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010586 }
John McCall490112f2011-02-04 18:33:18 +000010587
Jordan Rosea0a86be2013-03-08 22:25:36 +000010588 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000010589 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000010590 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000010591
Jordan Rose5c382722013-03-08 21:51:21 +000010592 QualType functionType =
10593 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010594 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000010595 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000010596
10597 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000010598 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000010599 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000010600
10601 if (!oldBlock->blockMissingReturnType()) {
10602 blockScope->HasImplicitReturnType = false;
10603 blockScope->ReturnType = exprResultType;
10604 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010605
John McCall3882ace2011-01-05 12:14:39 +000010606 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000010607 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010608 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010609 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000010610 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010611 }
John McCall3882ace2011-01-05 12:14:39 +000010612
John McCall490112f2011-02-04 18:33:18 +000010613#ifndef NDEBUG
10614 // In builds with assertions, make sure that we captured everything we
10615 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010616 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010617 for (const auto &I : oldBlock->captures()) {
10618 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010619
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010620 // Ignore parameter packs.
10621 if (isa<ParmVarDecl>(oldCapture) &&
10622 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10623 continue;
John McCall490112f2011-02-04 18:33:18 +000010624
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010625 VarDecl *newCapture =
10626 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10627 oldCapture));
10628 assert(blockScope->CaptureMap.count(newCapture));
10629 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010630 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010631 }
10632#endif
10633
10634 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010635 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010636}
10637
Mike Stump11289f42009-09-09 15:08:12 +000010638template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010639ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010640TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010641 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010642}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010643
10644template<typename Derived>
10645ExprResult
10646TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010647 QualType RetTy = getDerived().TransformType(E->getType());
10648 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010649 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010650 SubExprs.reserve(E->getNumSubExprs());
10651 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10652 SubExprs, &ArgumentChanged))
10653 return ExprError();
10654
10655 if (!getDerived().AlwaysRebuild() &&
10656 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010657 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010658
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010659 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010660 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010661}
Chad Rosier1dcde962012-08-08 18:46:20 +000010662
Douglas Gregora16548e2009-08-11 05:31:07 +000010663//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010664// Type reconstruction
10665//===----------------------------------------------------------------------===//
10666
Mike Stump11289f42009-09-09 15:08:12 +000010667template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010668QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10669 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010670 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010671 getDerived().getBaseEntity());
10672}
10673
Mike Stump11289f42009-09-09 15:08:12 +000010674template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010675QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10676 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010677 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010678 getDerived().getBaseEntity());
10679}
10680
Mike Stump11289f42009-09-09 15:08:12 +000010681template<typename Derived>
10682QualType
John McCall70dd5f62009-10-30 00:06:24 +000010683TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10684 bool WrittenAsLValue,
10685 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010686 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010687 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010688}
10689
10690template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010691QualType
John McCall70dd5f62009-10-30 00:06:24 +000010692TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10693 QualType ClassType,
10694 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010695 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10696 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010697}
10698
10699template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000010700QualType TreeTransform<Derived>::RebuildObjCObjectType(
10701 QualType BaseType,
10702 SourceLocation Loc,
10703 SourceLocation TypeArgsLAngleLoc,
10704 ArrayRef<TypeSourceInfo *> TypeArgs,
10705 SourceLocation TypeArgsRAngleLoc,
10706 SourceLocation ProtocolLAngleLoc,
10707 ArrayRef<ObjCProtocolDecl *> Protocols,
10708 ArrayRef<SourceLocation> ProtocolLocs,
10709 SourceLocation ProtocolRAngleLoc) {
10710 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
10711 TypeArgs, TypeArgsRAngleLoc,
10712 ProtocolLAngleLoc, Protocols, ProtocolLocs,
10713 ProtocolRAngleLoc,
10714 /*FailOnError=*/true);
10715}
10716
10717template<typename Derived>
10718QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
10719 QualType PointeeType,
10720 SourceLocation Star) {
10721 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
10722}
10723
10724template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010725QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010726TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10727 ArrayType::ArraySizeModifier SizeMod,
10728 const llvm::APInt *Size,
10729 Expr *SizeExpr,
10730 unsigned IndexTypeQuals,
10731 SourceRange BracketsRange) {
10732 if (SizeExpr || !Size)
10733 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10734 IndexTypeQuals, BracketsRange,
10735 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010736
10737 QualType Types[] = {
10738 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10739 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10740 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010741 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010742 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010743 QualType SizeType;
10744 for (unsigned I = 0; I != NumTypes; ++I)
10745 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10746 SizeType = Types[I];
10747 break;
10748 }
Mike Stump11289f42009-09-09 15:08:12 +000010749
Eli Friedman9562f392012-01-25 23:20:27 +000010750 // Note that we can return a VariableArrayType here in the case where
10751 // the element type was a dependent VariableArrayType.
10752 IntegerLiteral *ArraySize
10753 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10754 /*FIXME*/BracketsRange.getBegin());
10755 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010756 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010757 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010758}
Mike Stump11289f42009-09-09 15:08:12 +000010759
Douglas Gregord6ff3322009-08-04 16:50:30 +000010760template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010761QualType
10762TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010763 ArrayType::ArraySizeModifier SizeMod,
10764 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010765 unsigned IndexTypeQuals,
10766 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010767 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010768 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010769}
10770
10771template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010772QualType
Mike Stump11289f42009-09-09 15:08:12 +000010773TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010774 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010775 unsigned IndexTypeQuals,
10776 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010777 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010778 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010779}
Mike Stump11289f42009-09-09 15:08:12 +000010780
Douglas Gregord6ff3322009-08-04 16:50:30 +000010781template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010782QualType
10783TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010784 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010785 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010786 unsigned IndexTypeQuals,
10787 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010788 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010789 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010790 IndexTypeQuals, BracketsRange);
10791}
10792
10793template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010794QualType
10795TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010796 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010797 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010798 unsigned IndexTypeQuals,
10799 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010800 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010801 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010802 IndexTypeQuals, BracketsRange);
10803}
10804
10805template<typename Derived>
10806QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010807 unsigned NumElements,
10808 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010809 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010810 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010811}
Mike Stump11289f42009-09-09 15:08:12 +000010812
Douglas Gregord6ff3322009-08-04 16:50:30 +000010813template<typename Derived>
10814QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10815 unsigned NumElements,
10816 SourceLocation AttributeLoc) {
10817 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10818 NumElements, true);
10819 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010820 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10821 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010822 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010823}
Mike Stump11289f42009-09-09 15:08:12 +000010824
Douglas Gregord6ff3322009-08-04 16:50:30 +000010825template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010826QualType
10827TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010828 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010829 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010830 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010831}
Mike Stump11289f42009-09-09 15:08:12 +000010832
Douglas Gregord6ff3322009-08-04 16:50:30 +000010833template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010834QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10835 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010836 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010837 const FunctionProtoType::ExtProtoInfo &EPI) {
10838 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010839 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010840 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010841 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010842}
Mike Stump11289f42009-09-09 15:08:12 +000010843
Douglas Gregord6ff3322009-08-04 16:50:30 +000010844template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010845QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10846 return SemaRef.Context.getFunctionNoProtoType(T);
10847}
10848
10849template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010850QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10851 assert(D && "no decl found");
10852 if (D->isInvalidDecl()) return QualType();
10853
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010854 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010855 TypeDecl *Ty;
10856 if (isa<UsingDecl>(D)) {
10857 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010858 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010859 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10860
10861 // A valid resolved using typename decl points to exactly one type decl.
10862 assert(++Using->shadow_begin() == Using->shadow_end());
10863 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010864
John McCallb96ec562009-12-04 22:46:56 +000010865 } else {
10866 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10867 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10868 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10869 }
10870
10871 return SemaRef.Context.getTypeDeclType(Ty);
10872}
10873
10874template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010875QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10876 SourceLocation Loc) {
10877 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010878}
10879
10880template<typename Derived>
10881QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10882 return SemaRef.Context.getTypeOfType(Underlying);
10883}
10884
10885template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010886QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10887 SourceLocation Loc) {
10888 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010889}
10890
10891template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010892QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10893 UnaryTransformType::UTTKind UKind,
10894 SourceLocation Loc) {
10895 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10896}
10897
10898template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010899QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010900 TemplateName Template,
10901 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010902 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010903 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010904}
Mike Stump11289f42009-09-09 15:08:12 +000010905
Douglas Gregor1135c352009-08-06 05:28:30 +000010906template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010907QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10908 SourceLocation KWLoc) {
10909 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10910}
10911
10912template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010913TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010914TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010915 bool TemplateKW,
10916 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010917 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010918 Template);
10919}
10920
10921template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010922TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010923TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10924 const IdentifierInfo &Name,
10925 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010926 QualType ObjectType,
10927 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010928 UnqualifiedId TemplateName;
10929 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010930 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010931 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010932 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010933 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010934 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010935 /*EnteringContext=*/false,
10936 Template);
John McCall31f82722010-11-12 08:19:04 +000010937 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010938}
Mike Stump11289f42009-09-09 15:08:12 +000010939
Douglas Gregora16548e2009-08-11 05:31:07 +000010940template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010941TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010942TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010943 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010944 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010945 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010946 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010947 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010948 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010949 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010950 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010951 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010952 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010953 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010954 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010955 /*EnteringContext=*/false,
10956 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010957 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010958}
Chad Rosier1dcde962012-08-08 18:46:20 +000010959
Douglas Gregor71395fa2009-11-04 00:56:37 +000010960template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010961ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010962TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10963 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010964 Expr *OrigCallee,
10965 Expr *First,
10966 Expr *Second) {
10967 Expr *Callee = OrigCallee->IgnoreParenCasts();
10968 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010969
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010970 if (First->getObjectKind() == OK_ObjCProperty) {
10971 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10972 if (BinaryOperator::isAssignmentOp(Opc))
10973 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10974 First, Second);
10975 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10976 if (Result.isInvalid())
10977 return ExprError();
10978 First = Result.get();
10979 }
10980
10981 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10982 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10983 if (Result.isInvalid())
10984 return ExprError();
10985 Second = Result.get();
10986 }
10987
Douglas Gregora16548e2009-08-11 05:31:07 +000010988 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010989 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010990 if (!First->getType()->isOverloadableType() &&
10991 !Second->getType()->isOverloadableType())
10992 return getSema().CreateBuiltinArraySubscriptExpr(First,
10993 Callee->getLocStart(),
10994 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010995 } else if (Op == OO_Arrow) {
10996 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010997 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10998 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010999 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011000 // The argument is not of overloadable type, so try to create a
11001 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011002 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011003 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011004
John McCallb268a282010-08-23 23:25:46 +000011005 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011006 }
11007 } else {
John McCallb268a282010-08-23 23:25:46 +000011008 if (!First->getType()->isOverloadableType() &&
11009 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011010 // Neither of the arguments is an overloadable type, so try to
11011 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011012 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011013 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011014 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011015 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011016 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011017
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011018 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011019 }
11020 }
Mike Stump11289f42009-09-09 15:08:12 +000011021
11022 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011023 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011024 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011025
John McCallb268a282010-08-23 23:25:46 +000011026 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011027 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011028 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011029 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011030 // If we've resolved this to a particular non-member function, just call
11031 // that function. If we resolved it to a member function,
11032 // CreateOverloaded* will find that function for us.
11033 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11034 if (!isa<CXXMethodDecl>(ND))
11035 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011036 }
Mike Stump11289f42009-09-09 15:08:12 +000011037
Douglas Gregora16548e2009-08-11 05:31:07 +000011038 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011039 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011040 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011041
Douglas Gregora16548e2009-08-11 05:31:07 +000011042 // Create the overloaded operator invocation for unary operators.
11043 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011044 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011045 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011046 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011047 }
Mike Stump11289f42009-09-09 15:08:12 +000011048
Douglas Gregore9d62932011-07-15 16:25:15 +000011049 if (Op == OO_Subscript) {
11050 SourceLocation LBrace;
11051 SourceLocation RBrace;
11052
11053 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011054 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011055 LBrace = SourceLocation::getFromRawEncoding(
11056 NameLoc.CXXOperatorName.BeginOpNameLoc);
11057 RBrace = SourceLocation::getFromRawEncoding(
11058 NameLoc.CXXOperatorName.EndOpNameLoc);
11059 } else {
11060 LBrace = Callee->getLocStart();
11061 RBrace = OpLoc;
11062 }
11063
11064 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11065 First, Second);
11066 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011067
Douglas Gregora16548e2009-08-11 05:31:07 +000011068 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011069 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011070 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011071 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11072 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011073 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011074
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011075 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011076}
Mike Stump11289f42009-09-09 15:08:12 +000011077
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011078template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011079ExprResult
John McCallb268a282010-08-23 23:25:46 +000011080TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011081 SourceLocation OperatorLoc,
11082 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011083 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011084 TypeSourceInfo *ScopeType,
11085 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011086 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011087 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011088 QualType BaseType = Base->getType();
11089 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011090 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011091 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011092 !BaseType->getAs<PointerType>()->getPointeeType()
11093 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011094 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011095 return SemaRef.BuildPseudoDestructorExpr(
11096 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11097 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011098 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011099
Douglas Gregor678f90d2010-02-25 01:56:36 +000011100 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011101 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11102 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11103 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11104 NameInfo.setNamedTypeInfo(DestroyedType);
11105
Richard Smith8e4a3862012-05-15 06:15:11 +000011106 // The scope type is now known to be a valid nested name specifier
11107 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011108 if (ScopeType) {
11109 if (!ScopeType->getType()->getAs<TagType>()) {
11110 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11111 diag::err_expected_class_or_namespace)
11112 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11113 return ExprError();
11114 }
11115 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11116 CCLoc);
11117 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011118
Abramo Bagnara7945c982012-01-27 09:46:47 +000011119 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011120 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011121 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011122 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011123 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011124 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000011125 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011126}
11127
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011128template<typename Derived>
11129StmtResult
11130TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011131 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011132 CapturedDecl *CD = S->getCapturedDecl();
11133 unsigned NumParams = CD->getNumParams();
11134 unsigned ContextParamPos = CD->getContextParamPosition();
11135 SmallVector<Sema::CapturedParamNameType, 4> Params;
11136 for (unsigned I = 0; I < NumParams; ++I) {
11137 if (I != ContextParamPos) {
11138 Params.push_back(
11139 std::make_pair(
11140 CD->getParam(I)->getName(),
11141 getDerived().TransformType(CD->getParam(I)->getType())));
11142 } else {
11143 Params.push_back(std::make_pair(StringRef(), QualType()));
11144 }
11145 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011146 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011147 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011148 StmtResult Body;
11149 {
11150 Sema::CompoundScopeRAII CompoundScope(getSema());
11151 Body = getDerived().TransformStmt(S->getCapturedStmt());
11152 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011153
11154 if (Body.isInvalid()) {
11155 getSema().ActOnCapturedRegionError();
11156 return StmtError();
11157 }
11158
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011159 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011160}
11161
Douglas Gregord6ff3322009-08-04 16:50:30 +000011162} // end namespace clang
11163
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000011164#endif