blob: 878300ebc9f81208f1ad15ff8153bdd95bf34ba0 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000016
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000101
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000106
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000114
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000119
Mike Stump11289f42009-09-09 15:08:12 +0000120public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000123
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 }
131
John McCalldadc5752010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000134
Douglas Gregord6ff3322009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000144 ///
145 /// We must always rebuild all AST nodes when performing variadic template
146 /// pack expansion, in order to avoid violating the AST invariant that each
147 /// statement node appears at most once in its containing declaration.
148 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregord6ff3322009-08-04 16:50:30 +0000150 /// \brief Returns the location of the entity being transformed, if that
151 /// information was not available elsewhere in the AST.
152 ///
Mike Stump11289f42009-09-09 15:08:12 +0000153 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000154 /// provide an alternative implementation that provides better location
155 /// information.
156 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregord6ff3322009-08-04 16:50:30 +0000158 /// \brief Returns the name of the entity being transformed, if that
159 /// information was not available elsewhere in the AST.
160 ///
161 /// By default, returns an empty name. Subclasses can provide an alternative
162 /// implementation with a more precise name.
163 DeclarationName getBaseEntity() { return DeclarationName(); }
164
Douglas Gregora16548e2009-08-11 05:31:07 +0000165 /// \brief Sets the "base" location and entity when that
166 /// information is known based on another transformation.
167 ///
168 /// By default, the source location and entity are ignored. Subclasses can
169 /// override this function to provide a customized implementation.
170 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000171
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 /// \brief RAII object that temporarily sets the base location and entity
173 /// used for reporting diagnostics in types.
174 class TemporaryBase {
175 TreeTransform &Self;
176 SourceLocation OldLocation;
177 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 public:
180 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000181 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000182 OldLocation = Self.getDerived().getBaseLocation();
183 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000184
Douglas Gregora518d5b2011-01-25 17:51:48 +0000185 if (Location.isValid())
186 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000187 }
Mike Stump11289f42009-09-09 15:08:12 +0000188
Douglas Gregora16548e2009-08-11 05:31:07 +0000189 ~TemporaryBase() {
190 Self.getDerived().setBase(OldLocation, OldEntity);
191 }
192 };
Mike Stump11289f42009-09-09 15:08:12 +0000193
194 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000195 /// transformed.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000198 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000199 /// not change. For example, template instantiation need not traverse
200 /// non-dependent types.
201 bool AlreadyTransformed(QualType T) {
202 return T.isNull();
203 }
204
Douglas Gregord196a582009-12-14 19:27:10 +0000205 /// \brief Determine whether the given call argument should be dropped, e.g.,
206 /// because it is a default argument.
207 ///
208 /// Subclasses can provide an alternative implementation of this routine to
209 /// determine which kinds of call arguments get dropped. By default,
210 /// CXXDefaultArgument nodes are dropped (prior to transformation).
211 bool DropCallArgument(Expr *E) {
212 return E->isDefaultArgument();
213 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000214
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000215 /// \brief Determine whether we should expand a pack expansion with the
216 /// given set of parameter packs into separate arguments by repeatedly
217 /// transforming the pattern.
218 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000219 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000220 /// Subclasses can override this routine to provide different behavior.
221 ///
222 /// \param EllipsisLoc The location of the ellipsis that identifies the
223 /// pack expansion.
224 ///
225 /// \param PatternRange The source range that covers the entire pattern of
226 /// the pack expansion.
227 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000228 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000229 /// pattern.
230 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// \param ShouldExpand Will be set to \c true if the transformer should
232 /// expand the corresponding pack expansions into separate arguments. When
233 /// set, \c NumExpansions must also be set.
234 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000235 /// \param RetainExpansion Whether the caller should add an unexpanded
236 /// pack expansion after all of the expanded arguments. This is used
237 /// when extending explicitly-specified template argument packs per
238 /// C++0x [temp.arg.explicit]p9.
239 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000241 /// the expanded form of the corresponding pack expansion. This is both an
242 /// input and an output parameter, which can be set by the caller if the
243 /// number of expansions is known a priori (e.g., due to a prior substitution)
244 /// and will be set by the callee when the number of expansions is known.
245 /// The callee must set this value when \c ShouldExpand is \c true; it may
246 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000247 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000248 /// \returns true if an error occurred (e.g., because the parameter packs
249 /// are to be instantiated with arguments of different lengths), false
250 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 /// must be set.
252 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
253 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000254 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000255 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000257 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000258 ShouldExpand = false;
259 return false;
260 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000261
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000262 /// \brief "Forget" about the partially-substituted pack template argument,
263 /// when performing an instantiation that must preserve the parameter pack
264 /// use.
265 ///
266 /// This routine is meant to be overridden by the template instantiator.
267 TemplateArgument ForgetPartiallySubstitutedPack() {
268 return TemplateArgument();
269 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000270
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000271 /// \brief "Remember" the partially-substituted pack template argument
272 /// after performing an instantiation that must preserve the parameter pack
273 /// use.
274 ///
275 /// This routine is meant to be overridden by the template instantiator.
276 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000277
Douglas Gregorf3010112011-01-07 16:43:16 +0000278 /// \brief Note to the derived class when a function parameter pack is
279 /// being expanded.
280 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transforms the given type into another type.
283 ///
John McCall550e0c22009-10-21 00:40:46 +0000284 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000285 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000286 /// function. This is expensive, but we don't mind, because
287 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000288 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
290 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000291 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000292
John McCall550e0c22009-10-21 00:40:46 +0000293 /// \brief Transforms the given type-with-location into a new
294 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000295 ///
John McCall550e0c22009-10-21 00:40:46 +0000296 /// By default, this routine transforms a type by delegating to the
297 /// appropriate TransformXXXType to build a new type. Subclasses
298 /// may override this function (to take over all type
299 /// transformations) or some set of the TransformXXXType functions
300 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000301 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000302
303 /// \brief Transform the given type-with-location into a new
304 /// type, collecting location information in the given builder
305 /// as necessary.
306 ///
John McCall31f82722010-11-12 08:19:04 +0000307 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000308
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000309 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000310 ///
Mike Stump11289f42009-09-09 15:08:12 +0000311 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000312 /// appropriate TransformXXXStmt function to transform a specific kind of
313 /// statement or the TransformExpr() function to transform an expression.
314 /// Subclasses may override this function to transform statements using some
315 /// other mechanism.
316 ///
317 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000318 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000319
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000320 /// \brief Transform the given statement.
321 ///
322 /// By default, this routine transforms a statement by delegating to the
323 /// appropriate TransformOMPXXXClause function to transform a specific kind
324 /// of clause. Subclasses may override this function to transform statements
325 /// using some other mechanism.
326 ///
327 /// \returns the transformed OpenMP clause.
328 OMPClause *TransformOMPClause(OMPClause *S);
329
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000330 /// \brief Transform the given attribute.
331 ///
332 /// By default, this routine transforms a statement by delegating to the
333 /// appropriate TransformXXXAttr function to transform a specific kind
334 /// of attribute. Subclasses may override this function to transform
335 /// attributed statements using some other mechanism.
336 ///
337 /// \returns the transformed attribute
338 const Attr *TransformAttr(const Attr *S);
339
340/// \brief Transform the specified attribute.
341///
342/// Subclasses should override the transformation of attributes with a pragma
343/// spelling to transform expressions stored within the attribute.
344///
345/// \returns the transformed attribute.
346#define ATTR(X)
347#define PRAGMA_SPELLING_ATTR(X) \
348 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
349#include "clang/Basic/AttrList.inc"
350
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000351 /// \brief Transform the given expression.
352 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000353 /// By default, this routine transforms an expression by delegating to the
354 /// appropriate TransformXXXExpr function to build a new expression.
355 /// Subclasses may override this function to transform expressions using some
356 /// other mechanism.
357 ///
358 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000359 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000360
Richard Smithd59b8322012-12-19 01:39:02 +0000361 /// \brief Transform the given initializer.
362 ///
363 /// By default, this routine transforms an initializer by stripping off the
364 /// semantic nodes added by initialization, then passing the result to
365 /// TransformExpr or TransformExprs.
366 ///
367 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000368 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000369
Douglas Gregora3efea12011-01-03 19:04:46 +0000370 /// \brief Transform the given list of expressions.
371 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000372 /// This routine transforms a list of expressions by invoking
373 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000374 /// support for variadic templates by expanding any pack expansions (if the
375 /// derived class permits such expansion) along the way. When pack expansions
376 /// are present, the number of outputs may not equal the number of inputs.
377 ///
378 /// \param Inputs The set of expressions to be transformed.
379 ///
380 /// \param NumInputs The number of expressions in \c Inputs.
381 ///
382 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000383 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000384 /// be.
385 ///
386 /// \param Outputs The transformed input expressions will be added to this
387 /// vector.
388 ///
389 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
390 /// due to transformation.
391 ///
392 /// \returns true if an error occurred, false otherwise.
393 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000394 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000395 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000396
Douglas Gregord6ff3322009-08-04 16:50:30 +0000397 /// \brief Transform the given declaration, which is referenced from a type
398 /// or expression.
399 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000400 /// By default, acts as the identity function on declarations, unless the
401 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000402 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000403 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000404 llvm::DenseMap<Decl *, Decl *>::iterator Known
405 = TransformedLocalDecls.find(D);
406 if (Known != TransformedLocalDecls.end())
407 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
409 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000410 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000411
Chad Rosier1dcde962012-08-08 18:46:20 +0000412 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000413 /// place them on the new declaration.
414 ///
415 /// By default, this operation does nothing. Subclasses may override this
416 /// behavior to transform attributes.
417 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000418
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000419 /// \brief Note that a local declaration has been transformed by this
420 /// transformer.
421 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000422 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000423 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
424 /// the transformer itself has to transform the declarations. This routine
425 /// can be overridden by a subclass that keeps track of such mappings.
426 void transformedLocalDecl(Decl *Old, Decl *New) {
427 TransformedLocalDecls[Old] = New;
428 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000429
Douglas Gregorebe10102009-08-20 07:17:43 +0000430 /// \brief Transform the definition of the given declaration.
431 ///
Mike Stump11289f42009-09-09 15:08:12 +0000432 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000433 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000434 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
435 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000436 }
Mike Stump11289f42009-09-09 15:08:12 +0000437
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000438 /// \brief Transform the given declaration, which was the first part of a
439 /// nested-name-specifier in a member access expression.
440 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000441 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000442 /// identifier in a nested-name-specifier of a member access expression, e.g.,
443 /// the \c T in \c x->T::member
444 ///
445 /// By default, invokes TransformDecl() to transform the declaration.
446 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000447 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
448 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000449 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000450
Douglas Gregor14454802011-02-25 02:25:35 +0000451 /// \brief Transform the given nested-name-specifier with source-location
452 /// information.
453 ///
454 /// By default, transforms all of the types and declarations within the
455 /// nested-name-specifier. Subclasses may override this function to provide
456 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000457 NestedNameSpecifierLoc
458 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
459 QualType ObjectType = QualType(),
460 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000461
Douglas Gregorf816bd72009-09-03 22:13:48 +0000462 /// \brief Transform the given declaration name.
463 ///
464 /// By default, transforms the types of conversion function, constructor,
465 /// and destructor names and then (if needed) rebuilds the declaration name.
466 /// Identifiers and selectors are returned unmodified. Sublcasses may
467 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000468 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000469 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000470
Douglas Gregord6ff3322009-08-04 16:50:30 +0000471 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000472 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000473 /// \param SS The nested-name-specifier that qualifies the template
474 /// name. This nested-name-specifier must already have been transformed.
475 ///
476 /// \param Name The template name to transform.
477 ///
478 /// \param NameLoc The source location of the template name.
479 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000480 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000481 /// access expression, this is the type of the object whose member template
482 /// is being referenced.
483 ///
484 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
485 /// also refers to a name within the current (lexical) scope, this is the
486 /// declaration it refers to.
487 ///
488 /// By default, transforms the template name by transforming the declarations
489 /// and nested-name-specifiers that occur within the template name.
490 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000491 TemplateName
492 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
493 SourceLocation NameLoc,
494 QualType ObjectType = QualType(),
495 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000496
Douglas Gregord6ff3322009-08-04 16:50:30 +0000497 /// \brief Transform the given template argument.
498 ///
Mike Stump11289f42009-09-09 15:08:12 +0000499 /// By default, this operation transforms the type, expression, or
500 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000501 /// new template argument from the transformed result. Subclasses may
502 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000503 ///
504 /// Returns true if there was an error.
505 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
506 TemplateArgumentLoc &Output);
507
Douglas Gregor62e06f22010-12-20 17:31:10 +0000508 /// \brief Transform the given set of template arguments.
509 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000510 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000511 /// in the input set using \c TransformTemplateArgument(), and appends
512 /// the transformed arguments to the output list.
513 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000514 /// Note that this overload of \c TransformTemplateArguments() is merely
515 /// a convenience function. Subclasses that wish to override this behavior
516 /// should override the iterator-based member template version.
517 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000518 /// \param Inputs The set of template arguments to be transformed.
519 ///
520 /// \param NumInputs The number of template arguments in \p Inputs.
521 ///
522 /// \param Outputs The set of transformed template arguments output by this
523 /// routine.
524 ///
525 /// Returns true if an error occurred.
526 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
527 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000528 TemplateArgumentListInfo &Outputs) {
529 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
530 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000531
532 /// \brief Transform the given set of template arguments.
533 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000534 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000535 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000536 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000537 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000538 /// \param First An iterator to the first template argument.
539 ///
540 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000541 ///
542 /// \param Outputs The set of transformed template arguments output by this
543 /// routine.
544 ///
545 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000546 template<typename InputIterator>
547 bool TransformTemplateArguments(InputIterator First,
548 InputIterator Last,
549 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000550
John McCall0ad16662009-10-29 08:12:44 +0000551 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
552 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
553 TemplateArgumentLoc &ArgLoc);
554
John McCallbcd03502009-12-07 02:54:59 +0000555 /// \brief Fakes up a TypeSourceInfo for a type.
556 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
557 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000558 getDerived().getBaseLocation());
559 }
Mike Stump11289f42009-09-09 15:08:12 +0000560
John McCall550e0c22009-10-21 00:40:46 +0000561#define ABSTRACT_TYPELOC(CLASS, PARENT)
562#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000563 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000564#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000565
Richard Smith2e321552014-11-12 02:00:47 +0000566 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000567 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
568 FunctionProtoTypeLoc TL,
569 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000570 unsigned ThisTypeQuals,
571 Fn TransformExceptionSpec);
572
573 bool TransformExceptionSpec(SourceLocation Loc,
574 FunctionProtoType::ExceptionSpecInfo &ESI,
575 SmallVectorImpl<QualType> &Exceptions,
576 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000577
David Majnemerfad8f482013-10-15 09:33:02 +0000578 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000579
Chad Rosier1dcde962012-08-08 18:46:20 +0000580 QualType
John McCall31f82722010-11-12 08:19:04 +0000581 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
582 TemplateSpecializationTypeLoc TL,
583 TemplateName Template);
584
Chad Rosier1dcde962012-08-08 18:46:20 +0000585 QualType
John McCall31f82722010-11-12 08:19:04 +0000586 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
587 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000588 TemplateName Template,
589 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000590
Nico Weberc153d242014-07-28 00:02:09 +0000591 QualType TransformDependentTemplateSpecializationType(
592 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
593 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000594
John McCall58f10c32010-03-11 09:03:00 +0000595 /// \brief Transforms the parameters of a function type into the
596 /// given vectors.
597 ///
598 /// The result vectors should be kept in sync; null entries in the
599 /// variables vector are acceptable.
600 ///
601 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000602 bool TransformFunctionTypeParams(SourceLocation Loc,
603 ParmVarDecl **Params, unsigned NumParams,
604 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000605 SmallVectorImpl<QualType> &PTypes,
606 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000607
608 /// \brief Transforms a single function-type parameter. Return null
609 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000610 ///
611 /// \param indexAdjustment - A number to add to the parameter's
612 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000613 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000614 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000615 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000616 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000617
John McCall31f82722010-11-12 08:19:04 +0000618 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000619
John McCalldadc5752010-08-24 06:29:42 +0000620 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
621 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000622
Faisal Vali2cba1332013-10-23 06:44:28 +0000623 TemplateParameterList *TransformTemplateParameterList(
624 TemplateParameterList *TPL) {
625 return TPL;
626 }
627
Richard Smithdb2630f2012-10-21 03:28:35 +0000628 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000629
Richard Smithdb2630f2012-10-21 03:28:35 +0000630 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000631 bool IsAddressOfOperand,
632 TypeSourceInfo **RecoveryTSI);
633
634 ExprResult TransformParenDependentScopeDeclRefExpr(
635 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
636 TypeSourceInfo **RecoveryTSI);
637
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000638 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000639
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000640// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
641// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000642#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000643 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000644 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000645#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000646 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000647 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000648#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000649#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000650
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000651#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000652 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000653 OMPClause *Transform ## Class(Class *S);
654#include "clang/Basic/OpenMPKinds.def"
655
Douglas Gregord6ff3322009-08-04 16:50:30 +0000656 /// \brief Build a new pointer type given its pointee type.
657 ///
658 /// By default, performs semantic analysis when building the pointer type.
659 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000660 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661
662 /// \brief Build a new block pointer type given its pointee type.
663 ///
Mike Stump11289f42009-09-09 15:08:12 +0000664 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000665 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000666 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667
John McCall70dd5f62009-10-30 00:06:24 +0000668 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000669 ///
John McCall70dd5f62009-10-30 00:06:24 +0000670 /// By default, performs semantic analysis when building the
671 /// reference type. Subclasses may override this routine to provide
672 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000673 ///
John McCall70dd5f62009-10-30 00:06:24 +0000674 /// \param LValue whether the type was written with an lvalue sigil
675 /// or an rvalue sigil.
676 QualType RebuildReferenceType(QualType ReferentType,
677 bool LValue,
678 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000679
Douglas Gregord6ff3322009-08-04 16:50:30 +0000680 /// \brief Build a new member pointer type given the pointee type and the
681 /// class type it refers into.
682 ///
683 /// By default, performs semantic analysis when building the member pointer
684 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000685 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
686 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000687
Douglas Gregord6ff3322009-08-04 16:50:30 +0000688 /// \brief Build a new array type given the element type, size
689 /// modifier, size of the array (if known), size expression, and index type
690 /// qualifiers.
691 ///
692 /// By default, performs semantic analysis when building the array type.
693 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000694 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 QualType RebuildArrayType(QualType ElementType,
696 ArrayType::ArraySizeModifier SizeMod,
697 const llvm::APInt *Size,
698 Expr *SizeExpr,
699 unsigned IndexTypeQuals,
700 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000701
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702 /// \brief Build a new constant array type given the element type, size
703 /// modifier, (known) size of the array, and index type qualifiers.
704 ///
705 /// By default, performs semantic analysis when building the array type.
706 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000707 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000708 ArrayType::ArraySizeModifier SizeMod,
709 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000710 unsigned IndexTypeQuals,
711 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000712
Douglas Gregord6ff3322009-08-04 16:50:30 +0000713 /// \brief Build a new incomplete array type given the element type, size
714 /// modifier, and index type qualifiers.
715 ///
716 /// By default, performs semantic analysis when building the array type.
717 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000718 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000719 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000720 unsigned IndexTypeQuals,
721 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000722
Mike Stump11289f42009-09-09 15:08:12 +0000723 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724 /// size modifier, size expression, and index type qualifiers.
725 ///
726 /// By default, performs semantic analysis when building the array type.
727 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000728 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000729 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000730 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000731 unsigned IndexTypeQuals,
732 SourceRange BracketsRange);
733
Mike Stump11289f42009-09-09 15:08:12 +0000734 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000735 /// size modifier, size expression, and index type qualifiers.
736 ///
737 /// By default, performs semantic analysis when building the array type.
738 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000739 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000741 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000742 unsigned IndexTypeQuals,
743 SourceRange BracketsRange);
744
745 /// \brief Build a new vector type given the element type and
746 /// number of elements.
747 ///
748 /// By default, performs semantic analysis when building the vector type.
749 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000750 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000751 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000752
Douglas Gregord6ff3322009-08-04 16:50:30 +0000753 /// \brief Build a new extended vector type given the element type and
754 /// number of elements.
755 ///
756 /// By default, performs semantic analysis when building the vector type.
757 /// Subclasses may override this routine to provide different behavior.
758 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
759 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000760
761 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000762 /// given the element type and number of elements.
763 ///
764 /// By default, performs semantic analysis when building the vector type.
765 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000766 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000767 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000768 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000769
Douglas Gregord6ff3322009-08-04 16:50:30 +0000770 /// \brief Build a new function type.
771 ///
772 /// By default, performs semantic analysis when building the function type.
773 /// Subclasses may override this routine to provide different behavior.
774 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000775 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000776 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000777
John McCall550e0c22009-10-21 00:40:46 +0000778 /// \brief Build a new unprototyped function type.
779 QualType RebuildFunctionNoProtoType(QualType ResultType);
780
John McCallb96ec562009-12-04 22:46:56 +0000781 /// \brief Rebuild an unresolved typename type, given the decl that
782 /// the UnresolvedUsingTypenameDecl was transformed to.
783 QualType RebuildUnresolvedUsingType(Decl *D);
784
Douglas Gregord6ff3322009-08-04 16:50:30 +0000785 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000786 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000787 return SemaRef.Context.getTypeDeclType(Typedef);
788 }
789
790 /// \brief Build a new class/struct/union type.
791 QualType RebuildRecordType(RecordDecl *Record) {
792 return SemaRef.Context.getTypeDeclType(Record);
793 }
794
795 /// \brief Build a new Enum type.
796 QualType RebuildEnumType(EnumDecl *Enum) {
797 return SemaRef.Context.getTypeDeclType(Enum);
798 }
John McCallfcc33b02009-09-05 00:15:47 +0000799
Mike Stump11289f42009-09-09 15:08:12 +0000800 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000801 ///
802 /// By default, performs semantic analysis when building the typeof type.
803 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000804 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000805
Mike Stump11289f42009-09-09 15:08:12 +0000806 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000807 ///
808 /// By default, builds a new TypeOfType with the given underlying type.
809 QualType RebuildTypeOfType(QualType Underlying);
810
Alexis Hunte852b102011-05-24 22:41:36 +0000811 /// \brief Build a new unary transform type.
812 QualType RebuildUnaryTransformType(QualType BaseType,
813 UnaryTransformType::UTTKind UKind,
814 SourceLocation Loc);
815
Richard Smith74aeef52013-04-26 16:15:35 +0000816 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000817 ///
818 /// By default, performs semantic analysis when building the decltype type.
819 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000820 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000821
Richard Smith74aeef52013-04-26 16:15:35 +0000822 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000823 ///
824 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000825 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000826 // Note, IsDependent is always false here: we implicitly convert an 'auto'
827 // which has been deduced to a dependent type into an undeduced 'auto', so
828 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000829 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
830 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000831 }
832
Douglas Gregord6ff3322009-08-04 16:50:30 +0000833 /// \brief Build a new template specialization type.
834 ///
835 /// By default, performs semantic analysis when building the template
836 /// specialization type. Subclasses may override this routine to provide
837 /// different behavior.
838 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000839 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000840 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000841
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000842 /// \brief Build a new parenthesized type.
843 ///
844 /// By default, builds a new ParenType type from the inner type.
845 /// Subclasses may override this routine to provide different behavior.
846 QualType RebuildParenType(QualType InnerType) {
847 return SemaRef.Context.getParenType(InnerType);
848 }
849
Douglas Gregord6ff3322009-08-04 16:50:30 +0000850 /// \brief Build a new qualified name type.
851 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000852 /// By default, builds a new ElaboratedType type from the keyword,
853 /// the nested-name-specifier and the named type.
854 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000855 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
856 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000857 NestedNameSpecifierLoc QualifierLoc,
858 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000859 return SemaRef.Context.getElaboratedType(Keyword,
860 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000861 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000862 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000863
864 /// \brief Build a new typename type that refers to a template-id.
865 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000866 /// By default, builds a new DependentNameType type from the
867 /// nested-name-specifier and the given type. Subclasses may override
868 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000869 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000870 ElaboratedTypeKeyword Keyword,
871 NestedNameSpecifierLoc QualifierLoc,
872 const IdentifierInfo *Name,
873 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000874 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000875 // Rebuild the template name.
876 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000877 CXXScopeSpec SS;
878 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000879 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000880 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
881 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000882
Douglas Gregora7a795b2011-03-01 20:11:18 +0000883 if (InstName.isNull())
884 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000885
Douglas Gregora7a795b2011-03-01 20:11:18 +0000886 // If it's still dependent, make a dependent specialization.
887 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000888 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
889 QualifierLoc.getNestedNameSpecifier(),
890 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000891 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000892
Douglas Gregora7a795b2011-03-01 20:11:18 +0000893 // Otherwise, make an elaborated type wrapping a non-dependent
894 // specialization.
895 QualType T =
896 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
897 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000898
Craig Topperc3ec1492014-05-26 06:22:03 +0000899 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000900 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000901
902 return SemaRef.Context.getElaboratedType(Keyword,
903 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000904 T);
905 }
906
Douglas Gregord6ff3322009-08-04 16:50:30 +0000907 /// \brief Build a new typename type that refers to an identifier.
908 ///
909 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000910 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000911 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000912 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000913 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000914 NestedNameSpecifierLoc QualifierLoc,
915 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000916 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000917 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000918 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000919
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000920 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000921 // If the name is still dependent, just build a new dependent name type.
922 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000923 return SemaRef.Context.getDependentNameType(Keyword,
924 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000925 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000926 }
927
Abramo Bagnara6150c882010-05-11 21:36:43 +0000928 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000929 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000930 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000931
932 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
933
Abramo Bagnarad7548482010-05-19 21:37:53 +0000934 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000935 // into a non-dependent elaborated-type-specifier. Find the tag we're
936 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000937 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000938 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
939 if (!DC)
940 return QualType();
941
John McCallbf8c5192010-05-27 06:40:31 +0000942 if (SemaRef.RequireCompleteDeclContext(SS, DC))
943 return QualType();
944
Craig Topperc3ec1492014-05-26 06:22:03 +0000945 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000946 SemaRef.LookupQualifiedName(Result, DC);
947 switch (Result.getResultKind()) {
948 case LookupResult::NotFound:
949 case LookupResult::NotFoundInCurrentInstantiation:
950 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000951
Douglas Gregore677daf2010-03-31 22:19:08 +0000952 case LookupResult::Found:
953 Tag = Result.getAsSingle<TagDecl>();
954 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000955
Douglas Gregore677daf2010-03-31 22:19:08 +0000956 case LookupResult::FoundOverloaded:
957 case LookupResult::FoundUnresolvedValue:
958 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000959
Douglas Gregore677daf2010-03-31 22:19:08 +0000960 case LookupResult::Ambiguous:
961 // Let the LookupResult structure handle ambiguities.
962 return QualType();
963 }
964
965 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000966 // Check where the name exists but isn't a tag type and use that to emit
967 // better diagnostics.
968 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
969 SemaRef.LookupQualifiedName(Result, DC);
970 switch (Result.getResultKind()) {
971 case LookupResult::Found:
972 case LookupResult::FoundOverloaded:
973 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000974 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000975 unsigned Kind = 0;
976 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000977 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
978 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000979 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
980 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
981 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000982 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000983 default:
Nick Lewycky0c438082011-01-24 19:01:04 +0000984 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000985 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000986 break;
987 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000988 return QualType();
989 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000990
Richard Trieucaa33d32011-06-10 03:11:26 +0000991 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
992 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000993 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000994 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
995 return QualType();
996 }
997
998 // Build the elaborated-type-specifier type.
999 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001000 return SemaRef.Context.getElaboratedType(Keyword,
1001 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001002 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001003 }
Mike Stump11289f42009-09-09 15:08:12 +00001004
Douglas Gregor822d0302011-01-12 17:07:58 +00001005 /// \brief Build a new pack expansion type.
1006 ///
1007 /// By default, builds a new PackExpansionType type from the given pattern.
1008 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001009 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001010 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001011 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001012 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001013 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1014 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001015 }
1016
Eli Friedman0dfb8892011-10-06 23:00:33 +00001017 /// \brief Build a new atomic type given its value type.
1018 ///
1019 /// By default, performs semantic analysis when building the atomic type.
1020 /// Subclasses may override this routine to provide different behavior.
1021 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1022
Douglas Gregor71dc5092009-08-06 06:41:21 +00001023 /// \brief Build a new template name given a nested name specifier, a flag
1024 /// indicating whether the "template" keyword was provided, and the template
1025 /// that the template name refers to.
1026 ///
1027 /// By default, builds the new template name directly. Subclasses may override
1028 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001029 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001030 bool TemplateKW,
1031 TemplateDecl *Template);
1032
Douglas Gregor71dc5092009-08-06 06:41:21 +00001033 /// \brief Build a new template name given a nested name specifier and the
1034 /// name that is referred to as a template.
1035 ///
1036 /// By default, performs semantic analysis to determine whether the name can
1037 /// be resolved to a specific template, then builds the appropriate kind of
1038 /// template name. Subclasses may override this routine to provide different
1039 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001040 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1041 const IdentifierInfo &Name,
1042 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001043 QualType ObjectType,
1044 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001045
Douglas Gregor71395fa2009-11-04 00:56:37 +00001046 /// \brief Build a new template name given a nested name specifier and the
1047 /// overloaded operator name that is referred to as a template.
1048 ///
1049 /// By default, performs semantic analysis to determine whether the name can
1050 /// be resolved to a specific template, then builds the appropriate kind of
1051 /// template name. Subclasses may override this routine to provide different
1052 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001053 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001054 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001055 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001056 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001057
1058 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001059 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001060 ///
1061 /// By default, performs semantic analysis to determine whether the name can
1062 /// be resolved to a specific template, then builds the appropriate kind of
1063 /// template name. Subclasses may override this routine to provide different
1064 /// behavior.
1065 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1066 const TemplateArgument &ArgPack) {
1067 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1068 }
1069
Douglas Gregorebe10102009-08-20 07:17:43 +00001070 /// \brief Build a new compound statement.
1071 ///
1072 /// By default, performs semantic analysis to build the new statement.
1073 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001074 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001075 MultiStmtArg Statements,
1076 SourceLocation RBraceLoc,
1077 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001078 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001079 IsStmtExpr);
1080 }
1081
1082 /// \brief Build a new case statement.
1083 ///
1084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001086 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001087 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001088 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001089 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001090 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001091 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001092 ColonLoc);
1093 }
Mike Stump11289f42009-09-09 15:08:12 +00001094
Douglas Gregorebe10102009-08-20 07:17:43 +00001095 /// \brief Attach the body to a new case statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001099 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001100 getSema().ActOnCaseStmtBody(S, Body);
1101 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001102 }
Mike Stump11289f42009-09-09 15:08:12 +00001103
Douglas Gregorebe10102009-08-20 07:17:43 +00001104 /// \brief Build a new default statement.
1105 ///
1106 /// By default, performs semantic analysis to build the new statement.
1107 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001108 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001109 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001110 Stmt *SubStmt) {
1111 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001112 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 }
Mike Stump11289f42009-09-09 15:08:12 +00001114
Douglas Gregorebe10102009-08-20 07:17:43 +00001115 /// \brief Build a new label statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001119 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1120 SourceLocation ColonLoc, Stmt *SubStmt) {
1121 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001122 }
Mike Stump11289f42009-09-09 15:08:12 +00001123
Richard Smithc202b282012-04-14 00:33:13 +00001124 /// \brief Build a new label statement.
1125 ///
1126 /// By default, performs semantic analysis to build the new statement.
1127 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001128 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1129 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001130 Stmt *SubStmt) {
1131 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1132 }
1133
Douglas Gregorebe10102009-08-20 07:17:43 +00001134 /// \brief Build a new "if" statement.
1135 ///
1136 /// By default, performs semantic analysis to build the new statement.
1137 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001138 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001139 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001140 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001141 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001142 }
Mike Stump11289f42009-09-09 15:08:12 +00001143
Douglas Gregorebe10102009-08-20 07:17:43 +00001144 /// \brief Start building a new switch statement.
1145 ///
1146 /// By default, performs semantic analysis to build the new statement.
1147 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001148 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001149 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001150 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001151 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001152 }
Mike Stump11289f42009-09-09 15:08:12 +00001153
Douglas Gregorebe10102009-08-20 07:17:43 +00001154 /// \brief Attach the body to the switch statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001158 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001159 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001160 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001161 }
1162
1163 /// \brief Build a new while statement.
1164 ///
1165 /// By default, performs semantic analysis to build the new statement.
1166 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001167 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1168 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001169 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001170 }
Mike Stump11289f42009-09-09 15:08:12 +00001171
Douglas Gregorebe10102009-08-20 07:17:43 +00001172 /// \brief Build a new do-while statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001176 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001177 SourceLocation WhileLoc, SourceLocation LParenLoc,
1178 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001179 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1180 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001181 }
1182
1183 /// \brief Build a new for statement.
1184 ///
1185 /// By default, performs semantic analysis to build the new statement.
1186 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001187 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001188 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001189 VarDecl *CondVar, Sema::FullExprArg Inc,
1190 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001191 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001192 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001193 }
Mike Stump11289f42009-09-09 15:08:12 +00001194
Douglas Gregorebe10102009-08-20 07:17:43 +00001195 /// \brief Build a new goto statement.
1196 ///
1197 /// By default, performs semantic analysis to build the new statement.
1198 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001199 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1200 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001201 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001202 }
1203
1204 /// \brief Build a new indirect goto statement.
1205 ///
1206 /// By default, performs semantic analysis to build the new statement.
1207 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001208 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001209 SourceLocation StarLoc,
1210 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001211 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001212 }
Mike Stump11289f42009-09-09 15:08:12 +00001213
Douglas Gregorebe10102009-08-20 07:17:43 +00001214 /// \brief Build a new return statement.
1215 ///
1216 /// By default, performs semantic analysis to build the new statement.
1217 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001218 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001219 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001220 }
Mike Stump11289f42009-09-09 15:08:12 +00001221
Douglas Gregorebe10102009-08-20 07:17:43 +00001222 /// \brief Build a new declaration statement.
1223 ///
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001226 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001227 SourceLocation StartLoc, SourceLocation EndLoc) {
1228 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001229 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001230 }
Mike Stump11289f42009-09-09 15:08:12 +00001231
Anders Carlssonaaeef072010-01-24 05:50:09 +00001232 /// \brief Build a new inline asm statement.
1233 ///
1234 /// By default, performs semantic analysis to build the new statement.
1235 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001236 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1237 bool IsVolatile, unsigned NumOutputs,
1238 unsigned NumInputs, IdentifierInfo **Names,
1239 MultiExprArg Constraints, MultiExprArg Exprs,
1240 Expr *AsmString, MultiExprArg Clobbers,
1241 SourceLocation RParenLoc) {
1242 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1243 NumInputs, Names, Constraints, Exprs,
1244 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001245 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001246
Chad Rosier32503022012-06-11 20:47:18 +00001247 /// \brief Build a new MS style inline asm statement.
1248 ///
1249 /// By default, performs semantic analysis to build the new statement.
1250 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001251 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001252 ArrayRef<Token> AsmToks,
1253 StringRef AsmString,
1254 unsigned NumOutputs, unsigned NumInputs,
1255 ArrayRef<StringRef> Constraints,
1256 ArrayRef<StringRef> Clobbers,
1257 ArrayRef<Expr*> Exprs,
1258 SourceLocation EndLoc) {
1259 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1260 NumOutputs, NumInputs,
1261 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001262 }
1263
James Dennett2a4d13c2012-06-15 07:13:21 +00001264 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001265 ///
1266 /// By default, performs semantic analysis to build the new statement.
1267 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001268 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001269 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001270 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001271 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001272 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001273 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001274 }
1275
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001276 /// \brief Rebuild an Objective-C exception declaration.
1277 ///
1278 /// By default, performs semantic analysis to build the new declaration.
1279 /// Subclasses may override this routine to provide different behavior.
1280 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1281 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001282 return getSema().BuildObjCExceptionDecl(TInfo, T,
1283 ExceptionDecl->getInnerLocStart(),
1284 ExceptionDecl->getLocation(),
1285 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001286 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001287
James Dennett2a4d13c2012-06-15 07:13:21 +00001288 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001289 ///
1290 /// By default, performs semantic analysis to build the new statement.
1291 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001292 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001293 SourceLocation RParenLoc,
1294 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001295 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001296 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001297 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001298 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001299
James Dennett2a4d13c2012-06-15 07:13:21 +00001300 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001301 ///
1302 /// By default, performs semantic analysis to build the new statement.
1303 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001304 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001305 Stmt *Body) {
1306 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001307 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001308
James Dennett2a4d13c2012-06-15 07:13:21 +00001309 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001310 ///
1311 /// By default, performs semantic analysis to build the new statement.
1312 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001313 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001314 Expr *Operand) {
1315 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001316 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001317
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001318 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001319 ///
1320 /// By default, performs semantic analysis to build the new statement.
1321 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001322 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001323 DeclarationNameInfo DirName,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001324 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001325 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001326 SourceLocation EndLoc) {
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001327 return getSema().ActOnOpenMPExecutableDirective(Kind, DirName, Clauses,
1328 AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001329 }
1330
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001331 /// \brief Build a new OpenMP 'if' clause.
1332 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001333 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001334 /// Subclasses may override this routine to provide different behavior.
1335 OMPClause *RebuildOMPIfClause(Expr *Condition,
1336 SourceLocation StartLoc,
1337 SourceLocation LParenLoc,
1338 SourceLocation EndLoc) {
1339 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1340 LParenLoc, EndLoc);
1341 }
1342
Alexey Bataev3778b602014-07-17 07:32:53 +00001343 /// \brief Build a new OpenMP 'final' clause.
1344 ///
1345 /// By default, performs semantic analysis to build the new OpenMP clause.
1346 /// Subclasses may override this routine to provide different behavior.
1347 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1348 SourceLocation LParenLoc,
1349 SourceLocation EndLoc) {
1350 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1351 EndLoc);
1352 }
1353
Alexey Bataev568a8332014-03-06 06:15:19 +00001354 /// \brief Build a new OpenMP 'num_threads' clause.
1355 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001356 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001357 /// Subclasses may override this routine to provide different behavior.
1358 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1359 SourceLocation StartLoc,
1360 SourceLocation LParenLoc,
1361 SourceLocation EndLoc) {
1362 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1363 LParenLoc, EndLoc);
1364 }
1365
Alexey Bataev62c87d22014-03-21 04:51:18 +00001366 /// \brief Build a new OpenMP 'safelen' clause.
1367 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001368 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001369 /// Subclasses may override this routine to provide different behavior.
1370 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1371 SourceLocation LParenLoc,
1372 SourceLocation EndLoc) {
1373 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1374 }
1375
Alexander Musman8bd31e62014-05-27 15:12:19 +00001376 /// \brief Build a new OpenMP 'collapse' clause.
1377 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001378 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001379 /// Subclasses may override this routine to provide different behavior.
1380 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1381 SourceLocation LParenLoc,
1382 SourceLocation EndLoc) {
1383 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1384 EndLoc);
1385 }
1386
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001387 /// \brief Build a new OpenMP 'default' clause.
1388 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001389 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001390 /// Subclasses may override this routine to provide different behavior.
1391 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1392 SourceLocation KindKwLoc,
1393 SourceLocation StartLoc,
1394 SourceLocation LParenLoc,
1395 SourceLocation EndLoc) {
1396 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1397 StartLoc, LParenLoc, EndLoc);
1398 }
1399
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001400 /// \brief Build a new OpenMP 'proc_bind' clause.
1401 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001402 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001403 /// Subclasses may override this routine to provide different behavior.
1404 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1405 SourceLocation KindKwLoc,
1406 SourceLocation StartLoc,
1407 SourceLocation LParenLoc,
1408 SourceLocation EndLoc) {
1409 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1410 StartLoc, LParenLoc, EndLoc);
1411 }
1412
Alexey Bataev56dafe82014-06-20 07:16:17 +00001413 /// \brief Build a new OpenMP 'schedule' clause.
1414 ///
1415 /// By default, performs semantic analysis to build the new OpenMP clause.
1416 /// Subclasses may override this routine to provide different behavior.
1417 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1418 Expr *ChunkSize,
1419 SourceLocation StartLoc,
1420 SourceLocation LParenLoc,
1421 SourceLocation KindLoc,
1422 SourceLocation CommaLoc,
1423 SourceLocation EndLoc) {
1424 return getSema().ActOnOpenMPScheduleClause(
1425 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1426 }
1427
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001428 /// \brief Build a new OpenMP 'private' clause.
1429 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001430 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001431 /// Subclasses may override this routine to provide different behavior.
1432 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1433 SourceLocation StartLoc,
1434 SourceLocation LParenLoc,
1435 SourceLocation EndLoc) {
1436 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1437 EndLoc);
1438 }
1439
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001440 /// \brief Build a new OpenMP 'firstprivate' clause.
1441 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001442 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001443 /// Subclasses may override this routine to provide different behavior.
1444 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1445 SourceLocation StartLoc,
1446 SourceLocation LParenLoc,
1447 SourceLocation EndLoc) {
1448 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1449 EndLoc);
1450 }
1451
Alexander Musman1bb328c2014-06-04 13:06:39 +00001452 /// \brief Build a new OpenMP 'lastprivate' clause.
1453 ///
1454 /// By default, performs semantic analysis to build the new OpenMP clause.
1455 /// Subclasses may override this routine to provide different behavior.
1456 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1457 SourceLocation StartLoc,
1458 SourceLocation LParenLoc,
1459 SourceLocation EndLoc) {
1460 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1461 EndLoc);
1462 }
1463
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001464 /// \brief Build a new OpenMP 'shared' clause.
1465 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001466 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001467 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001468 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1469 SourceLocation StartLoc,
1470 SourceLocation LParenLoc,
1471 SourceLocation EndLoc) {
1472 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1473 EndLoc);
1474 }
1475
Alexey Bataevc5e02582014-06-16 07:08:35 +00001476 /// \brief Build a new OpenMP 'reduction' clause.
1477 ///
1478 /// By default, performs semantic analysis to build the new statement.
1479 /// Subclasses may override this routine to provide different behavior.
1480 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1481 SourceLocation StartLoc,
1482 SourceLocation LParenLoc,
1483 SourceLocation ColonLoc,
1484 SourceLocation EndLoc,
1485 CXXScopeSpec &ReductionIdScopeSpec,
1486 const DeclarationNameInfo &ReductionId) {
1487 return getSema().ActOnOpenMPReductionClause(
1488 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1489 ReductionId);
1490 }
1491
Alexander Musman8dba6642014-04-22 13:09:42 +00001492 /// \brief Build a new OpenMP 'linear' clause.
1493 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001494 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001495 /// Subclasses may override this routine to provide different behavior.
1496 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1497 SourceLocation StartLoc,
1498 SourceLocation LParenLoc,
1499 SourceLocation ColonLoc,
1500 SourceLocation EndLoc) {
1501 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1502 ColonLoc, EndLoc);
1503 }
1504
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001505 /// \brief Build a new OpenMP 'aligned' clause.
1506 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001507 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001508 /// Subclasses may override this routine to provide different behavior.
1509 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1510 SourceLocation StartLoc,
1511 SourceLocation LParenLoc,
1512 SourceLocation ColonLoc,
1513 SourceLocation EndLoc) {
1514 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1515 LParenLoc, ColonLoc, EndLoc);
1516 }
1517
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001518 /// \brief Build a new OpenMP 'copyin' clause.
1519 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001520 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001521 /// Subclasses may override this routine to provide different behavior.
1522 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1523 SourceLocation StartLoc,
1524 SourceLocation LParenLoc,
1525 SourceLocation EndLoc) {
1526 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1527 EndLoc);
1528 }
1529
Alexey Bataevbae9a792014-06-27 10:37:06 +00001530 /// \brief Build a new OpenMP 'copyprivate' clause.
1531 ///
1532 /// By default, performs semantic analysis to build the new OpenMP clause.
1533 /// Subclasses may override this routine to provide different behavior.
1534 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1535 SourceLocation StartLoc,
1536 SourceLocation LParenLoc,
1537 SourceLocation EndLoc) {
1538 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1539 EndLoc);
1540 }
1541
Alexey Bataev6125da92014-07-21 11:26:11 +00001542 /// \brief Build a new OpenMP 'flush' pseudo clause.
1543 ///
1544 /// By default, performs semantic analysis to build the new OpenMP clause.
1545 /// Subclasses may override this routine to provide different behavior.
1546 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1547 SourceLocation StartLoc,
1548 SourceLocation LParenLoc,
1549 SourceLocation EndLoc) {
1550 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1551 EndLoc);
1552 }
1553
James Dennett2a4d13c2012-06-15 07:13:21 +00001554 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001555 ///
1556 /// By default, performs semantic analysis to build the new statement.
1557 /// Subclasses may override this routine to provide different behavior.
1558 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1559 Expr *object) {
1560 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1561 }
1562
James Dennett2a4d13c2012-06-15 07:13:21 +00001563 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001564 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001565 /// By default, performs semantic analysis to build the new statement.
1566 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001567 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001568 Expr *Object, Stmt *Body) {
1569 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001570 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001571
James Dennett2a4d13c2012-06-15 07:13:21 +00001572 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001573 ///
1574 /// By default, performs semantic analysis to build the new statement.
1575 /// Subclasses may override this routine to provide different behavior.
1576 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1577 Stmt *Body) {
1578 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1579 }
John McCall53848232011-07-27 01:07:15 +00001580
Douglas Gregorf68a5082010-04-22 23:10:45 +00001581 /// \brief Build a new Objective-C fast enumeration statement.
1582 ///
1583 /// By default, performs semantic analysis to build the new statement.
1584 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001585 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001586 Stmt *Element,
1587 Expr *Collection,
1588 SourceLocation RParenLoc,
1589 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001590 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001591 Element,
John McCallb268a282010-08-23 23:25:46 +00001592 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001593 RParenLoc);
1594 if (ForEachStmt.isInvalid())
1595 return StmtError();
1596
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001597 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001598 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001599
Douglas Gregorebe10102009-08-20 07:17:43 +00001600 /// \brief Build a new C++ exception declaration.
1601 ///
1602 /// By default, performs semantic analysis to build the new decaration.
1603 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001604 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001605 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001606 SourceLocation StartLoc,
1607 SourceLocation IdLoc,
1608 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001609 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001610 StartLoc, IdLoc, Id);
1611 if (Var)
1612 getSema().CurContext->addDecl(Var);
1613 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001614 }
1615
1616 /// \brief Build a new C++ catch statement.
1617 ///
1618 /// By default, performs semantic analysis to build the new statement.
1619 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001620 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001621 VarDecl *ExceptionDecl,
1622 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001623 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1624 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001625 }
Mike Stump11289f42009-09-09 15:08:12 +00001626
Douglas Gregorebe10102009-08-20 07:17:43 +00001627 /// \brief Build a new C++ try statement.
1628 ///
1629 /// By default, performs semantic analysis to build the new statement.
1630 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001631 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1632 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001633 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001634 }
Mike Stump11289f42009-09-09 15:08:12 +00001635
Richard Smith02e85f32011-04-14 22:09:26 +00001636 /// \brief Build a new C++0x range-based for statement.
1637 ///
1638 /// By default, performs semantic analysis to build the new statement.
1639 /// Subclasses may override this routine to provide different behavior.
1640 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1641 SourceLocation ColonLoc,
1642 Stmt *Range, Stmt *BeginEnd,
1643 Expr *Cond, Expr *Inc,
1644 Stmt *LoopVar,
1645 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001646 // If we've just learned that the range is actually an Objective-C
1647 // collection, treat this as an Objective-C fast enumeration loop.
1648 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1649 if (RangeStmt->isSingleDecl()) {
1650 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001651 if (RangeVar->isInvalidDecl())
1652 return StmtError();
1653
Douglas Gregorf7106af2013-04-08 18:40:13 +00001654 Expr *RangeExpr = RangeVar->getInit();
1655 if (!RangeExpr->isTypeDependent() &&
1656 RangeExpr->getType()->isObjCObjectPointerType())
1657 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1658 RParenLoc);
1659 }
1660 }
1661 }
1662
Richard Smith02e85f32011-04-14 22:09:26 +00001663 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001664 Cond, Inc, LoopVar, RParenLoc,
1665 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001666 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001667
1668 /// \brief Build a new C++0x range-based for statement.
1669 ///
1670 /// By default, performs semantic analysis to build the new statement.
1671 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001672 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001673 bool IsIfExists,
1674 NestedNameSpecifierLoc QualifierLoc,
1675 DeclarationNameInfo NameInfo,
1676 Stmt *Nested) {
1677 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1678 QualifierLoc, NameInfo, Nested);
1679 }
1680
Richard Smith02e85f32011-04-14 22:09:26 +00001681 /// \brief Attach body to a C++0x range-based for statement.
1682 ///
1683 /// By default, performs semantic analysis to finish the new statement.
1684 /// Subclasses may override this routine to provide different behavior.
1685 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1686 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1687 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001688
David Majnemerfad8f482013-10-15 09:33:02 +00001689 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001690 Stmt *TryBlock, Stmt *Handler) {
1691 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001692 }
1693
David Majnemerfad8f482013-10-15 09:33:02 +00001694 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001695 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001696 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001697 }
1698
David Majnemerfad8f482013-10-15 09:33:02 +00001699 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001700 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001701 }
1702
Alexey Bataevec474782014-10-09 08:45:04 +00001703 /// \brief Build a new predefined expression.
1704 ///
1705 /// By default, performs semantic analysis to build the new expression.
1706 /// Subclasses may override this routine to provide different behavior.
1707 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1708 PredefinedExpr::IdentType IT) {
1709 return getSema().BuildPredefinedExpr(Loc, IT);
1710 }
1711
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 /// \brief Build a new expression that references a declaration.
1713 ///
1714 /// By default, performs semantic analysis to build the new expression.
1715 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001716 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001717 LookupResult &R,
1718 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001719 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1720 }
1721
1722
1723 /// \brief Build a new expression that references a declaration.
1724 ///
1725 /// By default, performs semantic analysis to build the new expression.
1726 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001727 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001728 ValueDecl *VD,
1729 const DeclarationNameInfo &NameInfo,
1730 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001731 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001732 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001733
1734 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001735
1736 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 }
Mike Stump11289f42009-09-09 15:08:12 +00001738
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001740 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001741 /// By default, performs semantic analysis to build the new expression.
1742 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001743 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001744 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001745 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001746 }
1747
Douglas Gregorad8a3362009-09-04 17:36:40 +00001748 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001749 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001750 /// By default, performs semantic analysis to build the new expression.
1751 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001752 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001753 SourceLocation OperatorLoc,
1754 bool isArrow,
1755 CXXScopeSpec &SS,
1756 TypeSourceInfo *ScopeType,
1757 SourceLocation CCLoc,
1758 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001759 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001760
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001762 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001763 /// By default, performs semantic analysis to build the new expression.
1764 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001765 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001766 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001767 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001768 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001769 }
Mike Stump11289f42009-09-09 15:08:12 +00001770
Douglas Gregor882211c2010-04-28 22:16:22 +00001771 /// \brief Build a new builtin offsetof expression.
1772 ///
1773 /// By default, performs semantic analysis to build the new expression.
1774 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001775 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001776 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001777 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001778 unsigned NumComponents,
1779 SourceLocation RParenLoc) {
1780 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1781 NumComponents, RParenLoc);
1782 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001783
1784 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001785 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001786 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 /// By default, performs semantic analysis to build the new expression.
1788 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001789 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1790 SourceLocation OpLoc,
1791 UnaryExprOrTypeTrait ExprKind,
1792 SourceRange R) {
1793 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001794 }
1795
Peter Collingbournee190dee2011-03-11 19:24:49 +00001796 /// \brief Build a new sizeof, alignof or vec step expression with an
1797 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001798 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001799 /// By default, performs semantic analysis to build the new expression.
1800 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001801 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1802 UnaryExprOrTypeTrait ExprKind,
1803 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001804 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001805 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001806 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001807 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001808
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001809 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001810 }
Mike Stump11289f42009-09-09 15:08:12 +00001811
Douglas Gregora16548e2009-08-11 05:31:07 +00001812 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001813 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001814 /// By default, performs semantic analysis to build the new expression.
1815 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001816 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001817 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001818 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001819 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001820 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001821 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001822 RBracketLoc);
1823 }
1824
1825 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001826 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001827 /// By default, performs semantic analysis to build the new expression.
1828 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001829 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001830 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001831 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001832 Expr *ExecConfig = nullptr) {
1833 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001834 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001835 }
1836
1837 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001838 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001839 /// By default, performs semantic analysis to build the new expression.
1840 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001841 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001842 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001843 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001844 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001845 const DeclarationNameInfo &MemberNameInfo,
1846 ValueDecl *Member,
1847 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001848 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001849 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001850 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1851 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001852 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001853 // We have a reference to an unnamed field. This is always the
1854 // base of an anonymous struct/union member access, i.e. the
1855 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001856 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001857 assert(Member->getType()->isRecordType() &&
1858 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001859
Richard Smithcab9a7d2011-10-26 19:06:56 +00001860 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001861 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001862 QualifierLoc.getNestedNameSpecifier(),
1863 FoundDecl, Member);
1864 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001865 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001866 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001867 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00001868 MemberExpr *ME = new (getSema().Context)
1869 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
1870 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001871 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001872 }
Mike Stump11289f42009-09-09 15:08:12 +00001873
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001874 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001875 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001876
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001877 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001878 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001879
John McCall16df1e52010-03-30 21:47:33 +00001880 // FIXME: this involves duplicating earlier analysis in a lot of
1881 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001882 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001883 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001884 R.resolveKind();
1885
John McCallb268a282010-08-23 23:25:46 +00001886 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001887 SS, TemplateKWLoc,
1888 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001889 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001890 }
Mike Stump11289f42009-09-09 15:08:12 +00001891
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001893 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001894 /// By default, performs semantic analysis to build the new expression.
1895 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001896 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001897 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001898 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001899 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001900 }
1901
1902 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001903 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 /// By default, performs semantic analysis to build the new expression.
1905 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001906 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001907 SourceLocation QuestionLoc,
1908 Expr *LHS,
1909 SourceLocation ColonLoc,
1910 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001911 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1912 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 }
1914
Douglas Gregora16548e2009-08-11 05:31:07 +00001915 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001916 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 /// By default, performs semantic analysis to build the new expression.
1918 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001919 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001920 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001922 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001923 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001924 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001925 }
Mike Stump11289f42009-09-09 15:08:12 +00001926
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001928 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 /// By default, performs semantic analysis to build the new expression.
1930 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001931 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001932 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001933 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001934 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001935 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001936 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 }
Mike Stump11289f42009-09-09 15:08:12 +00001938
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001940 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 /// By default, performs semantic analysis to build the new expression.
1942 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001943 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 SourceLocation OpLoc,
1945 SourceLocation AccessorLoc,
1946 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001947
John McCall10eae182009-11-30 22:42:35 +00001948 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001949 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001950 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001951 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001952 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001953 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001954 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001955 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001956 }
Mike Stump11289f42009-09-09 15:08:12 +00001957
Douglas Gregora16548e2009-08-11 05:31:07 +00001958 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001959 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 /// By default, performs semantic analysis to build the new expression.
1961 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001962 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001963 MultiExprArg Inits,
1964 SourceLocation RBraceLoc,
1965 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001966 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001967 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001968 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001969 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001970
Douglas Gregord3d93062009-11-09 17:16:50 +00001971 // Patch in the result type we were given, which may have been computed
1972 // when the initial InitListExpr was built.
1973 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1974 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001975 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 }
Mike Stump11289f42009-09-09 15:08:12 +00001977
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001979 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001980 /// By default, performs semantic analysis to build the new expression.
1981 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001982 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 MultiExprArg ArrayExprs,
1984 SourceLocation EqualOrColonLoc,
1985 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001986 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001987 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001988 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001989 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001990 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001991 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001992
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001993 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 }
Mike Stump11289f42009-09-09 15:08:12 +00001995
Douglas Gregora16548e2009-08-11 05:31:07 +00001996 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001997 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 /// By default, builds the implicit value initialization without performing
1999 /// any semantic analysis. Subclasses may override this routine to provide
2000 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002001 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002002 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 }
Mike Stump11289f42009-09-09 15:08:12 +00002004
Douglas Gregora16548e2009-08-11 05:31:07 +00002005 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002006 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002007 /// By default, performs semantic analysis to build the new expression.
2008 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002009 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002010 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002011 SourceLocation RParenLoc) {
2012 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002013 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002014 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002015 }
2016
2017 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002018 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 /// By default, performs semantic analysis to build the new expression.
2020 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002021 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002022 MultiExprArg SubExprs,
2023 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002024 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002025 }
Mike Stump11289f42009-09-09 15:08:12 +00002026
Douglas Gregora16548e2009-08-11 05:31:07 +00002027 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002028 ///
2029 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 /// rather than attempting to map the label statement itself.
2031 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002032 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002033 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002034 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002035 }
Mike Stump11289f42009-09-09 15:08:12 +00002036
Douglas Gregora16548e2009-08-11 05:31:07 +00002037 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002038 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002039 /// By default, performs semantic analysis to build the new expression.
2040 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002041 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002042 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002044 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002045 }
Mike Stump11289f42009-09-09 15:08:12 +00002046
Douglas Gregora16548e2009-08-11 05:31:07 +00002047 /// \brief Build a new __builtin_choose_expr expression.
2048 ///
2049 /// By default, performs semantic analysis to build the new expression.
2050 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002051 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002052 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 SourceLocation RParenLoc) {
2054 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002055 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002056 RParenLoc);
2057 }
Mike Stump11289f42009-09-09 15:08:12 +00002058
Peter Collingbourne91147592011-04-15 00:35:48 +00002059 /// \brief Build a new generic selection expression.
2060 ///
2061 /// By default, performs semantic analysis to build the new expression.
2062 /// Subclasses may override this routine to provide different behavior.
2063 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2064 SourceLocation DefaultLoc,
2065 SourceLocation RParenLoc,
2066 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002067 ArrayRef<TypeSourceInfo *> Types,
2068 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002069 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002070 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002071 }
2072
Douglas Gregora16548e2009-08-11 05:31:07 +00002073 /// \brief Build a new overloaded operator call expression.
2074 ///
2075 /// By default, performs semantic analysis to build the new expression.
2076 /// The semantic analysis provides the behavior of template instantiation,
2077 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002078 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002079 /// argument-dependent lookup, etc. Subclasses may override this routine to
2080 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002081 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002083 Expr *Callee,
2084 Expr *First,
2085 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002086
2087 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002088 /// reinterpret_cast.
2089 ///
2090 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002091 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002092 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002093 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002094 Stmt::StmtClass Class,
2095 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002096 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002097 SourceLocation RAngleLoc,
2098 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002099 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002100 SourceLocation RParenLoc) {
2101 switch (Class) {
2102 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002103 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002104 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002105 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002106
2107 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002108 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002109 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002110 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002111
Douglas Gregora16548e2009-08-11 05:31:07 +00002112 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002113 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002114 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002115 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002116 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002117
Douglas Gregora16548e2009-08-11 05:31:07 +00002118 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002119 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002120 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002121 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002122
Douglas Gregora16548e2009-08-11 05:31:07 +00002123 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002124 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002125 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002126 }
Mike Stump11289f42009-09-09 15:08:12 +00002127
Douglas Gregora16548e2009-08-11 05:31:07 +00002128 /// \brief Build a new C++ static_cast expression.
2129 ///
2130 /// By default, performs semantic analysis to build the new expression.
2131 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002132 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002133 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002134 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 SourceLocation RAngleLoc,
2136 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002137 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002139 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002140 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002141 SourceRange(LAngleLoc, RAngleLoc),
2142 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002143 }
2144
2145 /// \brief Build a new C++ dynamic_cast expression.
2146 ///
2147 /// By default, performs semantic analysis to build the new expression.
2148 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002149 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002150 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002151 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002152 SourceLocation RAngleLoc,
2153 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002154 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002155 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002156 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002157 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002158 SourceRange(LAngleLoc, RAngleLoc),
2159 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 }
2161
2162 /// \brief Build a new C++ reinterpret_cast expression.
2163 ///
2164 /// By default, performs semantic analysis to build the new expression.
2165 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002166 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002167 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002168 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002169 SourceLocation RAngleLoc,
2170 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002171 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002173 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002174 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002175 SourceRange(LAngleLoc, RAngleLoc),
2176 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 }
2178
2179 /// \brief Build a new C++ const_cast expression.
2180 ///
2181 /// By default, performs semantic analysis to build the new expression.
2182 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002183 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002185 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 SourceLocation RAngleLoc,
2187 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002188 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002190 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002191 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002192 SourceRange(LAngleLoc, RAngleLoc),
2193 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 }
Mike Stump11289f42009-09-09 15:08:12 +00002195
Douglas Gregora16548e2009-08-11 05:31:07 +00002196 /// \brief Build a new C++ functional-style cast expression.
2197 ///
2198 /// By default, performs semantic analysis to build the new expression.
2199 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002200 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2201 SourceLocation LParenLoc,
2202 Expr *Sub,
2203 SourceLocation RParenLoc) {
2204 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002205 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002206 RParenLoc);
2207 }
Mike Stump11289f42009-09-09 15:08:12 +00002208
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 /// \brief Build a new C++ typeid(type) expression.
2210 ///
2211 /// By default, performs semantic analysis to build the new expression.
2212 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002213 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002214 SourceLocation TypeidLoc,
2215 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002216 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002217 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002218 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002219 }
Mike Stump11289f42009-09-09 15:08:12 +00002220
Francois Pichet9f4f2072010-09-08 12:20:18 +00002221
Douglas Gregora16548e2009-08-11 05:31:07 +00002222 /// \brief Build a new C++ typeid(expr) expression.
2223 ///
2224 /// By default, performs semantic analysis to build the new expression.
2225 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002226 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002227 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002228 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002229 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002230 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002231 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002232 }
2233
Francois Pichet9f4f2072010-09-08 12:20:18 +00002234 /// \brief Build a new C++ __uuidof(type) expression.
2235 ///
2236 /// By default, performs semantic analysis to build the new expression.
2237 /// Subclasses may override this routine to provide different behavior.
2238 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2239 SourceLocation TypeidLoc,
2240 TypeSourceInfo *Operand,
2241 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002242 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002243 RParenLoc);
2244 }
2245
2246 /// \brief Build a new C++ __uuidof(expr) expression.
2247 ///
2248 /// By default, performs semantic analysis to build the new expression.
2249 /// Subclasses may override this routine to provide different behavior.
2250 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2251 SourceLocation TypeidLoc,
2252 Expr *Operand,
2253 SourceLocation RParenLoc) {
2254 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2255 RParenLoc);
2256 }
2257
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 /// \brief Build a new C++ "this" expression.
2259 ///
2260 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002261 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002262 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002263 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002264 QualType ThisType,
2265 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002266 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002267 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002268 }
2269
2270 /// \brief Build a new C++ throw expression.
2271 ///
2272 /// By default, performs semantic analysis to build the new expression.
2273 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002274 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2275 bool IsThrownVariableInScope) {
2276 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002277 }
2278
2279 /// \brief Build a new C++ default-argument expression.
2280 ///
2281 /// By default, builds a new default-argument expression, which does not
2282 /// require any semantic analysis. Subclasses may override this routine to
2283 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002284 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002285 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002286 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002287 }
2288
Richard Smith852c9db2013-04-20 22:23:05 +00002289 /// \brief Build a new C++11 default-initialization expression.
2290 ///
2291 /// By default, builds a new default field initialization expression, which
2292 /// does not require any semantic analysis. Subclasses may override this
2293 /// routine to provide different behavior.
2294 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2295 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002296 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002297 }
2298
Douglas Gregora16548e2009-08-11 05:31:07 +00002299 /// \brief Build a new C++ zero-initialization expression.
2300 ///
2301 /// By default, performs semantic analysis to build the new expression.
2302 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002303 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2304 SourceLocation LParenLoc,
2305 SourceLocation RParenLoc) {
2306 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002307 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002308 }
Mike Stump11289f42009-09-09 15:08:12 +00002309
Douglas Gregora16548e2009-08-11 05:31:07 +00002310 /// \brief Build a new C++ "new" expression.
2311 ///
2312 /// By default, performs semantic analysis to build the new expression.
2313 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002314 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002315 bool UseGlobal,
2316 SourceLocation PlacementLParen,
2317 MultiExprArg PlacementArgs,
2318 SourceLocation PlacementRParen,
2319 SourceRange TypeIdParens,
2320 QualType AllocatedType,
2321 TypeSourceInfo *AllocatedTypeInfo,
2322 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002323 SourceRange DirectInitRange,
2324 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002325 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002326 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002327 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002328 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002329 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002330 AllocatedType,
2331 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002332 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002333 DirectInitRange,
2334 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002335 }
Mike Stump11289f42009-09-09 15:08:12 +00002336
Douglas Gregora16548e2009-08-11 05:31:07 +00002337 /// \brief Build a new C++ "delete" expression.
2338 ///
2339 /// By default, performs semantic analysis to build the new expression.
2340 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002341 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002342 bool IsGlobalDelete,
2343 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002344 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002345 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002346 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002347 }
Mike Stump11289f42009-09-09 15:08:12 +00002348
Douglas Gregor29c42f22012-02-24 07:38:34 +00002349 /// \brief Build a new type trait expression.
2350 ///
2351 /// By default, performs semantic analysis to build the new expression.
2352 /// Subclasses may override this routine to provide different behavior.
2353 ExprResult RebuildTypeTrait(TypeTrait Trait,
2354 SourceLocation StartLoc,
2355 ArrayRef<TypeSourceInfo *> Args,
2356 SourceLocation RParenLoc) {
2357 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2358 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002359
John Wiegley6242b6a2011-04-28 00:16:57 +00002360 /// \brief Build a new array type trait expression.
2361 ///
2362 /// By default, performs semantic analysis to build the new expression.
2363 /// Subclasses may override this routine to provide different behavior.
2364 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2365 SourceLocation StartLoc,
2366 TypeSourceInfo *TSInfo,
2367 Expr *DimExpr,
2368 SourceLocation RParenLoc) {
2369 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2370 }
2371
John Wiegleyf9f65842011-04-25 06:54:41 +00002372 /// \brief Build a new expression trait expression.
2373 ///
2374 /// By default, performs semantic analysis to build the new expression.
2375 /// Subclasses may override this routine to provide different behavior.
2376 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2377 SourceLocation StartLoc,
2378 Expr *Queried,
2379 SourceLocation RParenLoc) {
2380 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2381 }
2382
Mike Stump11289f42009-09-09 15:08:12 +00002383 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002384 /// expression.
2385 ///
2386 /// By default, performs semantic analysis to build the new expression.
2387 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002388 ExprResult RebuildDependentScopeDeclRefExpr(
2389 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002390 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002391 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002392 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002393 bool IsAddressOfOperand,
2394 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002395 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002396 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002397
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002398 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002399 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2400 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002401
Reid Kleckner32506ed2014-06-12 23:03:48 +00002402 return getSema().BuildQualifiedDeclarationNameExpr(
2403 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002404 }
2405
2406 /// \brief Build a new template-id expression.
2407 ///
2408 /// By default, performs semantic analysis to build the new expression.
2409 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002410 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002411 SourceLocation TemplateKWLoc,
2412 LookupResult &R,
2413 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002414 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002415 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2416 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002417 }
2418
2419 /// \brief Build a new object-construction expression.
2420 ///
2421 /// By default, performs semantic analysis to build the new expression.
2422 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002423 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002424 SourceLocation Loc,
2425 CXXConstructorDecl *Constructor,
2426 bool IsElidable,
2427 MultiExprArg Args,
2428 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002429 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002430 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002431 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002432 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002433 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002434 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002435 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002436 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002437 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002438
Douglas Gregordb121ba2009-12-14 16:27:04 +00002439 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002440 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002441 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002442 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002443 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002444 RequiresZeroInit, ConstructKind,
2445 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002446 }
2447
2448 /// \brief Build a new object-construction expression.
2449 ///
2450 /// By default, performs semantic analysis to build the new expression.
2451 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002452 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2453 SourceLocation LParenLoc,
2454 MultiExprArg Args,
2455 SourceLocation RParenLoc) {
2456 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002457 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002458 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002459 RParenLoc);
2460 }
2461
2462 /// \brief Build a new object-construction expression.
2463 ///
2464 /// By default, performs semantic analysis to build the new expression.
2465 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002466 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2467 SourceLocation LParenLoc,
2468 MultiExprArg Args,
2469 SourceLocation RParenLoc) {
2470 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002471 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002472 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002473 RParenLoc);
2474 }
Mike Stump11289f42009-09-09 15:08:12 +00002475
Douglas Gregora16548e2009-08-11 05:31:07 +00002476 /// \brief Build a new member reference expression.
2477 ///
2478 /// By default, performs semantic analysis to build the new expression.
2479 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002480 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002481 QualType BaseType,
2482 bool IsArrow,
2483 SourceLocation OperatorLoc,
2484 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002485 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002486 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002487 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002488 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002489 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002490 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002491
John McCallb268a282010-08-23 23:25:46 +00002492 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002493 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002494 SS, TemplateKWLoc,
2495 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002496 MemberNameInfo,
2497 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002498 }
2499
John McCall10eae182009-11-30 22:42:35 +00002500 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002501 ///
2502 /// By default, performs semantic analysis to build the new expression.
2503 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002504 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2505 SourceLocation OperatorLoc,
2506 bool IsArrow,
2507 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002508 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002509 NamedDecl *FirstQualifierInScope,
2510 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002511 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002512 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002513 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002514
John McCallb268a282010-08-23 23:25:46 +00002515 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002516 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002517 SS, TemplateKWLoc,
2518 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002519 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002520 }
Mike Stump11289f42009-09-09 15:08:12 +00002521
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002522 /// \brief Build a new noexcept expression.
2523 ///
2524 /// By default, performs semantic analysis to build the new expression.
2525 /// Subclasses may override this routine to provide different behavior.
2526 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2527 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2528 }
2529
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002530 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002531 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2532 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002533 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002534 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002535 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002536 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2537 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002538 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002539
2540 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2541 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002542 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002543 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002544
Patrick Beard0caa3942012-04-19 00:25:12 +00002545 /// \brief Build a new Objective-C boxed expression.
2546 ///
2547 /// By default, performs semantic analysis to build the new expression.
2548 /// Subclasses may override this routine to provide different behavior.
2549 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2550 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2551 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002552
Ted Kremeneke65b0862012-03-06 20:05:56 +00002553 /// \brief Build a new Objective-C array literal.
2554 ///
2555 /// By default, performs semantic analysis to build the new expression.
2556 /// Subclasses may override this routine to provide different behavior.
2557 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2558 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002559 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002560 MultiExprArg(Elements, NumElements));
2561 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002562
2563 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002564 Expr *Base, Expr *Key,
2565 ObjCMethodDecl *getterMethod,
2566 ObjCMethodDecl *setterMethod) {
2567 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2568 getterMethod, setterMethod);
2569 }
2570
2571 /// \brief Build a new Objective-C dictionary literal.
2572 ///
2573 /// By default, performs semantic analysis to build the new expression.
2574 /// Subclasses may override this routine to provide different behavior.
2575 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2576 ObjCDictionaryElement *Elements,
2577 unsigned NumElements) {
2578 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2579 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002580
James Dennett2a4d13c2012-06-15 07:13:21 +00002581 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002582 ///
2583 /// By default, performs semantic analysis to build the new expression.
2584 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002585 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002586 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002587 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002588 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002589 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002590
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002591 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002592 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002593 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002594 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002595 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002596 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002597 MultiExprArg Args,
2598 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002599 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2600 ReceiverTypeInfo->getType(),
2601 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002602 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002603 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002604 }
2605
2606 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002607 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002608 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002609 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002610 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002611 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002612 MultiExprArg Args,
2613 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002614 return SemaRef.BuildInstanceMessage(Receiver,
2615 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002616 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002617 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002618 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002619 }
2620
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002621 /// \brief Build a new Objective-C instance/class message to 'super'.
2622 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2623 Selector Sel,
2624 ArrayRef<SourceLocation> SelectorLocs,
2625 ObjCMethodDecl *Method,
2626 SourceLocation LBracLoc,
2627 MultiExprArg Args,
2628 SourceLocation RBracLoc) {
2629 ObjCInterfaceDecl *Class = Method->getClassInterface();
2630 QualType ReceiverTy = SemaRef.Context.getObjCInterfaceType(Class);
2631
2632 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
2633 ReceiverTy,
2634 SuperLoc,
2635 Sel, Method, LBracLoc, SelectorLocs,
2636 RBracLoc, Args)
2637 : SemaRef.BuildClassMessage(nullptr,
2638 ReceiverTy,
2639 SuperLoc,
2640 Sel, Method, LBracLoc, SelectorLocs,
2641 RBracLoc, Args);
2642
2643
2644 }
2645
Douglas Gregord51d90d2010-04-26 20:11:03 +00002646 /// \brief Build a new Objective-C ivar reference expression.
2647 ///
2648 /// By default, performs semantic analysis to build the new expression.
2649 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002650 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002651 SourceLocation IvarLoc,
2652 bool IsArrow, bool IsFreeIvar) {
2653 // FIXME: We lose track of the IsFreeIvar bit.
2654 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002655 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2656 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002657 /*FIXME:*/IvarLoc, IsArrow,
2658 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002659 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002660 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002661 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002662 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002663
2664 /// \brief Build a new Objective-C property reference expression.
2665 ///
2666 /// By default, performs semantic analysis to build the new expression.
2667 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002668 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002669 ObjCPropertyDecl *Property,
2670 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002671 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002672 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2673 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2674 /*FIXME:*/PropertyLoc,
2675 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002676 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002677 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002678 NameInfo,
2679 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002680 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002681
John McCallb7bd14f2010-12-02 01:19:52 +00002682 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002683 ///
2684 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002685 /// Subclasses may override this routine to provide different behavior.
2686 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2687 ObjCMethodDecl *Getter,
2688 ObjCMethodDecl *Setter,
2689 SourceLocation PropertyLoc) {
2690 // Since these expressions can only be value-dependent, we do not
2691 // need to perform semantic analysis again.
2692 return Owned(
2693 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2694 VK_LValue, OK_ObjCProperty,
2695 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002696 }
2697
Douglas Gregord51d90d2010-04-26 20:11:03 +00002698 /// \brief Build a new Objective-C "isa" expression.
2699 ///
2700 /// By default, performs semantic analysis to build the new expression.
2701 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002702 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002703 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002704 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002705 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2706 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002707 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002708 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002709 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002710 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002711 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002712 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002713
Douglas Gregora16548e2009-08-11 05:31:07 +00002714 /// \brief Build a new shuffle vector expression.
2715 ///
2716 /// By default, performs semantic analysis to build the new expression.
2717 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002718 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002719 MultiExprArg SubExprs,
2720 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002721 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002722 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002723 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2724 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2725 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002726 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002727
Douglas Gregora16548e2009-08-11 05:31:07 +00002728 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002729 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002730 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2731 SemaRef.Context.BuiltinFnTy,
2732 VK_RValue, BuiltinLoc);
2733 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2734 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002735 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002736
2737 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002738 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002739 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002740 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002741
Douglas Gregora16548e2009-08-11 05:31:07 +00002742 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002743 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002744 }
John McCall31f82722010-11-12 08:19:04 +00002745
Hal Finkelc4d7c822013-09-18 03:29:45 +00002746 /// \brief Build a new convert vector expression.
2747 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2748 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2749 SourceLocation RParenLoc) {
2750 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2751 BuiltinLoc, RParenLoc);
2752 }
2753
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002754 /// \brief Build a new template argument pack expansion.
2755 ///
2756 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002757 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002758 /// different behavior.
2759 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002760 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002761 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002762 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002763 case TemplateArgument::Expression: {
2764 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002765 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2766 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002767 if (Result.isInvalid())
2768 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002769
Douglas Gregor98318c22011-01-03 21:37:45 +00002770 return TemplateArgumentLoc(Result.get(), Result.get());
2771 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002772
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002773 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002774 return TemplateArgumentLoc(TemplateArgument(
2775 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002776 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002777 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002778 Pattern.getTemplateNameLoc(),
2779 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002780
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002781 case TemplateArgument::Null:
2782 case TemplateArgument::Integral:
2783 case TemplateArgument::Declaration:
2784 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002785 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002786 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002787 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002788
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002789 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002790 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002791 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002792 EllipsisLoc,
2793 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002794 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2795 Expansion);
2796 break;
2797 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002798
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002799 return TemplateArgumentLoc();
2800 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002801
Douglas Gregor968f23a2011-01-03 19:31:53 +00002802 /// \brief Build a new expression pack expansion.
2803 ///
2804 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002805 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002806 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002807 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002808 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002809 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002810 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002811
Richard Smith0f0af192014-11-08 05:07:16 +00002812 /// \brief Build a new C++1z fold-expression.
2813 ///
2814 /// By default, performs semantic analysis in order to build a new fold
2815 /// expression.
2816 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
2817 BinaryOperatorKind Operator,
2818 SourceLocation EllipsisLoc, Expr *RHS,
2819 SourceLocation RParenLoc) {
2820 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
2821 RHS, RParenLoc);
2822 }
2823
2824 /// \brief Build an empty C++1z fold-expression with the given operator.
2825 ///
2826 /// By default, produces the fallback value for the fold-expression, or
2827 /// produce an error if there is no fallback value.
2828 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
2829 BinaryOperatorKind Operator) {
2830 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
2831 }
2832
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002833 /// \brief Build a new atomic operation expression.
2834 ///
2835 /// By default, performs semantic analysis to build the new expression.
2836 /// Subclasses may override this routine to provide different behavior.
2837 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2838 MultiExprArg SubExprs,
2839 QualType RetTy,
2840 AtomicExpr::AtomicOp Op,
2841 SourceLocation RParenLoc) {
2842 // Just create the expression; there is not any interesting semantic
2843 // analysis here because we can't actually build an AtomicExpr until
2844 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002845 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002846 RParenLoc);
2847 }
2848
John McCall31f82722010-11-12 08:19:04 +00002849private:
Douglas Gregor14454802011-02-25 02:25:35 +00002850 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2851 QualType ObjectType,
2852 NamedDecl *FirstQualifierInScope,
2853 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002854
2855 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2856 QualType ObjectType,
2857 NamedDecl *FirstQualifierInScope,
2858 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002859
2860 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2861 NamedDecl *FirstQualifierInScope,
2862 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002863};
Douglas Gregora16548e2009-08-11 05:31:07 +00002864
Douglas Gregorebe10102009-08-20 07:17:43 +00002865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002866StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002867 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002868 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002869
Douglas Gregorebe10102009-08-20 07:17:43 +00002870 switch (S->getStmtClass()) {
2871 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002872
Douglas Gregorebe10102009-08-20 07:17:43 +00002873 // Transform individual statement nodes
2874#define STMT(Node, Parent) \
2875 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002876#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002877#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002878#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002879
Douglas Gregorebe10102009-08-20 07:17:43 +00002880 // Transform expressions by calling TransformExpr.
2881#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002882#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002883#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002884#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002885 {
John McCalldadc5752010-08-24 06:29:42 +00002886 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002887 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002888 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002889
Richard Smith945f8d32013-01-14 22:39:08 +00002890 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002891 }
Mike Stump11289f42009-09-09 15:08:12 +00002892 }
2893
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002894 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002895}
Mike Stump11289f42009-09-09 15:08:12 +00002896
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002897template<typename Derived>
2898OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2899 if (!S)
2900 return S;
2901
2902 switch (S->getClauseKind()) {
2903 default: break;
2904 // Transform individual clause nodes
2905#define OPENMP_CLAUSE(Name, Class) \
2906 case OMPC_ ## Name : \
2907 return getDerived().Transform ## Class(cast<Class>(S));
2908#include "clang/Basic/OpenMPKinds.def"
2909 }
2910
2911 return S;
2912}
2913
Mike Stump11289f42009-09-09 15:08:12 +00002914
Douglas Gregore922c772009-08-04 22:27:00 +00002915template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002916ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002917 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002918 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002919
2920 switch (E->getStmtClass()) {
2921 case Stmt::NoStmtClass: break;
2922#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002923#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002924#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002925 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002926#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002927 }
2928
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002929 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002930}
2931
2932template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002933ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00002934 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00002935 // Initializers are instantiated like expressions, except that various outer
2936 // layers are stripped.
2937 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002938 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002939
2940 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2941 Init = ExprTemp->getSubExpr();
2942
Richard Smithe6ca4752013-05-30 22:40:16 +00002943 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2944 Init = MTE->GetTemporaryExpr();
2945
Richard Smithd59b8322012-12-19 01:39:02 +00002946 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2947 Init = Binder->getSubExpr();
2948
2949 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2950 Init = ICE->getSubExprAsWritten();
2951
Richard Smithcc1b96d2013-06-12 22:31:48 +00002952 if (CXXStdInitializerListExpr *ILE =
2953 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00002954 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00002955
Richard Smithc6abd962014-07-25 01:12:44 +00002956 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00002957 // InitListExprs. Other forms of copy-initialization will be a no-op if
2958 // the initializer is already the right type.
2959 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00002960 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00002961 return getDerived().TransformExpr(Init);
2962
2963 // Revert value-initialization back to empty parens.
2964 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2965 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002966 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002967 Parens.getEnd());
2968 }
2969
2970 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2971 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002972 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002973 SourceLocation());
2974
2975 // Revert initialization by constructor back to a parenthesized or braced list
2976 // of expressions. Any other form of initializer can just be reused directly.
2977 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002978 return getDerived().TransformExpr(Init);
2979
Richard Smithf8adcdc2014-07-17 05:12:35 +00002980 // If the initialization implicitly converted an initializer list to a
2981 // std::initializer_list object, unwrap the std::initializer_list too.
2982 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00002983 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00002984
Richard Smithd59b8322012-12-19 01:39:02 +00002985 SmallVector<Expr*, 8> NewArgs;
2986 bool ArgChanged = false;
2987 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00002988 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00002989 return ExprError();
2990
2991 // If this was list initialization, revert to list form.
2992 if (Construct->isListInitialization())
2993 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2994 Construct->getLocEnd(),
2995 Construct->getType());
2996
Richard Smithd59b8322012-12-19 01:39:02 +00002997 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002998 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00002999 if (Parens.isInvalid()) {
3000 // This was a variable declaration's initialization for which no initializer
3001 // was specified.
3002 assert(NewArgs.empty() &&
3003 "no parens or braces but have direct init with arguments?");
3004 return ExprEmpty();
3005 }
Richard Smithd59b8322012-12-19 01:39:02 +00003006 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3007 Parens.getEnd());
3008}
3009
3010template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00003011bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
3012 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003013 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003014 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003015 bool *ArgChanged) {
3016 for (unsigned I = 0; I != NumInputs; ++I) {
3017 // If requested, drop call arguments that need to be dropped.
3018 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3019 if (ArgChanged)
3020 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003021
Douglas Gregora3efea12011-01-03 19:04:46 +00003022 break;
3023 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003024
Douglas Gregor968f23a2011-01-03 19:31:53 +00003025 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3026 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003027
Chris Lattner01cf8db2011-07-20 06:58:45 +00003028 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003029 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3030 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003031
Douglas Gregor968f23a2011-01-03 19:31:53 +00003032 // Determine whether the set of unexpanded parameter packs can and should
3033 // be expanded.
3034 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003035 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003036 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3037 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003038 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3039 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003040 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003041 Expand, RetainExpansion,
3042 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003043 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003044
Douglas Gregor968f23a2011-01-03 19:31:53 +00003045 if (!Expand) {
3046 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003047 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003048 // expansion.
3049 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3050 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3051 if (OutPattern.isInvalid())
3052 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003053
3054 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003055 Expansion->getEllipsisLoc(),
3056 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003057 if (Out.isInvalid())
3058 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003059
Douglas Gregor968f23a2011-01-03 19:31:53 +00003060 if (ArgChanged)
3061 *ArgChanged = true;
3062 Outputs.push_back(Out.get());
3063 continue;
3064 }
John McCall542e7c62011-07-06 07:30:07 +00003065
3066 // Record right away that the argument was changed. This needs
3067 // to happen even if the array expands to nothing.
3068 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003069
Douglas Gregor968f23a2011-01-03 19:31:53 +00003070 // The transform has determined that we should perform an elementwise
3071 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003072 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003073 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3074 ExprResult Out = getDerived().TransformExpr(Pattern);
3075 if (Out.isInvalid())
3076 return true;
3077
Richard Smith9467be42014-06-06 17:33:35 +00003078 // FIXME: Can this happen? We should not try to expand the pack
3079 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003080 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003081 Out = getDerived().RebuildPackExpansion(
3082 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003083 if (Out.isInvalid())
3084 return true;
3085 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003086
Douglas Gregor968f23a2011-01-03 19:31:53 +00003087 Outputs.push_back(Out.get());
3088 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003089
Richard Smith9467be42014-06-06 17:33:35 +00003090 // If we're supposed to retain a pack expansion, do so by temporarily
3091 // forgetting the partially-substituted parameter pack.
3092 if (RetainExpansion) {
3093 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3094
3095 ExprResult Out = getDerived().TransformExpr(Pattern);
3096 if (Out.isInvalid())
3097 return true;
3098
3099 Out = getDerived().RebuildPackExpansion(
3100 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3101 if (Out.isInvalid())
3102 return true;
3103
3104 Outputs.push_back(Out.get());
3105 }
3106
Douglas Gregor968f23a2011-01-03 19:31:53 +00003107 continue;
3108 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003109
Richard Smithd59b8322012-12-19 01:39:02 +00003110 ExprResult Result =
3111 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3112 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003113 if (Result.isInvalid())
3114 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003115
Douglas Gregora3efea12011-01-03 19:04:46 +00003116 if (Result.get() != Inputs[I] && ArgChanged)
3117 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003118
3119 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003120 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003121
Douglas Gregora3efea12011-01-03 19:04:46 +00003122 return false;
3123}
3124
3125template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003126NestedNameSpecifierLoc
3127TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3128 NestedNameSpecifierLoc NNS,
3129 QualType ObjectType,
3130 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003131 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003132 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003133 Qualifier = Qualifier.getPrefix())
3134 Qualifiers.push_back(Qualifier);
3135
3136 CXXScopeSpec SS;
3137 while (!Qualifiers.empty()) {
3138 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3139 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003140
Douglas Gregor14454802011-02-25 02:25:35 +00003141 switch (QNNS->getKind()) {
3142 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003143 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003144 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003145 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003146 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003147 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003148 FirstQualifierInScope, false))
3149 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003150
Douglas Gregor14454802011-02-25 02:25:35 +00003151 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003152
Douglas Gregor14454802011-02-25 02:25:35 +00003153 case NestedNameSpecifier::Namespace: {
3154 NamespaceDecl *NS
3155 = cast_or_null<NamespaceDecl>(
3156 getDerived().TransformDecl(
3157 Q.getLocalBeginLoc(),
3158 QNNS->getAsNamespace()));
3159 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3160 break;
3161 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003162
Douglas Gregor14454802011-02-25 02:25:35 +00003163 case NestedNameSpecifier::NamespaceAlias: {
3164 NamespaceAliasDecl *Alias
3165 = cast_or_null<NamespaceAliasDecl>(
3166 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3167 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003168 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003169 Q.getLocalEndLoc());
3170 break;
3171 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003172
Douglas Gregor14454802011-02-25 02:25:35 +00003173 case NestedNameSpecifier::Global:
3174 // There is no meaningful transformation that one could perform on the
3175 // global scope.
3176 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3177 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003178
Nikola Smiljanic67860242014-09-26 00:28:20 +00003179 case NestedNameSpecifier::Super: {
3180 CXXRecordDecl *RD =
3181 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3182 SourceLocation(), QNNS->getAsRecordDecl()));
3183 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3184 break;
3185 }
3186
Douglas Gregor14454802011-02-25 02:25:35 +00003187 case NestedNameSpecifier::TypeSpecWithTemplate:
3188 case NestedNameSpecifier::TypeSpec: {
3189 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3190 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003191
Douglas Gregor14454802011-02-25 02:25:35 +00003192 if (!TL)
3193 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003194
Douglas Gregor14454802011-02-25 02:25:35 +00003195 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003196 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003197 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003198 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003199 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003200 if (TL.getType()->isEnumeralType())
3201 SemaRef.Diag(TL.getBeginLoc(),
3202 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003203 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3204 Q.getLocalEndLoc());
3205 break;
3206 }
Richard Trieude756fb2011-05-07 01:36:37 +00003207 // If the nested-name-specifier is an invalid type def, don't emit an
3208 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003209 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3210 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003211 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003212 << TL.getType() << SS.getRange();
3213 }
Douglas Gregor14454802011-02-25 02:25:35 +00003214 return NestedNameSpecifierLoc();
3215 }
Douglas Gregore16af532011-02-28 18:50:33 +00003216 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003217
Douglas Gregore16af532011-02-28 18:50:33 +00003218 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003219 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003220 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003221 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003222
Douglas Gregor14454802011-02-25 02:25:35 +00003223 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003224 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003225 !getDerived().AlwaysRebuild())
3226 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003227
3228 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003229 // nested-name-specifier, do so.
3230 if (SS.location_size() == NNS.getDataLength() &&
3231 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3232 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3233
3234 // Allocate new nested-name-specifier location information.
3235 return SS.getWithLocInContext(SemaRef.Context);
3236}
3237
3238template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003239DeclarationNameInfo
3240TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003241::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003242 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003243 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003244 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003245
3246 switch (Name.getNameKind()) {
3247 case DeclarationName::Identifier:
3248 case DeclarationName::ObjCZeroArgSelector:
3249 case DeclarationName::ObjCOneArgSelector:
3250 case DeclarationName::ObjCMultiArgSelector:
3251 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003252 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003253 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003254 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003255
Douglas Gregorf816bd72009-09-03 22:13:48 +00003256 case DeclarationName::CXXConstructorName:
3257 case DeclarationName::CXXDestructorName:
3258 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003259 TypeSourceInfo *NewTInfo;
3260 CanQualType NewCanTy;
3261 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003262 NewTInfo = getDerived().TransformType(OldTInfo);
3263 if (!NewTInfo)
3264 return DeclarationNameInfo();
3265 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003266 }
3267 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003268 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003269 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003270 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003271 if (NewT.isNull())
3272 return DeclarationNameInfo();
3273 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3274 }
Mike Stump11289f42009-09-09 15:08:12 +00003275
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003276 DeclarationName NewName
3277 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3278 NewCanTy);
3279 DeclarationNameInfo NewNameInfo(NameInfo);
3280 NewNameInfo.setName(NewName);
3281 NewNameInfo.setNamedTypeInfo(NewTInfo);
3282 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003283 }
Mike Stump11289f42009-09-09 15:08:12 +00003284 }
3285
David Blaikie83d382b2011-09-23 05:06:16 +00003286 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003287}
3288
3289template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003290TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003291TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3292 TemplateName Name,
3293 SourceLocation NameLoc,
3294 QualType ObjectType,
3295 NamedDecl *FirstQualifierInScope) {
3296 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3297 TemplateDecl *Template = QTN->getTemplateDecl();
3298 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003299
Douglas Gregor9db53502011-03-02 18:07:45 +00003300 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003301 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003302 Template));
3303 if (!TransTemplate)
3304 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003305
Douglas Gregor9db53502011-03-02 18:07:45 +00003306 if (!getDerived().AlwaysRebuild() &&
3307 SS.getScopeRep() == QTN->getQualifier() &&
3308 TransTemplate == Template)
3309 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003310
Douglas Gregor9db53502011-03-02 18:07:45 +00003311 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3312 TransTemplate);
3313 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003314
Douglas Gregor9db53502011-03-02 18:07:45 +00003315 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3316 if (SS.getScopeRep()) {
3317 // These apply to the scope specifier, not the template.
3318 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003319 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003320 }
3321
Douglas Gregor9db53502011-03-02 18:07:45 +00003322 if (!getDerived().AlwaysRebuild() &&
3323 SS.getScopeRep() == DTN->getQualifier() &&
3324 ObjectType.isNull())
3325 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003326
Douglas Gregor9db53502011-03-02 18:07:45 +00003327 if (DTN->isIdentifier()) {
3328 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003329 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003330 NameLoc,
3331 ObjectType,
3332 FirstQualifierInScope);
3333 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003334
Douglas Gregor9db53502011-03-02 18:07:45 +00003335 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3336 ObjectType);
3337 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003338
Douglas Gregor9db53502011-03-02 18:07:45 +00003339 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3340 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003341 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003342 Template));
3343 if (!TransTemplate)
3344 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003345
Douglas Gregor9db53502011-03-02 18:07:45 +00003346 if (!getDerived().AlwaysRebuild() &&
3347 TransTemplate == Template)
3348 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003349
Douglas Gregor9db53502011-03-02 18:07:45 +00003350 return TemplateName(TransTemplate);
3351 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003352
Douglas Gregor9db53502011-03-02 18:07:45 +00003353 if (SubstTemplateTemplateParmPackStorage *SubstPack
3354 = Name.getAsSubstTemplateTemplateParmPack()) {
3355 TemplateTemplateParmDecl *TransParam
3356 = cast_or_null<TemplateTemplateParmDecl>(
3357 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3358 if (!TransParam)
3359 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003360
Douglas Gregor9db53502011-03-02 18:07:45 +00003361 if (!getDerived().AlwaysRebuild() &&
3362 TransParam == SubstPack->getParameterPack())
3363 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003364
3365 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003366 SubstPack->getArgumentPack());
3367 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003368
Douglas Gregor9db53502011-03-02 18:07:45 +00003369 // These should be getting filtered out before they reach the AST.
3370 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003371}
3372
3373template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003374void TreeTransform<Derived>::InventTemplateArgumentLoc(
3375 const TemplateArgument &Arg,
3376 TemplateArgumentLoc &Output) {
3377 SourceLocation Loc = getDerived().getBaseLocation();
3378 switch (Arg.getKind()) {
3379 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003380 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003381 break;
3382
3383 case TemplateArgument::Type:
3384 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003385 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003386
John McCall0ad16662009-10-29 08:12:44 +00003387 break;
3388
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003389 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003390 case TemplateArgument::TemplateExpansion: {
3391 NestedNameSpecifierLocBuilder Builder;
3392 TemplateName Template = Arg.getAsTemplate();
3393 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3394 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3395 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3396 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003397
Douglas Gregor9d802122011-03-02 17:09:35 +00003398 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003399 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003400 Builder.getWithLocInContext(SemaRef.Context),
3401 Loc);
3402 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003403 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003404 Builder.getWithLocInContext(SemaRef.Context),
3405 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003406
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003407 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003408 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003409
John McCall0ad16662009-10-29 08:12:44 +00003410 case TemplateArgument::Expression:
3411 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3412 break;
3413
3414 case TemplateArgument::Declaration:
3415 case TemplateArgument::Integral:
3416 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003417 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003418 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003419 break;
3420 }
3421}
3422
3423template<typename Derived>
3424bool TreeTransform<Derived>::TransformTemplateArgument(
3425 const TemplateArgumentLoc &Input,
3426 TemplateArgumentLoc &Output) {
3427 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003428 switch (Arg.getKind()) {
3429 case TemplateArgument::Null:
3430 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003431 case TemplateArgument::Pack:
3432 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003433 case TemplateArgument::NullPtr:
3434 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003435
Douglas Gregore922c772009-08-04 22:27:00 +00003436 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003437 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003438 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003439 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003440
3441 DI = getDerived().TransformType(DI);
3442 if (!DI) return true;
3443
3444 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3445 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003446 }
Mike Stump11289f42009-09-09 15:08:12 +00003447
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003448 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003449 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3450 if (QualifierLoc) {
3451 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3452 if (!QualifierLoc)
3453 return true;
3454 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003455
Douglas Gregordf846d12011-03-02 18:46:51 +00003456 CXXScopeSpec SS;
3457 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003458 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003459 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3460 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003461 if (Template.isNull())
3462 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003463
Douglas Gregor9d802122011-03-02 17:09:35 +00003464 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003465 Input.getTemplateNameLoc());
3466 return false;
3467 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003468
3469 case TemplateArgument::TemplateExpansion:
3470 llvm_unreachable("Caller should expand pack expansions");
3471
Douglas Gregore922c772009-08-04 22:27:00 +00003472 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003473 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003474 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003475 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003476
John McCall0ad16662009-10-29 08:12:44 +00003477 Expr *InputExpr = Input.getSourceExpression();
3478 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3479
Chris Lattnercdb591a2011-04-25 20:37:58 +00003480 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003481 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003482 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003483 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003484 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003485 }
Douglas Gregore922c772009-08-04 22:27:00 +00003486 }
Mike Stump11289f42009-09-09 15:08:12 +00003487
Douglas Gregore922c772009-08-04 22:27:00 +00003488 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003489 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003490}
3491
Douglas Gregorfe921a72010-12-20 23:36:19 +00003492/// \brief Iterator adaptor that invents template argument location information
3493/// for each of the template arguments in its underlying iterator.
3494template<typename Derived, typename InputIterator>
3495class TemplateArgumentLocInventIterator {
3496 TreeTransform<Derived> &Self;
3497 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003498
Douglas Gregorfe921a72010-12-20 23:36:19 +00003499public:
3500 typedef TemplateArgumentLoc value_type;
3501 typedef TemplateArgumentLoc reference;
3502 typedef typename std::iterator_traits<InputIterator>::difference_type
3503 difference_type;
3504 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003505
Douglas Gregorfe921a72010-12-20 23:36:19 +00003506 class pointer {
3507 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003508
Douglas Gregorfe921a72010-12-20 23:36:19 +00003509 public:
3510 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003511
Douglas Gregorfe921a72010-12-20 23:36:19 +00003512 const TemplateArgumentLoc *operator->() const { return &Arg; }
3513 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003514
Douglas Gregorfe921a72010-12-20 23:36:19 +00003515 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003516
Douglas Gregorfe921a72010-12-20 23:36:19 +00003517 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3518 InputIterator Iter)
3519 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003520
Douglas Gregorfe921a72010-12-20 23:36:19 +00003521 TemplateArgumentLocInventIterator &operator++() {
3522 ++Iter;
3523 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003524 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003525
Douglas Gregorfe921a72010-12-20 23:36:19 +00003526 TemplateArgumentLocInventIterator operator++(int) {
3527 TemplateArgumentLocInventIterator Old(*this);
3528 ++(*this);
3529 return Old;
3530 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003531
Douglas Gregorfe921a72010-12-20 23:36:19 +00003532 reference operator*() const {
3533 TemplateArgumentLoc Result;
3534 Self.InventTemplateArgumentLoc(*Iter, Result);
3535 return Result;
3536 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003537
Douglas Gregorfe921a72010-12-20 23:36:19 +00003538 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003539
Douglas Gregorfe921a72010-12-20 23:36:19 +00003540 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3541 const TemplateArgumentLocInventIterator &Y) {
3542 return X.Iter == Y.Iter;
3543 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003544
Douglas Gregorfe921a72010-12-20 23:36:19 +00003545 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3546 const TemplateArgumentLocInventIterator &Y) {
3547 return X.Iter != Y.Iter;
3548 }
3549};
Chad Rosier1dcde962012-08-08 18:46:20 +00003550
Douglas Gregor42cafa82010-12-20 17:42:22 +00003551template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003552template<typename InputIterator>
3553bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3554 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003555 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003556 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003557 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003558 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003559
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003560 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3561 // Unpack argument packs, which we translate them into separate
3562 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003563 // FIXME: We could do much better if we could guarantee that the
3564 // TemplateArgumentLocInfo for the pack expansion would be usable for
3565 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003566 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003567 TemplateArgument::pack_iterator>
3568 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003569 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003570 In.getArgument().pack_begin()),
3571 PackLocIterator(*this,
3572 In.getArgument().pack_end()),
3573 Outputs))
3574 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003575
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003576 continue;
3577 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003578
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003579 if (In.getArgument().isPackExpansion()) {
3580 // We have a pack expansion, for which we will be substituting into
3581 // the pattern.
3582 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003583 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003584 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003585 = getSema().getTemplateArgumentPackExpansionPattern(
3586 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003587
Chris Lattner01cf8db2011-07-20 06:58:45 +00003588 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003589 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3590 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003591
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003592 // Determine whether the set of unexpanded parameter packs can and should
3593 // be expanded.
3594 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003595 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003596 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003597 if (getDerived().TryExpandParameterPacks(Ellipsis,
3598 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003599 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003600 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003601 RetainExpansion,
3602 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003603 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003604
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003605 if (!Expand) {
3606 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003607 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003608 // expansion.
3609 TemplateArgumentLoc OutPattern;
3610 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3611 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3612 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003613
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003614 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3615 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003616 if (Out.getArgument().isNull())
3617 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003618
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003619 Outputs.addArgument(Out);
3620 continue;
3621 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003622
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003623 // The transform has determined that we should perform an elementwise
3624 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003625 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003626 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3627
3628 if (getDerived().TransformTemplateArgument(Pattern, Out))
3629 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003630
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003631 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003632 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3633 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003634 if (Out.getArgument().isNull())
3635 return true;
3636 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003637
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003638 Outputs.addArgument(Out);
3639 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003640
Douglas Gregor48d24112011-01-10 20:53:55 +00003641 // If we're supposed to retain a pack expansion, do so by temporarily
3642 // forgetting the partially-substituted parameter pack.
3643 if (RetainExpansion) {
3644 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003645
Douglas Gregor48d24112011-01-10 20:53:55 +00003646 if (getDerived().TransformTemplateArgument(Pattern, Out))
3647 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003648
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003649 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3650 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003651 if (Out.getArgument().isNull())
3652 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003653
Douglas Gregor48d24112011-01-10 20:53:55 +00003654 Outputs.addArgument(Out);
3655 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003656
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003657 continue;
3658 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003659
3660 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003661 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003662 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003663
Douglas Gregor42cafa82010-12-20 17:42:22 +00003664 Outputs.addArgument(Out);
3665 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003666
Douglas Gregor42cafa82010-12-20 17:42:22 +00003667 return false;
3668
3669}
3670
Douglas Gregord6ff3322009-08-04 16:50:30 +00003671//===----------------------------------------------------------------------===//
3672// Type transformation
3673//===----------------------------------------------------------------------===//
3674
3675template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003676QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003677 if (getDerived().AlreadyTransformed(T))
3678 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003679
John McCall550e0c22009-10-21 00:40:46 +00003680 // Temporary workaround. All of these transformations should
3681 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003682 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3683 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003684
John McCall31f82722010-11-12 08:19:04 +00003685 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003686
John McCall550e0c22009-10-21 00:40:46 +00003687 if (!NewDI)
3688 return QualType();
3689
3690 return NewDI->getType();
3691}
3692
3693template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003694TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003695 // Refine the base location to the type's location.
3696 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3697 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003698 if (getDerived().AlreadyTransformed(DI->getType()))
3699 return DI;
3700
3701 TypeLocBuilder TLB;
3702
3703 TypeLoc TL = DI->getTypeLoc();
3704 TLB.reserve(TL.getFullDataSize());
3705
John McCall31f82722010-11-12 08:19:04 +00003706 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003707 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003708 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003709
John McCallbcd03502009-12-07 02:54:59 +00003710 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003711}
3712
3713template<typename Derived>
3714QualType
John McCall31f82722010-11-12 08:19:04 +00003715TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003716 switch (T.getTypeLocClass()) {
3717#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003718#define TYPELOC(CLASS, PARENT) \
3719 case TypeLoc::CLASS: \
3720 return getDerived().Transform##CLASS##Type(TLB, \
3721 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003722#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003723 }
Mike Stump11289f42009-09-09 15:08:12 +00003724
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003725 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003726}
3727
3728/// FIXME: By default, this routine adds type qualifiers only to types
3729/// that can have qualifiers, and silently suppresses those qualifiers
3730/// that are not permitted (e.g., qualifiers on reference or function
3731/// types). This is the right thing for template instantiation, but
3732/// probably not for other clients.
3733template<typename Derived>
3734QualType
3735TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003736 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003737 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003738
John McCall31f82722010-11-12 08:19:04 +00003739 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003740 if (Result.isNull())
3741 return QualType();
3742
3743 // Silently suppress qualifiers if the result type can't be qualified.
3744 // FIXME: this is the right thing for template instantiation, but
3745 // probably not for other clients.
3746 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003747 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003748
John McCall31168b02011-06-15 23:02:42 +00003749 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003750 // resulting type.
3751 if (Quals.hasObjCLifetime()) {
3752 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3753 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003754 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003755 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003756 // A lifetime qualifier applied to a substituted template parameter
3757 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003758 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003759 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003760 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3761 QualType Replacement = SubstTypeParam->getReplacementType();
3762 Qualifiers Qs = Replacement.getQualifiers();
3763 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003764 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003765 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3766 Qs);
3767 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003768 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003769 Replacement);
3770 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003771 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3772 // 'auto' types behave the same way as template parameters.
3773 QualType Deduced = AutoTy->getDeducedType();
3774 Qualifiers Qs = Deduced.getQualifiers();
3775 Qs.removeObjCLifetime();
3776 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3777 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003778 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3779 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003780 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003781 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003782 // Otherwise, complain about the addition of a qualifier to an
3783 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003784 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003785 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003786 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003787
Douglas Gregore46db902011-06-17 22:11:49 +00003788 Quals.removeObjCLifetime();
3789 }
3790 }
3791 }
John McCallcb0f89a2010-06-05 06:41:15 +00003792 if (!Quals.empty()) {
3793 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003794 // BuildQualifiedType might not add qualifiers if they are invalid.
3795 if (Result.hasLocalQualifiers())
3796 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003797 // No location information to preserve.
3798 }
John McCall550e0c22009-10-21 00:40:46 +00003799
3800 return Result;
3801}
3802
Douglas Gregor14454802011-02-25 02:25:35 +00003803template<typename Derived>
3804TypeLoc
3805TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3806 QualType ObjectType,
3807 NamedDecl *UnqualLookup,
3808 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003809 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003810 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003811
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003812 TypeSourceInfo *TSI =
3813 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3814 if (TSI)
3815 return TSI->getTypeLoc();
3816 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003817}
3818
Douglas Gregor579c15f2011-03-02 18:32:08 +00003819template<typename Derived>
3820TypeSourceInfo *
3821TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3822 QualType ObjectType,
3823 NamedDecl *UnqualLookup,
3824 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003825 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003826 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003827
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003828 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3829 UnqualLookup, SS);
3830}
3831
3832template <typename Derived>
3833TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3834 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3835 CXXScopeSpec &SS) {
3836 QualType T = TL.getType();
3837 assert(!getDerived().AlreadyTransformed(T));
3838
Douglas Gregor579c15f2011-03-02 18:32:08 +00003839 TypeLocBuilder TLB;
3840 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003841
Douglas Gregor579c15f2011-03-02 18:32:08 +00003842 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003843 TemplateSpecializationTypeLoc SpecTL =
3844 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003845
Douglas Gregor579c15f2011-03-02 18:32:08 +00003846 TemplateName Template
3847 = getDerived().TransformTemplateName(SS,
3848 SpecTL.getTypePtr()->getTemplateName(),
3849 SpecTL.getTemplateNameLoc(),
3850 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003851 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003852 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003853
3854 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003855 Template);
3856 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003857 DependentTemplateSpecializationTypeLoc SpecTL =
3858 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003859
Douglas Gregor579c15f2011-03-02 18:32:08 +00003860 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003861 = getDerived().RebuildTemplateName(SS,
3862 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003863 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003864 ObjectType, UnqualLookup);
3865 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003866 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003867
3868 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003869 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003870 Template,
3871 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003872 } else {
3873 // Nothing special needs to be done for these.
3874 Result = getDerived().TransformType(TLB, TL);
3875 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003876
3877 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003878 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003879
Douglas Gregor579c15f2011-03-02 18:32:08 +00003880 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3881}
3882
John McCall550e0c22009-10-21 00:40:46 +00003883template <class TyLoc> static inline
3884QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3885 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3886 NewT.setNameLoc(T.getNameLoc());
3887 return T.getType();
3888}
3889
John McCall550e0c22009-10-21 00:40:46 +00003890template<typename Derived>
3891QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003892 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003893 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3894 NewT.setBuiltinLoc(T.getBuiltinLoc());
3895 if (T.needsExtraLocalData())
3896 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3897 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003898}
Mike Stump11289f42009-09-09 15:08:12 +00003899
Douglas Gregord6ff3322009-08-04 16:50:30 +00003900template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003901QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003902 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003903 // FIXME: recurse?
3904 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003905}
Mike Stump11289f42009-09-09 15:08:12 +00003906
Reid Kleckner0503a872013-12-05 01:23:43 +00003907template <typename Derived>
3908QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3909 AdjustedTypeLoc TL) {
3910 // Adjustments applied during transformation are handled elsewhere.
3911 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3912}
3913
Douglas Gregord6ff3322009-08-04 16:50:30 +00003914template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003915QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3916 DecayedTypeLoc TL) {
3917 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3918 if (OriginalType.isNull())
3919 return QualType();
3920
3921 QualType Result = TL.getType();
3922 if (getDerived().AlwaysRebuild() ||
3923 OriginalType != TL.getOriginalLoc().getType())
3924 Result = SemaRef.Context.getDecayedType(OriginalType);
3925 TLB.push<DecayedTypeLoc>(Result);
3926 // Nothing to set for DecayedTypeLoc.
3927 return Result;
3928}
3929
3930template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003931QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003932 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003933 QualType PointeeType
3934 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003935 if (PointeeType.isNull())
3936 return QualType();
3937
3938 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003939 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003940 // A dependent pointer type 'T *' has is being transformed such
3941 // that an Objective-C class type is being replaced for 'T'. The
3942 // resulting pointer type is an ObjCObjectPointerType, not a
3943 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003944 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003945
John McCall8b07ec22010-05-15 11:32:37 +00003946 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3947 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003948 return Result;
3949 }
John McCall31f82722010-11-12 08:19:04 +00003950
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003951 if (getDerived().AlwaysRebuild() ||
3952 PointeeType != TL.getPointeeLoc().getType()) {
3953 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3954 if (Result.isNull())
3955 return QualType();
3956 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003957
John McCall31168b02011-06-15 23:02:42 +00003958 // Objective-C ARC can add lifetime qualifiers to the type that we're
3959 // pointing to.
3960 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003961
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003962 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3963 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003964 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003965}
Mike Stump11289f42009-09-09 15:08:12 +00003966
3967template<typename Derived>
3968QualType
John McCall550e0c22009-10-21 00:40:46 +00003969TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003970 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003971 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003972 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3973 if (PointeeType.isNull())
3974 return QualType();
3975
3976 QualType Result = TL.getType();
3977 if (getDerived().AlwaysRebuild() ||
3978 PointeeType != TL.getPointeeLoc().getType()) {
3979 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003980 TL.getSigilLoc());
3981 if (Result.isNull())
3982 return QualType();
3983 }
3984
Douglas Gregor049211a2010-04-22 16:50:51 +00003985 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003986 NewT.setSigilLoc(TL.getSigilLoc());
3987 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003988}
3989
John McCall70dd5f62009-10-30 00:06:24 +00003990/// Transforms a reference type. Note that somewhat paradoxically we
3991/// don't care whether the type itself is an l-value type or an r-value
3992/// type; we only care if the type was *written* as an l-value type
3993/// or an r-value type.
3994template<typename Derived>
3995QualType
3996TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003997 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003998 const ReferenceType *T = TL.getTypePtr();
3999
4000 // Note that this works with the pointee-as-written.
4001 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4002 if (PointeeType.isNull())
4003 return QualType();
4004
4005 QualType Result = TL.getType();
4006 if (getDerived().AlwaysRebuild() ||
4007 PointeeType != T->getPointeeTypeAsWritten()) {
4008 Result = getDerived().RebuildReferenceType(PointeeType,
4009 T->isSpelledAsLValue(),
4010 TL.getSigilLoc());
4011 if (Result.isNull())
4012 return QualType();
4013 }
4014
John McCall31168b02011-06-15 23:02:42 +00004015 // Objective-C ARC can add lifetime qualifiers to the type that we're
4016 // referring to.
4017 TLB.TypeWasModifiedSafely(
4018 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4019
John McCall70dd5f62009-10-30 00:06:24 +00004020 // r-value references can be rebuilt as l-value references.
4021 ReferenceTypeLoc NewTL;
4022 if (isa<LValueReferenceType>(Result))
4023 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4024 else
4025 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4026 NewTL.setSigilLoc(TL.getSigilLoc());
4027
4028 return Result;
4029}
4030
Mike Stump11289f42009-09-09 15:08:12 +00004031template<typename Derived>
4032QualType
John McCall550e0c22009-10-21 00:40:46 +00004033TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004034 LValueReferenceTypeLoc TL) {
4035 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004036}
4037
Mike Stump11289f42009-09-09 15:08:12 +00004038template<typename Derived>
4039QualType
John McCall550e0c22009-10-21 00:40:46 +00004040TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004041 RValueReferenceTypeLoc TL) {
4042 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004043}
Mike Stump11289f42009-09-09 15:08:12 +00004044
Douglas Gregord6ff3322009-08-04 16:50:30 +00004045template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004046QualType
John McCall550e0c22009-10-21 00:40:46 +00004047TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004048 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004049 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004050 if (PointeeType.isNull())
4051 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004052
Abramo Bagnara509357842011-03-05 14:42:21 +00004053 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004054 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004055 if (OldClsTInfo) {
4056 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4057 if (!NewClsTInfo)
4058 return QualType();
4059 }
4060
4061 const MemberPointerType *T = TL.getTypePtr();
4062 QualType OldClsType = QualType(T->getClass(), 0);
4063 QualType NewClsType;
4064 if (NewClsTInfo)
4065 NewClsType = NewClsTInfo->getType();
4066 else {
4067 NewClsType = getDerived().TransformType(OldClsType);
4068 if (NewClsType.isNull())
4069 return QualType();
4070 }
Mike Stump11289f42009-09-09 15:08:12 +00004071
John McCall550e0c22009-10-21 00:40:46 +00004072 QualType Result = TL.getType();
4073 if (getDerived().AlwaysRebuild() ||
4074 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004075 NewClsType != OldClsType) {
4076 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004077 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004078 if (Result.isNull())
4079 return QualType();
4080 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004081
Reid Kleckner0503a872013-12-05 01:23:43 +00004082 // If we had to adjust the pointee type when building a member pointer, make
4083 // sure to push TypeLoc info for it.
4084 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4085 if (MPT && PointeeType != MPT->getPointeeType()) {
4086 assert(isa<AdjustedType>(MPT->getPointeeType()));
4087 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4088 }
4089
John McCall550e0c22009-10-21 00:40:46 +00004090 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4091 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004092 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004093
4094 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004095}
4096
Mike Stump11289f42009-09-09 15:08:12 +00004097template<typename Derived>
4098QualType
John McCall550e0c22009-10-21 00:40:46 +00004099TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004100 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004101 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004102 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004103 if (ElementType.isNull())
4104 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004105
John McCall550e0c22009-10-21 00:40:46 +00004106 QualType Result = TL.getType();
4107 if (getDerived().AlwaysRebuild() ||
4108 ElementType != T->getElementType()) {
4109 Result = getDerived().RebuildConstantArrayType(ElementType,
4110 T->getSizeModifier(),
4111 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004112 T->getIndexTypeCVRQualifiers(),
4113 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004114 if (Result.isNull())
4115 return QualType();
4116 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004117
4118 // We might have either a ConstantArrayType or a VariableArrayType now:
4119 // a ConstantArrayType is allowed to have an element type which is a
4120 // VariableArrayType if the type is dependent. Fortunately, all array
4121 // types have the same location layout.
4122 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004123 NewTL.setLBracketLoc(TL.getLBracketLoc());
4124 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004125
John McCall550e0c22009-10-21 00:40:46 +00004126 Expr *Size = TL.getSizeExpr();
4127 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004128 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4129 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004130 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4131 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004132 }
4133 NewTL.setSizeExpr(Size);
4134
4135 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004136}
Mike Stump11289f42009-09-09 15:08:12 +00004137
Douglas Gregord6ff3322009-08-04 16:50:30 +00004138template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004139QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004140 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004141 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004142 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004143 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004144 if (ElementType.isNull())
4145 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004146
John McCall550e0c22009-10-21 00:40:46 +00004147 QualType Result = TL.getType();
4148 if (getDerived().AlwaysRebuild() ||
4149 ElementType != T->getElementType()) {
4150 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004151 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004152 T->getIndexTypeCVRQualifiers(),
4153 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004154 if (Result.isNull())
4155 return QualType();
4156 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004157
John McCall550e0c22009-10-21 00:40:46 +00004158 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4159 NewTL.setLBracketLoc(TL.getLBracketLoc());
4160 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004161 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004162
4163 return Result;
4164}
4165
4166template<typename Derived>
4167QualType
4168TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004169 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004170 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004171 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4172 if (ElementType.isNull())
4173 return QualType();
4174
John McCalldadc5752010-08-24 06:29:42 +00004175 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004176 = getDerived().TransformExpr(T->getSizeExpr());
4177 if (SizeResult.isInvalid())
4178 return QualType();
4179
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004180 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004181
4182 QualType Result = TL.getType();
4183 if (getDerived().AlwaysRebuild() ||
4184 ElementType != T->getElementType() ||
4185 Size != T->getSizeExpr()) {
4186 Result = getDerived().RebuildVariableArrayType(ElementType,
4187 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004188 Size,
John McCall550e0c22009-10-21 00:40:46 +00004189 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004190 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004191 if (Result.isNull())
4192 return QualType();
4193 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004194
Serge Pavlov774c6d02014-02-06 03:49:11 +00004195 // We might have constant size array now, but fortunately it has the same
4196 // location layout.
4197 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004198 NewTL.setLBracketLoc(TL.getLBracketLoc());
4199 NewTL.setRBracketLoc(TL.getRBracketLoc());
4200 NewTL.setSizeExpr(Size);
4201
4202 return Result;
4203}
4204
4205template<typename Derived>
4206QualType
4207TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004208 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004209 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004210 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4211 if (ElementType.isNull())
4212 return QualType();
4213
Richard Smith764d2fe2011-12-20 02:08:33 +00004214 // Array bounds are constant expressions.
4215 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4216 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004217
John McCall33ddac02011-01-19 10:06:00 +00004218 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4219 Expr *origSize = TL.getSizeExpr();
4220 if (!origSize) origSize = T->getSizeExpr();
4221
4222 ExprResult sizeResult
4223 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004224 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004225 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004226 return QualType();
4227
John McCall33ddac02011-01-19 10:06:00 +00004228 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004229
4230 QualType Result = TL.getType();
4231 if (getDerived().AlwaysRebuild() ||
4232 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004233 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004234 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4235 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004236 size,
John McCall550e0c22009-10-21 00:40:46 +00004237 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004238 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004239 if (Result.isNull())
4240 return QualType();
4241 }
John McCall550e0c22009-10-21 00:40:46 +00004242
4243 // We might have any sort of array type now, but fortunately they
4244 // all have the same location layout.
4245 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4246 NewTL.setLBracketLoc(TL.getLBracketLoc());
4247 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004248 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004249
4250 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004251}
Mike Stump11289f42009-09-09 15:08:12 +00004252
4253template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004254QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004255 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004256 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004257 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004258
4259 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004260 QualType ElementType = getDerived().TransformType(T->getElementType());
4261 if (ElementType.isNull())
4262 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004263
Richard Smith764d2fe2011-12-20 02:08:33 +00004264 // Vector sizes are constant expressions.
4265 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4266 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004267
John McCalldadc5752010-08-24 06:29:42 +00004268 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004269 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004270 if (Size.isInvalid())
4271 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004272
John McCall550e0c22009-10-21 00:40:46 +00004273 QualType Result = TL.getType();
4274 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004275 ElementType != T->getElementType() ||
4276 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004277 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004278 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004279 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004280 if (Result.isNull())
4281 return QualType();
4282 }
John McCall550e0c22009-10-21 00:40:46 +00004283
4284 // Result might be dependent or not.
4285 if (isa<DependentSizedExtVectorType>(Result)) {
4286 DependentSizedExtVectorTypeLoc NewTL
4287 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4288 NewTL.setNameLoc(TL.getNameLoc());
4289 } else {
4290 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4291 NewTL.setNameLoc(TL.getNameLoc());
4292 }
4293
4294 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004295}
Mike Stump11289f42009-09-09 15:08:12 +00004296
4297template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004298QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004299 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004300 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004301 QualType ElementType = getDerived().TransformType(T->getElementType());
4302 if (ElementType.isNull())
4303 return QualType();
4304
John McCall550e0c22009-10-21 00:40:46 +00004305 QualType Result = TL.getType();
4306 if (getDerived().AlwaysRebuild() ||
4307 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004308 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004309 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004310 if (Result.isNull())
4311 return QualType();
4312 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004313
John McCall550e0c22009-10-21 00:40:46 +00004314 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4315 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004316
John McCall550e0c22009-10-21 00:40:46 +00004317 return Result;
4318}
4319
4320template<typename Derived>
4321QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004322 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004323 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004324 QualType ElementType = getDerived().TransformType(T->getElementType());
4325 if (ElementType.isNull())
4326 return QualType();
4327
4328 QualType Result = TL.getType();
4329 if (getDerived().AlwaysRebuild() ||
4330 ElementType != T->getElementType()) {
4331 Result = getDerived().RebuildExtVectorType(ElementType,
4332 T->getNumElements(),
4333 /*FIXME*/ SourceLocation());
4334 if (Result.isNull())
4335 return QualType();
4336 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004337
John McCall550e0c22009-10-21 00:40:46 +00004338 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4339 NewTL.setNameLoc(TL.getNameLoc());
4340
4341 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004342}
Mike Stump11289f42009-09-09 15:08:12 +00004343
David Blaikie05785d12013-02-20 22:23:23 +00004344template <typename Derived>
4345ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4346 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4347 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004348 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004349 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004350
Douglas Gregor715e4612011-01-14 22:40:04 +00004351 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004352 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004353 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004354 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004355 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004356
Douglas Gregor715e4612011-01-14 22:40:04 +00004357 TypeLocBuilder TLB;
4358 TypeLoc NewTL = OldDI->getTypeLoc();
4359 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004360
4361 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004362 OldExpansionTL.getPatternLoc());
4363 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004364 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004365
4366 Result = RebuildPackExpansionType(Result,
4367 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004368 OldExpansionTL.getEllipsisLoc(),
4369 NumExpansions);
4370 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004371 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004372
Douglas Gregor715e4612011-01-14 22:40:04 +00004373 PackExpansionTypeLoc NewExpansionTL
4374 = TLB.push<PackExpansionTypeLoc>(Result);
4375 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4376 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4377 } else
4378 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004379 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004380 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004381
John McCall8fb0d9d2011-05-01 22:35:37 +00004382 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004383 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004384
4385 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4386 OldParm->getDeclContext(),
4387 OldParm->getInnerLocStart(),
4388 OldParm->getLocation(),
4389 OldParm->getIdentifier(),
4390 NewDI->getType(),
4391 NewDI,
4392 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004393 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004394 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4395 OldParm->getFunctionScopeIndex() + indexAdjustment);
4396 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004397}
4398
4399template<typename Derived>
4400bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004401 TransformFunctionTypeParams(SourceLocation Loc,
4402 ParmVarDecl **Params, unsigned NumParams,
4403 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004404 SmallVectorImpl<QualType> &OutParamTypes,
4405 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004406 int indexAdjustment = 0;
4407
Douglas Gregordd472162011-01-07 00:20:55 +00004408 for (unsigned i = 0; i != NumParams; ++i) {
4409 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004410 assert(OldParm->getFunctionScopeIndex() == i);
4411
David Blaikie05785d12013-02-20 22:23:23 +00004412 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004413 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004414 if (OldParm->isParameterPack()) {
4415 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004416 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004417
Douglas Gregor5499af42011-01-05 23:12:31 +00004418 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004419 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004420 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004421 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4422 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004423 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4424
Douglas Gregor5499af42011-01-05 23:12:31 +00004425 // Determine whether we should expand the parameter packs.
4426 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004427 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004428 Optional<unsigned> OrigNumExpansions =
4429 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004430 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004431 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4432 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004433 Unexpanded,
4434 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004435 RetainExpansion,
4436 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004437 return true;
4438 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004439
Douglas Gregor5499af42011-01-05 23:12:31 +00004440 if (ShouldExpand) {
4441 // Expand the function parameter pack into multiple, separate
4442 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004443 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004444 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004445 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004446 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004447 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004448 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004449 OrigNumExpansions,
4450 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004451 if (!NewParm)
4452 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004453
Douglas Gregordd472162011-01-07 00:20:55 +00004454 OutParamTypes.push_back(NewParm->getType());
4455 if (PVars)
4456 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004457 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004458
4459 // If we're supposed to retain a pack expansion, do so by temporarily
4460 // forgetting the partially-substituted parameter pack.
4461 if (RetainExpansion) {
4462 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004463 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004464 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004465 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004466 OrigNumExpansions,
4467 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004468 if (!NewParm)
4469 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004470
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004471 OutParamTypes.push_back(NewParm->getType());
4472 if (PVars)
4473 PVars->push_back(NewParm);
4474 }
4475
John McCall8fb0d9d2011-05-01 22:35:37 +00004476 // The next parameter should have the same adjustment as the
4477 // last thing we pushed, but we post-incremented indexAdjustment
4478 // on every push. Also, if we push nothing, the adjustment should
4479 // go down by one.
4480 indexAdjustment--;
4481
Douglas Gregor5499af42011-01-05 23:12:31 +00004482 // We're done with the pack expansion.
4483 continue;
4484 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004485
4486 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004487 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004488 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4489 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004490 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004491 NumExpansions,
4492 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004493 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004494 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004495 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004496 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004497
John McCall58f10c32010-03-11 09:03:00 +00004498 if (!NewParm)
4499 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004500
Douglas Gregordd472162011-01-07 00:20:55 +00004501 OutParamTypes.push_back(NewParm->getType());
4502 if (PVars)
4503 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004504 continue;
4505 }
John McCall58f10c32010-03-11 09:03:00 +00004506
4507 // Deal with the possibility that we don't have a parameter
4508 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004509 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004510 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004511 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004512 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004513 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004514 = dyn_cast<PackExpansionType>(OldType)) {
4515 // We have a function parameter pack that may need to be expanded.
4516 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004517 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004518 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004519
Douglas Gregor5499af42011-01-05 23:12:31 +00004520 // Determine whether we should expand the parameter packs.
4521 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004522 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004523 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004524 Unexpanded,
4525 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004526 RetainExpansion,
4527 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004528 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004529 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004530
Douglas Gregor5499af42011-01-05 23:12:31 +00004531 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004532 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004533 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004534 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004535 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4536 QualType NewType = getDerived().TransformType(Pattern);
4537 if (NewType.isNull())
4538 return true;
John McCall58f10c32010-03-11 09:03:00 +00004539
Douglas Gregordd472162011-01-07 00:20:55 +00004540 OutParamTypes.push_back(NewType);
4541 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004542 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004543 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004544
Douglas Gregor5499af42011-01-05 23:12:31 +00004545 // We're done with the pack expansion.
4546 continue;
4547 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004548
Douglas Gregor48d24112011-01-10 20:53:55 +00004549 // If we're supposed to retain a pack expansion, do so by temporarily
4550 // forgetting the partially-substituted parameter pack.
4551 if (RetainExpansion) {
4552 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4553 QualType NewType = getDerived().TransformType(Pattern);
4554 if (NewType.isNull())
4555 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004556
Douglas Gregor48d24112011-01-10 20:53:55 +00004557 OutParamTypes.push_back(NewType);
4558 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004559 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004560 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004561
Chad Rosier1dcde962012-08-08 18:46:20 +00004562 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004563 // expansion.
4564 OldType = Expansion->getPattern();
4565 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004566 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4567 NewType = getDerived().TransformType(OldType);
4568 } else {
4569 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004570 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004571
Douglas Gregor5499af42011-01-05 23:12:31 +00004572 if (NewType.isNull())
4573 return true;
4574
4575 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004576 NewType = getSema().Context.getPackExpansionType(NewType,
4577 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004578
Douglas Gregordd472162011-01-07 00:20:55 +00004579 OutParamTypes.push_back(NewType);
4580 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004581 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004582 }
4583
John McCall8fb0d9d2011-05-01 22:35:37 +00004584#ifndef NDEBUG
4585 if (PVars) {
4586 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4587 if (ParmVarDecl *parm = (*PVars)[i])
4588 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004589 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004590#endif
4591
4592 return false;
4593}
John McCall58f10c32010-03-11 09:03:00 +00004594
4595template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004596QualType
John McCall550e0c22009-10-21 00:40:46 +00004597TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004598 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004599 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004600 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004601 return getDerived().TransformFunctionProtoType(
4602 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004603 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4604 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4605 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004606 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004607}
4608
Richard Smith2e321552014-11-12 02:00:47 +00004609template<typename Derived> template<typename Fn>
4610QualType TreeTransform<Derived>::TransformFunctionProtoType(
4611 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4612 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004613 // Transform the parameters and return type.
4614 //
Richard Smithf623c962012-04-17 00:58:00 +00004615 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004616 // When the function has a trailing return type, we instantiate the
4617 // parameters before the return type, since the return type can then refer
4618 // to the parameters themselves (via decltype, sizeof, etc.).
4619 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004620 SmallVector<QualType, 4> ParamTypes;
4621 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004622 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004623
Douglas Gregor7fb25412010-10-01 18:44:50 +00004624 QualType ResultType;
4625
Richard Smith1226c602012-08-14 22:51:13 +00004626 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004627 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004628 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004629 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004630 return QualType();
4631
Douglas Gregor3024f072012-04-16 07:05:22 +00004632 {
4633 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004634 // If a declaration declares a member function or member function
4635 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004636 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004637 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004638 // declarator.
4639 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004640
Alp Toker42a16a62014-01-25 23:51:36 +00004641 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004642 if (ResultType.isNull())
4643 return QualType();
4644 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004645 }
4646 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004647 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004648 if (ResultType.isNull())
4649 return QualType();
4650
Alp Toker9cacbab2014-01-20 20:26:09 +00004651 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004652 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004653 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004654 return QualType();
4655 }
4656
Richard Smith2e321552014-11-12 02:00:47 +00004657 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4658
4659 bool EPIChanged = false;
4660 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4661 return QualType();
4662
4663 // FIXME: Need to transform ConsumedParameters for variadic template
4664 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004665
John McCall550e0c22009-10-21 00:40:46 +00004666 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004667 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004668 T->getNumParams() != ParamTypes.size() ||
4669 !std::equal(T->param_type_begin(), T->param_type_end(),
Richard Smith2e321552014-11-12 02:00:47 +00004670 ParamTypes.begin()) || EPIChanged) {
4671 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004672 if (Result.isNull())
4673 return QualType();
4674 }
Mike Stump11289f42009-09-09 15:08:12 +00004675
John McCall550e0c22009-10-21 00:40:46 +00004676 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004677 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004678 NewTL.setLParenLoc(TL.getLParenLoc());
4679 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004680 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004681 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4682 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004683
4684 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004685}
Mike Stump11289f42009-09-09 15:08:12 +00004686
Douglas Gregord6ff3322009-08-04 16:50:30 +00004687template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004688bool TreeTransform<Derived>::TransformExceptionSpec(
4689 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4690 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4691 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4692
4693 // Instantiate a dynamic noexcept expression, if any.
4694 if (ESI.Type == EST_ComputedNoexcept) {
4695 EnterExpressionEvaluationContext Unevaluated(getSema(),
4696 Sema::ConstantEvaluated);
4697 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4698 if (NoexceptExpr.isInvalid())
4699 return true;
4700
4701 NoexceptExpr = getSema().CheckBooleanCondition(
4702 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4703 if (NoexceptExpr.isInvalid())
4704 return true;
4705
4706 if (!NoexceptExpr.get()->isValueDependent()) {
4707 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4708 NoexceptExpr.get(), nullptr,
4709 diag::err_noexcept_needs_constant_expression,
4710 /*AllowFold*/false);
4711 if (NoexceptExpr.isInvalid())
4712 return true;
4713 }
4714
4715 if (ESI.NoexceptExpr != NoexceptExpr.get())
4716 Changed = true;
4717 ESI.NoexceptExpr = NoexceptExpr.get();
4718 }
4719
4720 if (ESI.Type != EST_Dynamic)
4721 return false;
4722
4723 // Instantiate a dynamic exception specification's type.
4724 for (QualType T : ESI.Exceptions) {
4725 if (const PackExpansionType *PackExpansion =
4726 T->getAs<PackExpansionType>()) {
4727 Changed = true;
4728
4729 // We have a pack expansion. Instantiate it.
4730 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4731 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4732 Unexpanded);
4733 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4734
4735 // Determine whether the set of unexpanded parameter packs can and
4736 // should
4737 // be expanded.
4738 bool Expand = false;
4739 bool RetainExpansion = false;
4740 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4741 // FIXME: Track the location of the ellipsis (and track source location
4742 // information for the types in the exception specification in general).
4743 if (getDerived().TryExpandParameterPacks(
4744 Loc, SourceRange(), Unexpanded, Expand,
4745 RetainExpansion, NumExpansions))
4746 return true;
4747
4748 if (!Expand) {
4749 // We can't expand this pack expansion into separate arguments yet;
4750 // just substitute into the pattern and create a new pack expansion
4751 // type.
4752 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4753 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4754 if (U.isNull())
4755 return true;
4756
4757 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4758 Exceptions.push_back(U);
4759 continue;
4760 }
4761
4762 // Substitute into the pack expansion pattern for each slice of the
4763 // pack.
4764 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4765 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4766
4767 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4768 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4769 return true;
4770
4771 Exceptions.push_back(U);
4772 }
4773 } else {
4774 QualType U = getDerived().TransformType(T);
4775 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4776 return true;
4777 if (T != U)
4778 Changed = true;
4779
4780 Exceptions.push_back(U);
4781 }
4782 }
4783
4784 ESI.Exceptions = Exceptions;
4785 return false;
4786}
4787
4788template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004789QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004790 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004791 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004792 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004793 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004794 if (ResultType.isNull())
4795 return QualType();
4796
4797 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004798 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004799 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4800
4801 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004802 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004803 NewTL.setLParenLoc(TL.getLParenLoc());
4804 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004805 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004806
4807 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004808}
Mike Stump11289f42009-09-09 15:08:12 +00004809
John McCallb96ec562009-12-04 22:46:56 +00004810template<typename Derived> QualType
4811TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004812 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004813 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004814 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004815 if (!D)
4816 return QualType();
4817
4818 QualType Result = TL.getType();
4819 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4820 Result = getDerived().RebuildUnresolvedUsingType(D);
4821 if (Result.isNull())
4822 return QualType();
4823 }
4824
4825 // We might get an arbitrary type spec type back. We should at
4826 // least always get a type spec type, though.
4827 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4828 NewTL.setNameLoc(TL.getNameLoc());
4829
4830 return Result;
4831}
4832
Douglas Gregord6ff3322009-08-04 16:50:30 +00004833template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004834QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004835 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004836 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004837 TypedefNameDecl *Typedef
4838 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4839 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004840 if (!Typedef)
4841 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004842
John McCall550e0c22009-10-21 00:40:46 +00004843 QualType Result = TL.getType();
4844 if (getDerived().AlwaysRebuild() ||
4845 Typedef != T->getDecl()) {
4846 Result = getDerived().RebuildTypedefType(Typedef);
4847 if (Result.isNull())
4848 return QualType();
4849 }
Mike Stump11289f42009-09-09 15:08:12 +00004850
John McCall550e0c22009-10-21 00:40:46 +00004851 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4852 NewTL.setNameLoc(TL.getNameLoc());
4853
4854 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004855}
Mike Stump11289f42009-09-09 15:08:12 +00004856
Douglas Gregord6ff3322009-08-04 16:50:30 +00004857template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004858QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004859 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004860 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004861 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4862 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004863
John McCalldadc5752010-08-24 06:29:42 +00004864 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004865 if (E.isInvalid())
4866 return QualType();
4867
Eli Friedmane4f22df2012-02-29 04:03:55 +00004868 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4869 if (E.isInvalid())
4870 return QualType();
4871
John McCall550e0c22009-10-21 00:40:46 +00004872 QualType Result = TL.getType();
4873 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004874 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004875 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004876 if (Result.isNull())
4877 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004878 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004879 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004880
John McCall550e0c22009-10-21 00:40:46 +00004881 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004882 NewTL.setTypeofLoc(TL.getTypeofLoc());
4883 NewTL.setLParenLoc(TL.getLParenLoc());
4884 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004885
4886 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004887}
Mike Stump11289f42009-09-09 15:08:12 +00004888
4889template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004890QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004891 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004892 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4893 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4894 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004895 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004896
John McCall550e0c22009-10-21 00:40:46 +00004897 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004898 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4899 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004900 if (Result.isNull())
4901 return QualType();
4902 }
Mike Stump11289f42009-09-09 15:08:12 +00004903
John McCall550e0c22009-10-21 00:40:46 +00004904 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004905 NewTL.setTypeofLoc(TL.getTypeofLoc());
4906 NewTL.setLParenLoc(TL.getLParenLoc());
4907 NewTL.setRParenLoc(TL.getRParenLoc());
4908 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004909
4910 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004911}
Mike Stump11289f42009-09-09 15:08:12 +00004912
4913template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004914QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004915 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004916 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004917
Douglas Gregore922c772009-08-04 22:27:00 +00004918 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004919 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4920 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004921
John McCalldadc5752010-08-24 06:29:42 +00004922 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004923 if (E.isInvalid())
4924 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004925
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004926 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004927 if (E.isInvalid())
4928 return QualType();
4929
John McCall550e0c22009-10-21 00:40:46 +00004930 QualType Result = TL.getType();
4931 if (getDerived().AlwaysRebuild() ||
4932 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004933 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004934 if (Result.isNull())
4935 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004936 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004937 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004938
John McCall550e0c22009-10-21 00:40:46 +00004939 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4940 NewTL.setNameLoc(TL.getNameLoc());
4941
4942 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004943}
4944
4945template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004946QualType TreeTransform<Derived>::TransformUnaryTransformType(
4947 TypeLocBuilder &TLB,
4948 UnaryTransformTypeLoc TL) {
4949 QualType Result = TL.getType();
4950 if (Result->isDependentType()) {
4951 const UnaryTransformType *T = TL.getTypePtr();
4952 QualType NewBase =
4953 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4954 Result = getDerived().RebuildUnaryTransformType(NewBase,
4955 T->getUTTKind(),
4956 TL.getKWLoc());
4957 if (Result.isNull())
4958 return QualType();
4959 }
4960
4961 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4962 NewTL.setKWLoc(TL.getKWLoc());
4963 NewTL.setParensRange(TL.getParensRange());
4964 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4965 return Result;
4966}
4967
4968template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004969QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4970 AutoTypeLoc TL) {
4971 const AutoType *T = TL.getTypePtr();
4972 QualType OldDeduced = T->getDeducedType();
4973 QualType NewDeduced;
4974 if (!OldDeduced.isNull()) {
4975 NewDeduced = getDerived().TransformType(OldDeduced);
4976 if (NewDeduced.isNull())
4977 return QualType();
4978 }
4979
4980 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004981 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4982 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004983 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004984 if (Result.isNull())
4985 return QualType();
4986 }
4987
4988 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4989 NewTL.setNameLoc(TL.getNameLoc());
4990
4991 return Result;
4992}
4993
4994template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004995QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004996 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004997 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004998 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004999 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5000 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005001 if (!Record)
5002 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005003
John McCall550e0c22009-10-21 00:40:46 +00005004 QualType Result = TL.getType();
5005 if (getDerived().AlwaysRebuild() ||
5006 Record != T->getDecl()) {
5007 Result = getDerived().RebuildRecordType(Record);
5008 if (Result.isNull())
5009 return QualType();
5010 }
Mike Stump11289f42009-09-09 15:08:12 +00005011
John McCall550e0c22009-10-21 00:40:46 +00005012 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5013 NewTL.setNameLoc(TL.getNameLoc());
5014
5015 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005016}
Mike Stump11289f42009-09-09 15:08:12 +00005017
5018template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005019QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005020 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005021 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005022 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005023 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5024 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005025 if (!Enum)
5026 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005027
John McCall550e0c22009-10-21 00:40:46 +00005028 QualType Result = TL.getType();
5029 if (getDerived().AlwaysRebuild() ||
5030 Enum != T->getDecl()) {
5031 Result = getDerived().RebuildEnumType(Enum);
5032 if (Result.isNull())
5033 return QualType();
5034 }
Mike Stump11289f42009-09-09 15:08:12 +00005035
John McCall550e0c22009-10-21 00:40:46 +00005036 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5037 NewTL.setNameLoc(TL.getNameLoc());
5038
5039 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005040}
John McCallfcc33b02009-09-05 00:15:47 +00005041
John McCalle78aac42010-03-10 03:28:59 +00005042template<typename Derived>
5043QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5044 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005045 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005046 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5047 TL.getTypePtr()->getDecl());
5048 if (!D) return QualType();
5049
5050 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5051 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5052 return T;
5053}
5054
Douglas Gregord6ff3322009-08-04 16:50:30 +00005055template<typename Derived>
5056QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005057 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005058 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005059 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005060}
5061
Mike Stump11289f42009-09-09 15:08:12 +00005062template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005063QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005064 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005065 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005066 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005067
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005068 // Substitute into the replacement type, which itself might involve something
5069 // that needs to be transformed. This only tends to occur with default
5070 // template arguments of template template parameters.
5071 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5072 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5073 if (Replacement.isNull())
5074 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005075
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005076 // Always canonicalize the replacement type.
5077 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5078 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005079 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005080 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005081
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005082 // Propagate type-source information.
5083 SubstTemplateTypeParmTypeLoc NewTL
5084 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5085 NewTL.setNameLoc(TL.getNameLoc());
5086 return Result;
5087
John McCallcebee162009-10-18 09:09:24 +00005088}
5089
5090template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005091QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5092 TypeLocBuilder &TLB,
5093 SubstTemplateTypeParmPackTypeLoc TL) {
5094 return TransformTypeSpecType(TLB, TL);
5095}
5096
5097template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005098QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005099 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005100 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005101 const TemplateSpecializationType *T = TL.getTypePtr();
5102
Douglas Gregordf846d12011-03-02 18:46:51 +00005103 // The nested-name-specifier never matters in a TemplateSpecializationType,
5104 // because we can't have a dependent nested-name-specifier anyway.
5105 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005106 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005107 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5108 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005109 if (Template.isNull())
5110 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005111
John McCall31f82722010-11-12 08:19:04 +00005112 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5113}
5114
Eli Friedman0dfb8892011-10-06 23:00:33 +00005115template<typename Derived>
5116QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5117 AtomicTypeLoc TL) {
5118 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5119 if (ValueType.isNull())
5120 return QualType();
5121
5122 QualType Result = TL.getType();
5123 if (getDerived().AlwaysRebuild() ||
5124 ValueType != TL.getValueLoc().getType()) {
5125 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5126 if (Result.isNull())
5127 return QualType();
5128 }
5129
5130 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5131 NewTL.setKWLoc(TL.getKWLoc());
5132 NewTL.setLParenLoc(TL.getLParenLoc());
5133 NewTL.setRParenLoc(TL.getRParenLoc());
5134
5135 return Result;
5136}
5137
Chad Rosier1dcde962012-08-08 18:46:20 +00005138 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005139 /// container that provides a \c getArgLoc() member function.
5140 ///
5141 /// This iterator is intended to be used with the iterator form of
5142 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5143 template<typename ArgLocContainer>
5144 class TemplateArgumentLocContainerIterator {
5145 ArgLocContainer *Container;
5146 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005147
Douglas Gregorfe921a72010-12-20 23:36:19 +00005148 public:
5149 typedef TemplateArgumentLoc value_type;
5150 typedef TemplateArgumentLoc reference;
5151 typedef int difference_type;
5152 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005153
Douglas Gregorfe921a72010-12-20 23:36:19 +00005154 class pointer {
5155 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005156
Douglas Gregorfe921a72010-12-20 23:36:19 +00005157 public:
5158 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005159
Douglas Gregorfe921a72010-12-20 23:36:19 +00005160 const TemplateArgumentLoc *operator->() const {
5161 return &Arg;
5162 }
5163 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005164
5165
Douglas Gregorfe921a72010-12-20 23:36:19 +00005166 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005167
Douglas Gregorfe921a72010-12-20 23:36:19 +00005168 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5169 unsigned Index)
5170 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005171
Douglas Gregorfe921a72010-12-20 23:36:19 +00005172 TemplateArgumentLocContainerIterator &operator++() {
5173 ++Index;
5174 return *this;
5175 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005176
Douglas Gregorfe921a72010-12-20 23:36:19 +00005177 TemplateArgumentLocContainerIterator operator++(int) {
5178 TemplateArgumentLocContainerIterator Old(*this);
5179 ++(*this);
5180 return Old;
5181 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005182
Douglas Gregorfe921a72010-12-20 23:36:19 +00005183 TemplateArgumentLoc operator*() const {
5184 return Container->getArgLoc(Index);
5185 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005186
Douglas Gregorfe921a72010-12-20 23:36:19 +00005187 pointer operator->() const {
5188 return pointer(Container->getArgLoc(Index));
5189 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005190
Douglas Gregorfe921a72010-12-20 23:36:19 +00005191 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005192 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005193 return X.Container == Y.Container && X.Index == Y.Index;
5194 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005195
Douglas Gregorfe921a72010-12-20 23:36:19 +00005196 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005197 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005198 return !(X == Y);
5199 }
5200 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005201
5202
John McCall31f82722010-11-12 08:19:04 +00005203template <typename Derived>
5204QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5205 TypeLocBuilder &TLB,
5206 TemplateSpecializationTypeLoc TL,
5207 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005208 TemplateArgumentListInfo NewTemplateArgs;
5209 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5210 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005211 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5212 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005213 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005214 ArgIterator(TL, TL.getNumArgs()),
5215 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005216 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005217
John McCall0ad16662009-10-29 08:12:44 +00005218 // FIXME: maybe don't rebuild if all the template arguments are the same.
5219
5220 QualType Result =
5221 getDerived().RebuildTemplateSpecializationType(Template,
5222 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005223 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005224
5225 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005226 // Specializations of template template parameters are represented as
5227 // TemplateSpecializationTypes, and substitution of type alias templates
5228 // within a dependent context can transform them into
5229 // DependentTemplateSpecializationTypes.
5230 if (isa<DependentTemplateSpecializationType>(Result)) {
5231 DependentTemplateSpecializationTypeLoc NewTL
5232 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005233 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005234 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005235 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005236 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005237 NewTL.setLAngleLoc(TL.getLAngleLoc());
5238 NewTL.setRAngleLoc(TL.getRAngleLoc());
5239 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5240 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5241 return Result;
5242 }
5243
John McCall0ad16662009-10-29 08:12:44 +00005244 TemplateSpecializationTypeLoc NewTL
5245 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005246 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005247 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5248 NewTL.setLAngleLoc(TL.getLAngleLoc());
5249 NewTL.setRAngleLoc(TL.getRAngleLoc());
5250 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5251 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005252 }
Mike Stump11289f42009-09-09 15:08:12 +00005253
John McCall0ad16662009-10-29 08:12:44 +00005254 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005255}
Mike Stump11289f42009-09-09 15:08:12 +00005256
Douglas Gregor5a064722011-02-28 17:23:35 +00005257template <typename Derived>
5258QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5259 TypeLocBuilder &TLB,
5260 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005261 TemplateName Template,
5262 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005263 TemplateArgumentListInfo NewTemplateArgs;
5264 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5265 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5266 typedef TemplateArgumentLocContainerIterator<
5267 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005268 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005269 ArgIterator(TL, TL.getNumArgs()),
5270 NewTemplateArgs))
5271 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005272
Douglas Gregor5a064722011-02-28 17:23:35 +00005273 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005274
Douglas Gregor5a064722011-02-28 17:23:35 +00005275 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5276 QualType Result
5277 = getSema().Context.getDependentTemplateSpecializationType(
5278 TL.getTypePtr()->getKeyword(),
5279 DTN->getQualifier(),
5280 DTN->getIdentifier(),
5281 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005282
Douglas Gregor5a064722011-02-28 17:23:35 +00005283 DependentTemplateSpecializationTypeLoc NewTL
5284 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005285 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005286 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005287 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005288 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005289 NewTL.setLAngleLoc(TL.getLAngleLoc());
5290 NewTL.setRAngleLoc(TL.getRAngleLoc());
5291 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5292 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5293 return Result;
5294 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005295
5296 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005297 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005298 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005299 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005300
Douglas Gregor5a064722011-02-28 17:23:35 +00005301 if (!Result.isNull()) {
5302 /// FIXME: Wrap this in an elaborated-type-specifier?
5303 TemplateSpecializationTypeLoc NewTL
5304 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005305 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005306 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005307 NewTL.setLAngleLoc(TL.getLAngleLoc());
5308 NewTL.setRAngleLoc(TL.getRAngleLoc());
5309 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5310 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5311 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005312
Douglas Gregor5a064722011-02-28 17:23:35 +00005313 return Result;
5314}
5315
Mike Stump11289f42009-09-09 15:08:12 +00005316template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005317QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005318TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005319 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005320 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005321
Douglas Gregor844cb502011-03-01 18:12:44 +00005322 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005323 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005324 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005325 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005326 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5327 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005328 return QualType();
5329 }
Mike Stump11289f42009-09-09 15:08:12 +00005330
John McCall31f82722010-11-12 08:19:04 +00005331 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5332 if (NamedT.isNull())
5333 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005334
Richard Smith3f1b5d02011-05-05 21:57:07 +00005335 // C++0x [dcl.type.elab]p2:
5336 // If the identifier resolves to a typedef-name or the simple-template-id
5337 // resolves to an alias template specialization, the
5338 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005339 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5340 if (const TemplateSpecializationType *TST =
5341 NamedT->getAs<TemplateSpecializationType>()) {
5342 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005343 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5344 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005345 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5346 diag::err_tag_reference_non_tag) << 4;
5347 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5348 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005349 }
5350 }
5351
John McCall550e0c22009-10-21 00:40:46 +00005352 QualType Result = TL.getType();
5353 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005354 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005355 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005356 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005357 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005358 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005359 if (Result.isNull())
5360 return QualType();
5361 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005362
Abramo Bagnara6150c882010-05-11 21:36:43 +00005363 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005364 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005365 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005366 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005367}
Mike Stump11289f42009-09-09 15:08:12 +00005368
5369template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005370QualType TreeTransform<Derived>::TransformAttributedType(
5371 TypeLocBuilder &TLB,
5372 AttributedTypeLoc TL) {
5373 const AttributedType *oldType = TL.getTypePtr();
5374 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5375 if (modifiedType.isNull())
5376 return QualType();
5377
5378 QualType result = TL.getType();
5379
5380 // FIXME: dependent operand expressions?
5381 if (getDerived().AlwaysRebuild() ||
5382 modifiedType != oldType->getModifiedType()) {
5383 // TODO: this is really lame; we should really be rebuilding the
5384 // equivalent type from first principles.
5385 QualType equivalentType
5386 = getDerived().TransformType(oldType->getEquivalentType());
5387 if (equivalentType.isNull())
5388 return QualType();
5389 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5390 modifiedType,
5391 equivalentType);
5392 }
5393
5394 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5395 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5396 if (TL.hasAttrOperand())
5397 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5398 if (TL.hasAttrExprOperand())
5399 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5400 else if (TL.hasAttrEnumOperand())
5401 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5402
5403 return result;
5404}
5405
5406template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005407QualType
5408TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5409 ParenTypeLoc TL) {
5410 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5411 if (Inner.isNull())
5412 return QualType();
5413
5414 QualType Result = TL.getType();
5415 if (getDerived().AlwaysRebuild() ||
5416 Inner != TL.getInnerLoc().getType()) {
5417 Result = getDerived().RebuildParenType(Inner);
5418 if (Result.isNull())
5419 return QualType();
5420 }
5421
5422 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5423 NewTL.setLParenLoc(TL.getLParenLoc());
5424 NewTL.setRParenLoc(TL.getRParenLoc());
5425 return Result;
5426}
5427
5428template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005429QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005430 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005431 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005432
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005433 NestedNameSpecifierLoc QualifierLoc
5434 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5435 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005436 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005437
John McCallc392f372010-06-11 00:33:02 +00005438 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005439 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005440 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005441 QualifierLoc,
5442 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005443 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005444 if (Result.isNull())
5445 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005446
Abramo Bagnarad7548482010-05-19 21:37:53 +00005447 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5448 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005449 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5450
Abramo Bagnarad7548482010-05-19 21:37:53 +00005451 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005452 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005453 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005454 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005455 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005456 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005457 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005458 NewTL.setNameLoc(TL.getNameLoc());
5459 }
John McCall550e0c22009-10-21 00:40:46 +00005460 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005461}
Mike Stump11289f42009-09-09 15:08:12 +00005462
Douglas Gregord6ff3322009-08-04 16:50:30 +00005463template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005464QualType TreeTransform<Derived>::
5465 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005466 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005467 NestedNameSpecifierLoc QualifierLoc;
5468 if (TL.getQualifierLoc()) {
5469 QualifierLoc
5470 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5471 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005472 return QualType();
5473 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005474
John McCall31f82722010-11-12 08:19:04 +00005475 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005476 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005477}
5478
5479template<typename Derived>
5480QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005481TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5482 DependentTemplateSpecializationTypeLoc TL,
5483 NestedNameSpecifierLoc QualifierLoc) {
5484 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005485
Douglas Gregora7a795b2011-03-01 20:11:18 +00005486 TemplateArgumentListInfo NewTemplateArgs;
5487 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5488 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005489
Douglas Gregora7a795b2011-03-01 20:11:18 +00005490 typedef TemplateArgumentLocContainerIterator<
5491 DependentTemplateSpecializationTypeLoc> ArgIterator;
5492 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5493 ArgIterator(TL, TL.getNumArgs()),
5494 NewTemplateArgs))
5495 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005496
Douglas Gregora7a795b2011-03-01 20:11:18 +00005497 QualType Result
5498 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5499 QualifierLoc,
5500 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005501 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005502 NewTemplateArgs);
5503 if (Result.isNull())
5504 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005505
Douglas Gregora7a795b2011-03-01 20:11:18 +00005506 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5507 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005508
Douglas Gregora7a795b2011-03-01 20:11:18 +00005509 // Copy information relevant to the template specialization.
5510 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005511 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005512 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005513 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005514 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5515 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005516 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005517 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005518
Douglas Gregora7a795b2011-03-01 20:11:18 +00005519 // Copy information relevant to the elaborated type.
5520 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005521 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005522 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005523 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5524 DependentTemplateSpecializationTypeLoc SpecTL
5525 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005526 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005527 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005528 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005529 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005530 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5531 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005532 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005533 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005534 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005535 TemplateSpecializationTypeLoc SpecTL
5536 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005537 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005538 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005539 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5540 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005541 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005542 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005543 }
5544 return Result;
5545}
5546
5547template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005548QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5549 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005550 QualType Pattern
5551 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005552 if (Pattern.isNull())
5553 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005554
5555 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005556 if (getDerived().AlwaysRebuild() ||
5557 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005558 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005559 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005560 TL.getEllipsisLoc(),
5561 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005562 if (Result.isNull())
5563 return QualType();
5564 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005565
Douglas Gregor822d0302011-01-12 17:07:58 +00005566 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5567 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5568 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005569}
5570
5571template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005572QualType
5573TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005574 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005575 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005576 TLB.pushFullCopy(TL);
5577 return TL.getType();
5578}
5579
5580template<typename Derived>
5581QualType
5582TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005583 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005584 // ObjCObjectType is never dependent.
5585 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005586 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005587}
Mike Stump11289f42009-09-09 15:08:12 +00005588
5589template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005590QualType
5591TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005592 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005593 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005594 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005595 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005596}
5597
Douglas Gregord6ff3322009-08-04 16:50:30 +00005598//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005599// Statement transformation
5600//===----------------------------------------------------------------------===//
5601template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005602StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005603TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005604 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005605}
5606
5607template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005608StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005609TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5610 return getDerived().TransformCompoundStmt(S, false);
5611}
5612
5613template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005614StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005615TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005616 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005617 Sema::CompoundScopeRAII CompoundScope(getSema());
5618
John McCall1ababa62010-08-27 19:56:05 +00005619 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005620 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005621 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005622 for (auto *B : S->body()) {
5623 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005624 if (Result.isInvalid()) {
5625 // Immediately fail if this was a DeclStmt, since it's very
5626 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005627 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005628 return StmtError();
5629
5630 // Otherwise, just keep processing substatements and fail later.
5631 SubStmtInvalid = true;
5632 continue;
5633 }
Mike Stump11289f42009-09-09 15:08:12 +00005634
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005635 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005636 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005637 }
Mike Stump11289f42009-09-09 15:08:12 +00005638
John McCall1ababa62010-08-27 19:56:05 +00005639 if (SubStmtInvalid)
5640 return StmtError();
5641
Douglas Gregorebe10102009-08-20 07:17:43 +00005642 if (!getDerived().AlwaysRebuild() &&
5643 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005644 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005645
5646 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005647 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005648 S->getRBracLoc(),
5649 IsStmtExpr);
5650}
Mike Stump11289f42009-09-09 15:08:12 +00005651
Douglas Gregorebe10102009-08-20 07:17:43 +00005652template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005653StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005654TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005655 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005656 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005657 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5658 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005659
Eli Friedman06577382009-11-19 03:14:00 +00005660 // Transform the left-hand case value.
5661 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005662 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005663 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005664 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005665
Eli Friedman06577382009-11-19 03:14:00 +00005666 // Transform the right-hand case value (for the GNU case-range extension).
5667 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005668 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005669 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005670 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005671 }
Mike Stump11289f42009-09-09 15:08:12 +00005672
Douglas Gregorebe10102009-08-20 07:17:43 +00005673 // Build the case statement.
5674 // Case statements are always rebuilt so that they will attached to their
5675 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005676 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005677 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005678 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005679 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005680 S->getColonLoc());
5681 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005682 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005683
Douglas Gregorebe10102009-08-20 07:17:43 +00005684 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005685 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005686 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005687 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005688
Douglas Gregorebe10102009-08-20 07:17:43 +00005689 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005690 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005691}
5692
5693template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005694StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005695TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005696 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005697 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005698 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005699 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005700
Douglas Gregorebe10102009-08-20 07:17:43 +00005701 // Default statements are always rebuilt
5702 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005703 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005704}
Mike Stump11289f42009-09-09 15:08:12 +00005705
Douglas Gregorebe10102009-08-20 07:17:43 +00005706template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005707StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005708TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005709 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005710 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005711 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005712
Chris Lattnercab02a62011-02-17 20:34:02 +00005713 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5714 S->getDecl());
5715 if (!LD)
5716 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005717
5718
Douglas Gregorebe10102009-08-20 07:17:43 +00005719 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005720 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005721 cast<LabelDecl>(LD), SourceLocation(),
5722 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005723}
Mike Stump11289f42009-09-09 15:08:12 +00005724
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005725template <typename Derived>
5726const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
5727 if (!R)
5728 return R;
5729
5730 switch (R->getKind()) {
5731// Transform attributes with a pragma spelling by calling TransformXXXAttr.
5732#define ATTR(X)
5733#define PRAGMA_SPELLING_ATTR(X) \
5734 case attr::X: \
5735 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
5736#include "clang/Basic/AttrList.inc"
5737 default:
5738 return R;
5739 }
5740}
5741
5742template <typename Derived>
5743StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5744 bool AttrsChanged = false;
5745 SmallVector<const Attr *, 1> Attrs;
5746
5747 // Visit attributes and keep track if any are transformed.
5748 for (const auto *I : S->getAttrs()) {
5749 const Attr *R = getDerived().TransformAttr(I);
5750 AttrsChanged |= (I != R);
5751 Attrs.push_back(R);
5752 }
5753
Richard Smithc202b282012-04-14 00:33:13 +00005754 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5755 if (SubStmt.isInvalid())
5756 return StmtError();
5757
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005758 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00005759 return S;
5760
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005761 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00005762 SubStmt.get());
5763}
5764
5765template<typename Derived>
5766StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005767TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005768 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005769 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005770 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005771 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005772 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005773 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005774 getDerived().TransformDefinition(
5775 S->getConditionVariable()->getLocation(),
5776 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005777 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005778 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005779 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005780 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005781
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005782 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005783 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005784
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005785 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005786 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005787 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005788 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005789 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005790 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005791
John McCallb268a282010-08-23 23:25:46 +00005792 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005793 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005794 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005795
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005796 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005797 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005798 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005799
Douglas Gregorebe10102009-08-20 07:17:43 +00005800 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005801 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005802 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005803 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005804
Douglas Gregorebe10102009-08-20 07:17:43 +00005805 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005806 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005807 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005808 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005809
Douglas Gregorebe10102009-08-20 07:17:43 +00005810 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005811 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005812 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005813 Then.get() == S->getThen() &&
5814 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005815 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005816
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005817 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005818 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005819 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005820}
5821
5822template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005823StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005824TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005825 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005826 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005827 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005828 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005829 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005830 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005831 getDerived().TransformDefinition(
5832 S->getConditionVariable()->getLocation(),
5833 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005834 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005835 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005836 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005837 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005838
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005839 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005840 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005841 }
Mike Stump11289f42009-09-09 15:08:12 +00005842
Douglas Gregorebe10102009-08-20 07:17:43 +00005843 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005844 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005845 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005846 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005847 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005848 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005849
Douglas Gregorebe10102009-08-20 07:17:43 +00005850 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005851 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005852 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005853 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005854
Douglas Gregorebe10102009-08-20 07:17:43 +00005855 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005856 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5857 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005858}
Mike Stump11289f42009-09-09 15:08:12 +00005859
Douglas Gregorebe10102009-08-20 07:17:43 +00005860template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005861StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005862TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005863 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005864 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005865 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005866 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005867 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005868 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005869 getDerived().TransformDefinition(
5870 S->getConditionVariable()->getLocation(),
5871 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005872 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005873 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005874 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005875 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005876
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005877 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005878 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005879
5880 if (S->getCond()) {
5881 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005882 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5883 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005884 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005885 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005886 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005887 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005888 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005889 }
Mike Stump11289f42009-09-09 15:08:12 +00005890
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005891 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005892 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005893 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005894
Douglas Gregorebe10102009-08-20 07:17:43 +00005895 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005896 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005897 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005898 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005899
Douglas Gregorebe10102009-08-20 07:17:43 +00005900 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005901 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005902 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005903 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005904 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005905
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005906 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005907 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005908}
Mike Stump11289f42009-09-09 15:08:12 +00005909
Douglas Gregorebe10102009-08-20 07:17:43 +00005910template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005911StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005912TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005913 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005914 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005915 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005916 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005917
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005918 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005919 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005920 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005921 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005922
Douglas Gregorebe10102009-08-20 07:17:43 +00005923 if (!getDerived().AlwaysRebuild() &&
5924 Cond.get() == S->getCond() &&
5925 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005926 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005927
John McCallb268a282010-08-23 23:25:46 +00005928 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5929 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005930 S->getRParenLoc());
5931}
Mike Stump11289f42009-09-09 15:08:12 +00005932
Douglas Gregorebe10102009-08-20 07:17:43 +00005933template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005934StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005935TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005936 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005937 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005938 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005939 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005940
Douglas Gregorebe10102009-08-20 07:17:43 +00005941 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005942 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005943 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005944 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005945 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005946 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005947 getDerived().TransformDefinition(
5948 S->getConditionVariable()->getLocation(),
5949 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005950 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005951 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005952 } else {
5953 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005954
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005955 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005956 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005957
5958 if (S->getCond()) {
5959 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005960 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5961 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005962 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005963 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005964 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005965
John McCallb268a282010-08-23 23:25:46 +00005966 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005967 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005968 }
Mike Stump11289f42009-09-09 15:08:12 +00005969
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005970 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005971 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005972 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005973
Douglas Gregorebe10102009-08-20 07:17:43 +00005974 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005975 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005976 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005977 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005978
Richard Smith945f8d32013-01-14 22:39:08 +00005979 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005980 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005981 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005982
Douglas Gregorebe10102009-08-20 07:17:43 +00005983 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005984 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005985 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005986 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005987
Douglas Gregorebe10102009-08-20 07:17:43 +00005988 if (!getDerived().AlwaysRebuild() &&
5989 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005990 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005991 Inc.get() == S->getInc() &&
5992 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005993 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005994
Douglas Gregorebe10102009-08-20 07:17:43 +00005995 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005996 Init.get(), FullCond, ConditionVar,
5997 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005998}
5999
6000template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006001StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006002TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006003 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6004 S->getLabel());
6005 if (!LD)
6006 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006007
Douglas Gregorebe10102009-08-20 07:17:43 +00006008 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006009 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006010 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006011}
6012
6013template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006014StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006015TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006016 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006017 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006018 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006019 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006020
Douglas Gregorebe10102009-08-20 07:17:43 +00006021 if (!getDerived().AlwaysRebuild() &&
6022 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006023 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006024
6025 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006026 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006027}
6028
6029template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006030StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006031TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006032 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006033}
Mike Stump11289f42009-09-09 15:08:12 +00006034
Douglas Gregorebe10102009-08-20 07:17:43 +00006035template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006036StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006037TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006038 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006039}
Mike Stump11289f42009-09-09 15:08:12 +00006040
Douglas Gregorebe10102009-08-20 07:17:43 +00006041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006042StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006043TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006044 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6045 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006046 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006047 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006048
Mike Stump11289f42009-09-09 15:08:12 +00006049 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006050 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006051 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006052}
Mike Stump11289f42009-09-09 15:08:12 +00006053
Douglas Gregorebe10102009-08-20 07:17:43 +00006054template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006055StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006056TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006057 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006058 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006059 for (auto *D : S->decls()) {
6060 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006061 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006062 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006063
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006064 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006065 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006066
Douglas Gregorebe10102009-08-20 07:17:43 +00006067 Decls.push_back(Transformed);
6068 }
Mike Stump11289f42009-09-09 15:08:12 +00006069
Douglas Gregorebe10102009-08-20 07:17:43 +00006070 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006071 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006072
Rafael Espindolaab417692013-07-09 12:05:01 +00006073 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006074}
Mike Stump11289f42009-09-09 15:08:12 +00006075
Douglas Gregorebe10102009-08-20 07:17:43 +00006076template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006077StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006078TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006079
Benjamin Kramerf0623432012-08-23 22:51:59 +00006080 SmallVector<Expr*, 8> Constraints;
6081 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006082 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006083
John McCalldadc5752010-08-24 06:29:42 +00006084 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006085 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006086
6087 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006088
Anders Carlssonaaeef072010-01-24 05:50:09 +00006089 // Go through the outputs.
6090 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006091 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006092
Anders Carlssonaaeef072010-01-24 05:50:09 +00006093 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006094 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006095
Anders Carlssonaaeef072010-01-24 05:50:09 +00006096 // Transform the output expr.
6097 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006098 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006099 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006100 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006101
Anders Carlssonaaeef072010-01-24 05:50:09 +00006102 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006103
John McCallb268a282010-08-23 23:25:46 +00006104 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006105 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006106
Anders Carlssonaaeef072010-01-24 05:50:09 +00006107 // Go through the inputs.
6108 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006109 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006110
Anders Carlssonaaeef072010-01-24 05:50:09 +00006111 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006112 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006113
Anders Carlssonaaeef072010-01-24 05:50:09 +00006114 // Transform the input expr.
6115 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006116 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006117 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006118 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006119
Anders Carlssonaaeef072010-01-24 05:50:09 +00006120 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006121
John McCallb268a282010-08-23 23:25:46 +00006122 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006123 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006124
Anders Carlssonaaeef072010-01-24 05:50:09 +00006125 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006126 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006127
6128 // Go through the clobbers.
6129 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006130 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006131
6132 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006133 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006134 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6135 S->isVolatile(), S->getNumOutputs(),
6136 S->getNumInputs(), Names.data(),
6137 Constraints, Exprs, AsmString.get(),
6138 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006139}
6140
Chad Rosier32503022012-06-11 20:47:18 +00006141template<typename Derived>
6142StmtResult
6143TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006144 ArrayRef<Token> AsmToks =
6145 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006146
John McCallf413f5e2013-05-03 00:10:13 +00006147 bool HadError = false, HadChange = false;
6148
6149 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6150 SmallVector<Expr*, 8> TransformedExprs;
6151 TransformedExprs.reserve(SrcExprs.size());
6152 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6153 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6154 if (!Result.isUsable()) {
6155 HadError = true;
6156 } else {
6157 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006158 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006159 }
6160 }
6161
6162 if (HadError) return StmtError();
6163 if (!HadChange && !getDerived().AlwaysRebuild())
6164 return Owned(S);
6165
Chad Rosierb6f46c12012-08-15 16:53:30 +00006166 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006167 AsmToks, S->getAsmString(),
6168 S->getNumOutputs(), S->getNumInputs(),
6169 S->getAllConstraints(), S->getClobbers(),
6170 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006171}
Douglas Gregorebe10102009-08-20 07:17:43 +00006172
6173template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006174StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006175TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006176 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006177 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006178 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006179 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006180
Douglas Gregor96c79492010-04-23 22:50:49 +00006181 // Transform the @catch statements (if present).
6182 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006183 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006184 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006185 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006186 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006187 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006188 if (Catch.get() != S->getCatchStmt(I))
6189 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006190 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006191 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006192
Douglas Gregor306de2f2010-04-22 23:59:56 +00006193 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006194 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006195 if (S->getFinallyStmt()) {
6196 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6197 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006198 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006199 }
6200
6201 // If nothing changed, just retain this statement.
6202 if (!getDerived().AlwaysRebuild() &&
6203 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006204 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006205 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006206 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006207
Douglas Gregor306de2f2010-04-22 23:59:56 +00006208 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006209 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006210 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006211}
Mike Stump11289f42009-09-09 15:08:12 +00006212
Douglas Gregorebe10102009-08-20 07:17:43 +00006213template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006214StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006215TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006216 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006217 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006218 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006219 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006220 if (FromVar->getTypeSourceInfo()) {
6221 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6222 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006223 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006224 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006225
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006226 QualType T;
6227 if (TSInfo)
6228 T = TSInfo->getType();
6229 else {
6230 T = getDerived().TransformType(FromVar->getType());
6231 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006232 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006233 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006234
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006235 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6236 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006237 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006238 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006239
John McCalldadc5752010-08-24 06:29:42 +00006240 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006241 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006242 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006243
6244 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006245 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006246 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006247}
Mike Stump11289f42009-09-09 15:08:12 +00006248
Douglas Gregorebe10102009-08-20 07:17:43 +00006249template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006250StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006251TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006252 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006253 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006254 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006255 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006256
Douglas Gregor306de2f2010-04-22 23:59:56 +00006257 // If nothing changed, just retain this statement.
6258 if (!getDerived().AlwaysRebuild() &&
6259 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006260 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006261
6262 // Build a new statement.
6263 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006264 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006265}
Mike Stump11289f42009-09-09 15:08:12 +00006266
Douglas Gregorebe10102009-08-20 07:17:43 +00006267template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006268StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006269TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006270 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006271 if (S->getThrowExpr()) {
6272 Operand = getDerived().TransformExpr(S->getThrowExpr());
6273 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006274 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006275 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006276
Douglas Gregor2900c162010-04-22 21:44:01 +00006277 if (!getDerived().AlwaysRebuild() &&
6278 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006279 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006280
John McCallb268a282010-08-23 23:25:46 +00006281 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006282}
Mike Stump11289f42009-09-09 15:08:12 +00006283
Douglas Gregorebe10102009-08-20 07:17:43 +00006284template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006285StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006286TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006287 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006288 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006289 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006290 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006291 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006292 Object =
6293 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6294 Object.get());
6295 if (Object.isInvalid())
6296 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006297
Douglas Gregor6148de72010-04-22 22:01:21 +00006298 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006299 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006300 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006301 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006302
Douglas Gregor6148de72010-04-22 22:01:21 +00006303 // If nothing change, just retain the current statement.
6304 if (!getDerived().AlwaysRebuild() &&
6305 Object.get() == S->getSynchExpr() &&
6306 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006307 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006308
6309 // Build a new statement.
6310 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006311 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006312}
6313
6314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006315StmtResult
John McCall31168b02011-06-15 23:02:42 +00006316TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6317 ObjCAutoreleasePoolStmt *S) {
6318 // Transform the body.
6319 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6320 if (Body.isInvalid())
6321 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006322
John McCall31168b02011-06-15 23:02:42 +00006323 // If nothing changed, just retain this statement.
6324 if (!getDerived().AlwaysRebuild() &&
6325 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006326 return S;
John McCall31168b02011-06-15 23:02:42 +00006327
6328 // Build a new statement.
6329 return getDerived().RebuildObjCAutoreleasePoolStmt(
6330 S->getAtLoc(), Body.get());
6331}
6332
6333template<typename Derived>
6334StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006335TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006336 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006337 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006338 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006339 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006340 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006341
Douglas Gregorf68a5082010-04-22 23:10:45 +00006342 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006343 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006344 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006345 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006346
Douglas Gregorf68a5082010-04-22 23:10:45 +00006347 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006348 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006349 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006350 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006351
Douglas Gregorf68a5082010-04-22 23:10:45 +00006352 // If nothing changed, just retain this statement.
6353 if (!getDerived().AlwaysRebuild() &&
6354 Element.get() == S->getElement() &&
6355 Collection.get() == S->getCollection() &&
6356 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006357 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006358
Douglas Gregorf68a5082010-04-22 23:10:45 +00006359 // Build a new statement.
6360 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006361 Element.get(),
6362 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006363 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006364 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006365}
6366
David Majnemer5f7efef2013-10-15 09:50:08 +00006367template <typename Derived>
6368StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006369 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006370 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006371 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6372 TypeSourceInfo *T =
6373 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006374 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006375 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006376
David Majnemer5f7efef2013-10-15 09:50:08 +00006377 Var = getDerived().RebuildExceptionDecl(
6378 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6379 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006380 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006381 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006382 }
Mike Stump11289f42009-09-09 15:08:12 +00006383
Douglas Gregorebe10102009-08-20 07:17:43 +00006384 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006385 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006386 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006387 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006388
David Majnemer5f7efef2013-10-15 09:50:08 +00006389 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006390 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006391 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006392
David Majnemer5f7efef2013-10-15 09:50:08 +00006393 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006394}
Mike Stump11289f42009-09-09 15:08:12 +00006395
David Majnemer5f7efef2013-10-15 09:50:08 +00006396template <typename Derived>
6397StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006398 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006399 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006400 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006401 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006402
Douglas Gregorebe10102009-08-20 07:17:43 +00006403 // Transform the handlers.
6404 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006405 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006406 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006407 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006408 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006409 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006410
Douglas Gregorebe10102009-08-20 07:17:43 +00006411 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006412 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006413 }
Mike Stump11289f42009-09-09 15:08:12 +00006414
David Majnemer5f7efef2013-10-15 09:50:08 +00006415 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006416 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006417 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006418
John McCallb268a282010-08-23 23:25:46 +00006419 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006420 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006421}
Mike Stump11289f42009-09-09 15:08:12 +00006422
Richard Smith02e85f32011-04-14 22:09:26 +00006423template<typename Derived>
6424StmtResult
6425TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6426 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6427 if (Range.isInvalid())
6428 return StmtError();
6429
6430 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6431 if (BeginEnd.isInvalid())
6432 return StmtError();
6433
6434 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6435 if (Cond.isInvalid())
6436 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006437 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006438 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006439 if (Cond.isInvalid())
6440 return StmtError();
6441 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006442 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006443
6444 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6445 if (Inc.isInvalid())
6446 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006447 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006448 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006449
6450 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6451 if (LoopVar.isInvalid())
6452 return StmtError();
6453
6454 StmtResult NewStmt = S;
6455 if (getDerived().AlwaysRebuild() ||
6456 Range.get() != S->getRangeStmt() ||
6457 BeginEnd.get() != S->getBeginEndStmt() ||
6458 Cond.get() != S->getCond() ||
6459 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006460 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006461 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6462 S->getColonLoc(), Range.get(),
6463 BeginEnd.get(), Cond.get(),
6464 Inc.get(), LoopVar.get(),
6465 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006466 if (NewStmt.isInvalid())
6467 return StmtError();
6468 }
Richard Smith02e85f32011-04-14 22:09:26 +00006469
6470 StmtResult Body = getDerived().TransformStmt(S->getBody());
6471 if (Body.isInvalid())
6472 return StmtError();
6473
6474 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6475 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006476 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006477 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6478 S->getColonLoc(), Range.get(),
6479 BeginEnd.get(), Cond.get(),
6480 Inc.get(), LoopVar.get(),
6481 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006482 if (NewStmt.isInvalid())
6483 return StmtError();
6484 }
Richard Smith02e85f32011-04-14 22:09:26 +00006485
6486 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006487 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006488
6489 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6490}
6491
John Wiegley1c0675e2011-04-28 01:08:34 +00006492template<typename Derived>
6493StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006494TreeTransform<Derived>::TransformMSDependentExistsStmt(
6495 MSDependentExistsStmt *S) {
6496 // Transform the nested-name-specifier, if any.
6497 NestedNameSpecifierLoc QualifierLoc;
6498 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006499 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006500 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6501 if (!QualifierLoc)
6502 return StmtError();
6503 }
6504
6505 // Transform the declaration name.
6506 DeclarationNameInfo NameInfo = S->getNameInfo();
6507 if (NameInfo.getName()) {
6508 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6509 if (!NameInfo.getName())
6510 return StmtError();
6511 }
6512
6513 // Check whether anything changed.
6514 if (!getDerived().AlwaysRebuild() &&
6515 QualifierLoc == S->getQualifierLoc() &&
6516 NameInfo.getName() == S->getNameInfo().getName())
6517 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006518
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006519 // Determine whether this name exists, if we can.
6520 CXXScopeSpec SS;
6521 SS.Adopt(QualifierLoc);
6522 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006523 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006524 case Sema::IER_Exists:
6525 if (S->isIfExists())
6526 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006527
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006528 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6529
6530 case Sema::IER_DoesNotExist:
6531 if (S->isIfNotExists())
6532 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006533
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006534 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006535
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006536 case Sema::IER_Dependent:
6537 Dependent = true;
6538 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006539
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006540 case Sema::IER_Error:
6541 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006542 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006543
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006544 // We need to continue with the instantiation, so do so now.
6545 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6546 if (SubStmt.isInvalid())
6547 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006548
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006549 // If we have resolved the name, just transform to the substatement.
6550 if (!Dependent)
6551 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006552
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006553 // The name is still dependent, so build a dependent expression again.
6554 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6555 S->isIfExists(),
6556 QualifierLoc,
6557 NameInfo,
6558 SubStmt.get());
6559}
6560
6561template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006562ExprResult
6563TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6564 NestedNameSpecifierLoc QualifierLoc;
6565 if (E->getQualifierLoc()) {
6566 QualifierLoc
6567 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6568 if (!QualifierLoc)
6569 return ExprError();
6570 }
6571
6572 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6573 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6574 if (!PD)
6575 return ExprError();
6576
6577 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6578 if (Base.isInvalid())
6579 return ExprError();
6580
6581 return new (SemaRef.getASTContext())
6582 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6583 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6584 QualifierLoc, E->getMemberLoc());
6585}
6586
David Majnemerfad8f482013-10-15 09:33:02 +00006587template <typename Derived>
6588StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006589 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006590 if (TryBlock.isInvalid())
6591 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006592
6593 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006594 if (Handler.isInvalid())
6595 return StmtError();
6596
David Majnemerfad8f482013-10-15 09:33:02 +00006597 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6598 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006599 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006600
Warren Huntf6be4cb2014-07-25 20:52:51 +00006601 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6602 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006603}
6604
David Majnemerfad8f482013-10-15 09:33:02 +00006605template <typename Derived>
6606StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006607 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006608 if (Block.isInvalid())
6609 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006610
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006611 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006612}
6613
David Majnemerfad8f482013-10-15 09:33:02 +00006614template <typename Derived>
6615StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006616 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006617 if (FilterExpr.isInvalid())
6618 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006619
David Majnemer7e755502013-10-15 09:30:14 +00006620 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006621 if (Block.isInvalid())
6622 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006623
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006624 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6625 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006626}
6627
David Majnemerfad8f482013-10-15 09:33:02 +00006628template <typename Derived>
6629StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6630 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006631 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6632 else
6633 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6634}
6635
Nico Weber9b982072014-07-07 00:12:30 +00006636template<typename Derived>
6637StmtResult
6638TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6639 return S;
6640}
6641
Alexander Musman64d33f12014-06-04 07:53:32 +00006642//===----------------------------------------------------------------------===//
6643// OpenMP directive transformation
6644//===----------------------------------------------------------------------===//
6645template <typename Derived>
6646StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6647 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006648
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006649 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006650 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006651 ArrayRef<OMPClause *> Clauses = D->clauses();
6652 TClauses.reserve(Clauses.size());
6653 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6654 I != E; ++I) {
6655 if (*I) {
6656 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevc5e02582014-06-16 07:08:35 +00006657 if (Clause)
6658 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006659 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006660 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006661 }
6662 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006663 StmtResult AssociatedStmt;
6664 if (D->hasAssociatedStmt()) {
6665 if (!D->getAssociatedStmt()) {
6666 return StmtError();
6667 }
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00006668 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
6669 /*CurScope=*/nullptr);
6670 StmtResult Body;
6671 {
6672 Sema::CompoundScopeRAII CompoundScope(getSema());
6673 Body = getDerived().TransformStmt(
6674 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
6675 }
6676 AssociatedStmt =
6677 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00006678 if (AssociatedStmt.isInvalid()) {
6679 return StmtError();
6680 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006681 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006682 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006683 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006684 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006685
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006686 // Transform directive name for 'omp critical' directive.
6687 DeclarationNameInfo DirName;
6688 if (D->getDirectiveKind() == OMPD_critical) {
6689 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6690 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6691 }
6692
Alexander Musman64d33f12014-06-04 07:53:32 +00006693 return getDerived().RebuildOMPExecutableDirective(
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006694 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
6695 D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006696}
6697
Alexander Musman64d33f12014-06-04 07:53:32 +00006698template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006699StmtResult
6700TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6701 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006702 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6703 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006704 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6705 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6706 return Res;
6707}
6708
Alexander Musman64d33f12014-06-04 07:53:32 +00006709template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006710StmtResult
6711TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6712 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006713 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6714 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006715 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6716 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006717 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006718}
6719
Alexey Bataevf29276e2014-06-18 04:14:57 +00006720template <typename Derived>
6721StmtResult
6722TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6723 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006724 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6725 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006726 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6727 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6728 return Res;
6729}
6730
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006731template <typename Derived>
6732StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00006733TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
6734 DeclarationNameInfo DirName;
6735 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
6736 D->getLocStart());
6737 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6738 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6739 return Res;
6740}
6741
6742template <typename Derived>
6743StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006744TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6745 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006746 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6747 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006748 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6749 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6750 return Res;
6751}
6752
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006753template <typename Derived>
6754StmtResult
6755TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6756 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006757 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6758 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006759 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6760 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6761 return Res;
6762}
6763
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006764template <typename Derived>
6765StmtResult
6766TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6767 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006768 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6769 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006770 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6771 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6772 return Res;
6773}
6774
Alexey Bataev4acb8592014-07-07 13:01:15 +00006775template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006776StmtResult
6777TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6778 DeclarationNameInfo DirName;
6779 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6780 D->getLocStart());
6781 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6782 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6783 return Res;
6784}
6785
6786template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006787StmtResult
6788TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6789 getDerived().getSema().StartOpenMPDSABlock(
6790 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
6791 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6792 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6793 return Res;
6794}
6795
6796template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00006797StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6798 OMPParallelForDirective *D) {
6799 DeclarationNameInfo DirName;
6800 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6801 nullptr, D->getLocStart());
6802 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6803 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6804 return Res;
6805}
6806
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006807template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00006808StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
6809 OMPParallelForSimdDirective *D) {
6810 DeclarationNameInfo DirName;
6811 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
6812 nullptr, D->getLocStart());
6813 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6814 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6815 return Res;
6816}
6817
6818template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006819StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6820 OMPParallelSectionsDirective *D) {
6821 DeclarationNameInfo DirName;
6822 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6823 nullptr, D->getLocStart());
6824 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6825 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6826 return Res;
6827}
6828
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00006829template <typename Derived>
6830StmtResult
6831TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6832 DeclarationNameInfo DirName;
6833 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6834 D->getLocStart());
6835 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6836 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6837 return Res;
6838}
6839
Alexey Bataev68446b72014-07-18 07:47:19 +00006840template <typename Derived>
6841StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
6842 OMPTaskyieldDirective *D) {
6843 DeclarationNameInfo DirName;
6844 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
6845 D->getLocStart());
6846 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6847 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6848 return Res;
6849}
6850
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00006851template <typename Derived>
6852StmtResult
6853TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
6854 DeclarationNameInfo DirName;
6855 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
6856 D->getLocStart());
6857 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6858 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6859 return Res;
6860}
6861
Alexey Bataev2df347a2014-07-18 10:17:07 +00006862template <typename Derived>
6863StmtResult
6864TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
6865 DeclarationNameInfo DirName;
6866 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
6867 D->getLocStart());
6868 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6869 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6870 return Res;
6871}
6872
Alexey Bataev6125da92014-07-21 11:26:11 +00006873template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00006874StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
6875 OMPTaskgroupDirective *D) {
6876 DeclarationNameInfo DirName;
6877 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
6878 D->getLocStart());
6879 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6880 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6881 return Res;
6882}
6883
6884template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00006885StmtResult
6886TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
6887 DeclarationNameInfo DirName;
6888 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
6889 D->getLocStart());
6890 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6891 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6892 return Res;
6893}
6894
Alexey Bataev9fb6e642014-07-22 06:45:04 +00006895template <typename Derived>
6896StmtResult
6897TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
6898 DeclarationNameInfo DirName;
6899 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
6900 D->getLocStart());
6901 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6902 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6903 return Res;
6904}
6905
Alexey Bataev0162e452014-07-22 10:10:35 +00006906template <typename Derived>
6907StmtResult
6908TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
6909 DeclarationNameInfo DirName;
6910 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
6911 D->getLocStart());
6912 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6913 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6914 return Res;
6915}
6916
Alexey Bataev0bd520b2014-09-19 08:19:49 +00006917template <typename Derived>
6918StmtResult
6919TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
6920 DeclarationNameInfo DirName;
6921 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
6922 D->getLocStart());
6923 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6924 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6925 return Res;
6926}
6927
Alexey Bataev13314bf2014-10-09 04:18:56 +00006928template <typename Derived>
6929StmtResult
6930TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
6931 DeclarationNameInfo DirName;
6932 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
6933 D->getLocStart());
6934 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6935 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6936 return Res;
6937}
6938
Alexander Musman64d33f12014-06-04 07:53:32 +00006939//===----------------------------------------------------------------------===//
6940// OpenMP clause transformation
6941//===----------------------------------------------------------------------===//
6942template <typename Derived>
6943OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006944 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6945 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006946 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006947 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006948 C->getLParenLoc(), C->getLocEnd());
6949}
6950
Alexander Musman64d33f12014-06-04 07:53:32 +00006951template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00006952OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
6953 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6954 if (Cond.isInvalid())
6955 return nullptr;
6956 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
6957 C->getLParenLoc(), C->getLocEnd());
6958}
6959
6960template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006961OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006962TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6963 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6964 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006965 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006966 return getDerived().RebuildOMPNumThreadsClause(
6967 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006968}
6969
Alexey Bataev62c87d22014-03-21 04:51:18 +00006970template <typename Derived>
6971OMPClause *
6972TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6973 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6974 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006975 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006976 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006977 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006978}
6979
Alexander Musman8bd31e62014-05-27 15:12:19 +00006980template <typename Derived>
6981OMPClause *
6982TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6983 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6984 if (E.isInvalid())
6985 return 0;
6986 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006987 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006988}
6989
Alexander Musman64d33f12014-06-04 07:53:32 +00006990template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006991OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006992TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006993 return getDerived().RebuildOMPDefaultClause(
6994 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6995 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006996}
6997
Alexander Musman64d33f12014-06-04 07:53:32 +00006998template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006999OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007000TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007001 return getDerived().RebuildOMPProcBindClause(
7002 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7003 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007004}
7005
Alexander Musman64d33f12014-06-04 07:53:32 +00007006template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007007OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007008TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7009 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7010 if (E.isInvalid())
7011 return nullptr;
7012 return getDerived().RebuildOMPScheduleClause(
7013 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7014 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7015}
7016
7017template <typename Derived>
7018OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007019TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
7020 // No need to rebuild this clause, no template-dependent parameters.
7021 return C;
7022}
7023
7024template <typename Derived>
7025OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007026TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7027 // No need to rebuild this clause, no template-dependent parameters.
7028 return C;
7029}
7030
7031template <typename Derived>
7032OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007033TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7034 // No need to rebuild this clause, no template-dependent parameters.
7035 return C;
7036}
7037
7038template <typename Derived>
7039OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007040TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7041 // No need to rebuild this clause, no template-dependent parameters.
7042 return C;
7043}
7044
7045template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007046OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7047 // No need to rebuild this clause, no template-dependent parameters.
7048 return C;
7049}
7050
7051template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007052OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7053 // No need to rebuild this clause, no template-dependent parameters.
7054 return C;
7055}
7056
7057template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007058OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007059TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7060 // No need to rebuild this clause, no template-dependent parameters.
7061 return C;
7062}
7063
7064template <typename Derived>
7065OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007066TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7067 // No need to rebuild this clause, no template-dependent parameters.
7068 return C;
7069}
7070
7071template <typename Derived>
7072OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007073TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7074 // No need to rebuild this clause, no template-dependent parameters.
7075 return C;
7076}
7077
7078template <typename Derived>
7079OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007080TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007081 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007082 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007083 for (auto *VE : C->varlists()) {
7084 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007085 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007086 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007087 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007088 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007089 return getDerived().RebuildOMPPrivateClause(
7090 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007091}
7092
Alexander Musman64d33f12014-06-04 07:53:32 +00007093template <typename Derived>
7094OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7095 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007096 llvm::SmallVector<Expr *, 16> Vars;
7097 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007098 for (auto *VE : C->varlists()) {
7099 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007100 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007101 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007102 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007103 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007104 return getDerived().RebuildOMPFirstprivateClause(
7105 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007106}
7107
Alexander Musman64d33f12014-06-04 07:53:32 +00007108template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007109OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007110TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7111 llvm::SmallVector<Expr *, 16> Vars;
7112 Vars.reserve(C->varlist_size());
7113 for (auto *VE : C->varlists()) {
7114 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7115 if (EVar.isInvalid())
7116 return nullptr;
7117 Vars.push_back(EVar.get());
7118 }
7119 return getDerived().RebuildOMPLastprivateClause(
7120 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7121}
7122
7123template <typename Derived>
7124OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007125TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7126 llvm::SmallVector<Expr *, 16> Vars;
7127 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007128 for (auto *VE : C->varlists()) {
7129 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007130 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007131 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007132 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007133 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007134 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7135 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007136}
7137
Alexander Musman64d33f12014-06-04 07:53:32 +00007138template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007139OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007140TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7141 llvm::SmallVector<Expr *, 16> Vars;
7142 Vars.reserve(C->varlist_size());
7143 for (auto *VE : C->varlists()) {
7144 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7145 if (EVar.isInvalid())
7146 return nullptr;
7147 Vars.push_back(EVar.get());
7148 }
7149 CXXScopeSpec ReductionIdScopeSpec;
7150 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7151
7152 DeclarationNameInfo NameInfo = C->getNameInfo();
7153 if (NameInfo.getName()) {
7154 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7155 if (!NameInfo.getName())
7156 return nullptr;
7157 }
7158 return getDerived().RebuildOMPReductionClause(
7159 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7160 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7161}
7162
7163template <typename Derived>
7164OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007165TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7166 llvm::SmallVector<Expr *, 16> Vars;
7167 Vars.reserve(C->varlist_size());
7168 for (auto *VE : C->varlists()) {
7169 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7170 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007171 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007172 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007173 }
7174 ExprResult Step = getDerived().TransformExpr(C->getStep());
7175 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007176 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007177 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
7178 C->getLParenLoc(),
7179 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007180}
7181
Alexander Musman64d33f12014-06-04 07:53:32 +00007182template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007183OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007184TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7185 llvm::SmallVector<Expr *, 16> Vars;
7186 Vars.reserve(C->varlist_size());
7187 for (auto *VE : C->varlists()) {
7188 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7189 if (EVar.isInvalid())
7190 return nullptr;
7191 Vars.push_back(EVar.get());
7192 }
7193 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7194 if (Alignment.isInvalid())
7195 return nullptr;
7196 return getDerived().RebuildOMPAlignedClause(
7197 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7198 C->getColonLoc(), C->getLocEnd());
7199}
7200
Alexander Musman64d33f12014-06-04 07:53:32 +00007201template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007202OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007203TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7204 llvm::SmallVector<Expr *, 16> Vars;
7205 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007206 for (auto *VE : C->varlists()) {
7207 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007208 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007209 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007210 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007211 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007212 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7213 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007214}
7215
Alexey Bataevbae9a792014-06-27 10:37:06 +00007216template <typename Derived>
7217OMPClause *
7218TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7219 llvm::SmallVector<Expr *, 16> Vars;
7220 Vars.reserve(C->varlist_size());
7221 for (auto *VE : C->varlists()) {
7222 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7223 if (EVar.isInvalid())
7224 return nullptr;
7225 Vars.push_back(EVar.get());
7226 }
7227 return getDerived().RebuildOMPCopyprivateClause(
7228 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7229}
7230
Alexey Bataev6125da92014-07-21 11:26:11 +00007231template <typename Derived>
7232OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7233 llvm::SmallVector<Expr *, 16> Vars;
7234 Vars.reserve(C->varlist_size());
7235 for (auto *VE : C->varlists()) {
7236 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7237 if (EVar.isInvalid())
7238 return nullptr;
7239 Vars.push_back(EVar.get());
7240 }
7241 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7242 C->getLParenLoc(), C->getLocEnd());
7243}
7244
Douglas Gregorebe10102009-08-20 07:17:43 +00007245//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007246// Expression transformation
7247//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007248template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007249ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007250TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007251 if (!E->isTypeDependent())
7252 return E;
7253
7254 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7255 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007256}
Mike Stump11289f42009-09-09 15:08:12 +00007257
7258template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007259ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007260TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007261 NestedNameSpecifierLoc QualifierLoc;
7262 if (E->getQualifierLoc()) {
7263 QualifierLoc
7264 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7265 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007266 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007267 }
John McCallce546572009-12-08 09:08:17 +00007268
7269 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007270 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7271 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007272 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007273 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007274
John McCall815039a2010-08-17 21:27:17 +00007275 DeclarationNameInfo NameInfo = E->getNameInfo();
7276 if (NameInfo.getName()) {
7277 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7278 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007279 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007280 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007281
7282 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007283 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007284 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007285 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007286 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007287
7288 // Mark it referenced in the new context regardless.
7289 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007290 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007291
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007292 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007293 }
John McCallce546572009-12-08 09:08:17 +00007294
Craig Topperc3ec1492014-05-26 06:22:03 +00007295 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007296 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007297 TemplateArgs = &TransArgs;
7298 TransArgs.setLAngleLoc(E->getLAngleLoc());
7299 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007300 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7301 E->getNumTemplateArgs(),
7302 TransArgs))
7303 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007304 }
7305
Chad Rosier1dcde962012-08-08 18:46:20 +00007306 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007307 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007308}
Mike Stump11289f42009-09-09 15:08:12 +00007309
Douglas Gregora16548e2009-08-11 05:31:07 +00007310template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007311ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007312TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007313 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007314}
Mike Stump11289f42009-09-09 15:08:12 +00007315
Douglas Gregora16548e2009-08-11 05:31:07 +00007316template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007317ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007318TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007319 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007320}
Mike Stump11289f42009-09-09 15:08:12 +00007321
Douglas Gregora16548e2009-08-11 05:31:07 +00007322template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007323ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007324TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007325 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007326}
Mike Stump11289f42009-09-09 15:08:12 +00007327
Douglas Gregora16548e2009-08-11 05:31:07 +00007328template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007329ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007330TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007331 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007332}
Mike Stump11289f42009-09-09 15:08:12 +00007333
Douglas Gregora16548e2009-08-11 05:31:07 +00007334template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007335ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007336TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007337 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007338}
7339
7340template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007341ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007342TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007343 if (FunctionDecl *FD = E->getDirectCallee())
7344 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007345 return SemaRef.MaybeBindToTemporary(E);
7346}
7347
7348template<typename Derived>
7349ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007350TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7351 ExprResult ControllingExpr =
7352 getDerived().TransformExpr(E->getControllingExpr());
7353 if (ControllingExpr.isInvalid())
7354 return ExprError();
7355
Chris Lattner01cf8db2011-07-20 06:58:45 +00007356 SmallVector<Expr *, 4> AssocExprs;
7357 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007358 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7359 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7360 if (TS) {
7361 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7362 if (!AssocType)
7363 return ExprError();
7364 AssocTypes.push_back(AssocType);
7365 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007366 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007367 }
7368
7369 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7370 if (AssocExpr.isInvalid())
7371 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007372 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007373 }
7374
7375 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7376 E->getDefaultLoc(),
7377 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007378 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007379 AssocTypes,
7380 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007381}
7382
7383template<typename Derived>
7384ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007385TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007386 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007387 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007388 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007389
Douglas Gregora16548e2009-08-11 05:31:07 +00007390 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007391 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007392
John McCallb268a282010-08-23 23:25:46 +00007393 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007394 E->getRParen());
7395}
7396
Richard Smithdb2630f2012-10-21 03:28:35 +00007397/// \brief The operand of a unary address-of operator has special rules: it's
7398/// allowed to refer to a non-static member of a class even if there's no 'this'
7399/// object available.
7400template<typename Derived>
7401ExprResult
7402TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7403 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007404 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007405 else
7406 return getDerived().TransformExpr(E);
7407}
7408
Mike Stump11289f42009-09-09 15:08:12 +00007409template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007410ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007411TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007412 ExprResult SubExpr;
7413 if (E->getOpcode() == UO_AddrOf)
7414 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7415 else
7416 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007417 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007418 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007419
Douglas Gregora16548e2009-08-11 05:31:07 +00007420 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007421 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007422
Douglas Gregora16548e2009-08-11 05:31:07 +00007423 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7424 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007425 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007426}
Mike Stump11289f42009-09-09 15:08:12 +00007427
Douglas Gregora16548e2009-08-11 05:31:07 +00007428template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007429ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007430TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7431 // Transform the type.
7432 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7433 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007434 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007435
Douglas Gregor882211c2010-04-28 22:16:22 +00007436 // Transform all of the components into components similar to what the
7437 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007438 // FIXME: It would be slightly more efficient in the non-dependent case to
7439 // just map FieldDecls, rather than requiring the rebuilder to look for
7440 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007441 // template code that we don't care.
7442 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007443 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007444 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007445 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007446 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7447 const Node &ON = E->getComponent(I);
7448 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007449 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007450 Comp.LocStart = ON.getSourceRange().getBegin();
7451 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007452 switch (ON.getKind()) {
7453 case Node::Array: {
7454 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007455 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007456 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007457 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007458
Douglas Gregor882211c2010-04-28 22:16:22 +00007459 ExprChanged = ExprChanged || Index.get() != FromIndex;
7460 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007461 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007462 break;
7463 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007464
Douglas Gregor882211c2010-04-28 22:16:22 +00007465 case Node::Field:
7466 case Node::Identifier:
7467 Comp.isBrackets = false;
7468 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007469 if (!Comp.U.IdentInfo)
7470 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007471
Douglas Gregor882211c2010-04-28 22:16:22 +00007472 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007473
Douglas Gregord1702062010-04-29 00:18:15 +00007474 case Node::Base:
7475 // Will be recomputed during the rebuild.
7476 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007477 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007478
Douglas Gregor882211c2010-04-28 22:16:22 +00007479 Components.push_back(Comp);
7480 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007481
Douglas Gregor882211c2010-04-28 22:16:22 +00007482 // If nothing changed, retain the existing expression.
7483 if (!getDerived().AlwaysRebuild() &&
7484 Type == E->getTypeSourceInfo() &&
7485 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007486 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007487
Douglas Gregor882211c2010-04-28 22:16:22 +00007488 // Build a new offsetof expression.
7489 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7490 Components.data(), Components.size(),
7491 E->getRParenLoc());
7492}
7493
7494template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007495ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007496TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7497 assert(getDerived().AlreadyTransformed(E->getType()) &&
7498 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007499 return E;
John McCall8d69a212010-11-15 23:31:06 +00007500}
7501
7502template<typename Derived>
7503ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00007504TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
7505 return E;
7506}
7507
7508template<typename Derived>
7509ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007510TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007511 // Rebuild the syntactic form. The original syntactic form has
7512 // opaque-value expressions in it, so strip those away and rebuild
7513 // the result. This is a really awful way of doing this, but the
7514 // better solution (rebuilding the semantic expressions and
7515 // rebinding OVEs as necessary) doesn't work; we'd need
7516 // TreeTransform to not strip away implicit conversions.
7517 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7518 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007519 if (result.isInvalid()) return ExprError();
7520
7521 // If that gives us a pseudo-object result back, the pseudo-object
7522 // expression must have been an lvalue-to-rvalue conversion which we
7523 // should reapply.
7524 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007525 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007526
7527 return result;
7528}
7529
7530template<typename Derived>
7531ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007532TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7533 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007534 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007535 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007536
John McCallbcd03502009-12-07 02:54:59 +00007537 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007538 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007539 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007540
John McCall4c98fd82009-11-04 07:28:41 +00007541 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007542 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007543
Peter Collingbournee190dee2011-03-11 19:24:49 +00007544 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7545 E->getKind(),
7546 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007547 }
Mike Stump11289f42009-09-09 15:08:12 +00007548
Eli Friedmane4f22df2012-02-29 04:03:55 +00007549 // C++0x [expr.sizeof]p1:
7550 // The operand is either an expression, which is an unevaluated operand
7551 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007552 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7553 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007554
Reid Kleckner32506ed2014-06-12 23:03:48 +00007555 // Try to recover if we have something like sizeof(T::X) where X is a type.
7556 // Notably, there must be *exactly* one set of parens if X is a type.
7557 TypeSourceInfo *RecoveryTSI = nullptr;
7558 ExprResult SubExpr;
7559 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7560 if (auto *DRE =
7561 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7562 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7563 PE, DRE, false, &RecoveryTSI);
7564 else
7565 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7566
7567 if (RecoveryTSI) {
7568 return getDerived().RebuildUnaryExprOrTypeTrait(
7569 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7570 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007571 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007572
Eli Friedmane4f22df2012-02-29 04:03:55 +00007573 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007574 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007575
Peter Collingbournee190dee2011-03-11 19:24:49 +00007576 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7577 E->getOperatorLoc(),
7578 E->getKind(),
7579 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007580}
Mike Stump11289f42009-09-09 15:08:12 +00007581
Douglas Gregora16548e2009-08-11 05:31:07 +00007582template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007583ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007584TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007585 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007586 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007587 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007588
John McCalldadc5752010-08-24 06:29:42 +00007589 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007590 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007591 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007592
7593
Douglas Gregora16548e2009-08-11 05:31:07 +00007594 if (!getDerived().AlwaysRebuild() &&
7595 LHS.get() == E->getLHS() &&
7596 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007597 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007598
John McCallb268a282010-08-23 23:25:46 +00007599 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007600 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007601 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007602 E->getRBracketLoc());
7603}
Mike Stump11289f42009-09-09 15:08:12 +00007604
7605template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007606ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007607TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007608 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007609 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007610 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007611 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007612
7613 // Transform arguments.
7614 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007615 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007616 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007617 &ArgChanged))
7618 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007619
Douglas Gregora16548e2009-08-11 05:31:07 +00007620 if (!getDerived().AlwaysRebuild() &&
7621 Callee.get() == E->getCallee() &&
7622 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007623 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007624
Douglas Gregora16548e2009-08-11 05:31:07 +00007625 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007626 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007627 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007628 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007629 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007630 E->getRParenLoc());
7631}
Mike Stump11289f42009-09-09 15:08:12 +00007632
7633template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007634ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007635TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007636 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007637 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007638 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007639
Douglas Gregorea972d32011-02-28 21:54:11 +00007640 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007641 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007642 QualifierLoc
7643 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007644
Douglas Gregorea972d32011-02-28 21:54:11 +00007645 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007646 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007647 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007648 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007649
Eli Friedman2cfcef62009-12-04 06:40:45 +00007650 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007651 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7652 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007653 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007654 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007655
John McCall16df1e52010-03-30 21:47:33 +00007656 NamedDecl *FoundDecl = E->getFoundDecl();
7657 if (FoundDecl == E->getMemberDecl()) {
7658 FoundDecl = Member;
7659 } else {
7660 FoundDecl = cast_or_null<NamedDecl>(
7661 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7662 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007663 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007664 }
7665
Douglas Gregora16548e2009-08-11 05:31:07 +00007666 if (!getDerived().AlwaysRebuild() &&
7667 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007668 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007669 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007670 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007671 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007672
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007673 // Mark it referenced in the new context regardless.
7674 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007675 SemaRef.MarkMemberReferenced(E);
7676
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007677 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007678 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007679
John McCall6b51f282009-11-23 01:53:49 +00007680 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007681 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007682 TransArgs.setLAngleLoc(E->getLAngleLoc());
7683 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007684 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7685 E->getNumTemplateArgs(),
7686 TransArgs))
7687 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007688 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007689
Douglas Gregora16548e2009-08-11 05:31:07 +00007690 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007691 SourceLocation FakeOperatorLoc =
7692 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007693
John McCall38836f02010-01-15 08:34:02 +00007694 // FIXME: to do this check properly, we will need to preserve the
7695 // first-qualifier-in-scope here, just in case we had a dependent
7696 // base (and therefore couldn't do the check) and a
7697 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007698 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007699
John McCallb268a282010-08-23 23:25:46 +00007700 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007701 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007702 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007703 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007704 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007705 Member,
John McCall16df1e52010-03-30 21:47:33 +00007706 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007707 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007708 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007709 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007710}
Mike Stump11289f42009-09-09 15:08:12 +00007711
Douglas Gregora16548e2009-08-11 05:31:07 +00007712template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007713ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007714TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007715 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007716 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007717 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007718
John McCalldadc5752010-08-24 06:29:42 +00007719 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007720 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007721 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007722
Douglas Gregora16548e2009-08-11 05:31:07 +00007723 if (!getDerived().AlwaysRebuild() &&
7724 LHS.get() == E->getLHS() &&
7725 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007726 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007727
Lang Hames5de91cc2012-10-02 04:45:10 +00007728 Sema::FPContractStateRAII FPContractState(getSema());
7729 getSema().FPFeatures.fp_contract = E->isFPContractable();
7730
Douglas Gregora16548e2009-08-11 05:31:07 +00007731 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007732 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007733}
7734
Mike Stump11289f42009-09-09 15:08:12 +00007735template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007736ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007737TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007738 CompoundAssignOperator *E) {
7739 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007740}
Mike Stump11289f42009-09-09 15:08:12 +00007741
Douglas Gregora16548e2009-08-11 05:31:07 +00007742template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007743ExprResult TreeTransform<Derived>::
7744TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7745 // Just rebuild the common and RHS expressions and see whether we
7746 // get any changes.
7747
7748 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7749 if (commonExpr.isInvalid())
7750 return ExprError();
7751
7752 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7753 if (rhs.isInvalid())
7754 return ExprError();
7755
7756 if (!getDerived().AlwaysRebuild() &&
7757 commonExpr.get() == e->getCommon() &&
7758 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007759 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007760
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007761 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007762 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007763 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007764 e->getColonLoc(),
7765 rhs.get());
7766}
7767
7768template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007769ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007770TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007771 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007772 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007773 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007774
John McCalldadc5752010-08-24 06:29:42 +00007775 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007776 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007777 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007778
John McCalldadc5752010-08-24 06:29:42 +00007779 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007780 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007781 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007782
Douglas Gregora16548e2009-08-11 05:31:07 +00007783 if (!getDerived().AlwaysRebuild() &&
7784 Cond.get() == E->getCond() &&
7785 LHS.get() == E->getLHS() &&
7786 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007787 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007788
John McCallb268a282010-08-23 23:25:46 +00007789 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007790 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007791 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007792 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007793 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007794}
Mike Stump11289f42009-09-09 15:08:12 +00007795
7796template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007797ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007798TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007799 // Implicit casts are eliminated during transformation, since they
7800 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007801 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007802}
Mike Stump11289f42009-09-09 15:08:12 +00007803
Douglas Gregora16548e2009-08-11 05:31:07 +00007804template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007805ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007806TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007807 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7808 if (!Type)
7809 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007810
John McCalldadc5752010-08-24 06:29:42 +00007811 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007812 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007813 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007814 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007815
Douglas Gregora16548e2009-08-11 05:31:07 +00007816 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007817 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007818 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007819 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007820
John McCall97513962010-01-15 18:39:57 +00007821 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007822 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007823 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007824 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007825}
Mike Stump11289f42009-09-09 15:08:12 +00007826
Douglas Gregora16548e2009-08-11 05:31:07 +00007827template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007828ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007829TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007830 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7831 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7832 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007833 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007834
John McCalldadc5752010-08-24 06:29:42 +00007835 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007836 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007837 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007838
Douglas Gregora16548e2009-08-11 05:31:07 +00007839 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007840 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007841 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007842 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007843
John McCall5d7aa7f2010-01-19 22:33:45 +00007844 // Note: the expression type doesn't necessarily match the
7845 // type-as-written, but that's okay, because it should always be
7846 // derivable from the initializer.
7847
John McCalle15bbff2010-01-18 19:35:47 +00007848 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007849 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007850 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007851}
Mike Stump11289f42009-09-09 15:08:12 +00007852
Douglas Gregora16548e2009-08-11 05:31:07 +00007853template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007854ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007855TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007856 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007857 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007858 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007859
Douglas Gregora16548e2009-08-11 05:31:07 +00007860 if (!getDerived().AlwaysRebuild() &&
7861 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007862 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007863
Douglas Gregora16548e2009-08-11 05:31:07 +00007864 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007865 SourceLocation FakeOperatorLoc =
7866 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007867 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007868 E->getAccessorLoc(),
7869 E->getAccessor());
7870}
Mike Stump11289f42009-09-09 15:08:12 +00007871
Douglas Gregora16548e2009-08-11 05:31:07 +00007872template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007873ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007874TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00007875 if (InitListExpr *Syntactic = E->getSyntacticForm())
7876 E = Syntactic;
7877
Douglas Gregora16548e2009-08-11 05:31:07 +00007878 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007879
Benjamin Kramerf0623432012-08-23 22:51:59 +00007880 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007881 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007882 Inits, &InitChanged))
7883 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007884
Richard Smith520449d2015-02-05 06:15:50 +00007885 if (!getDerived().AlwaysRebuild() && !InitChanged) {
7886 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
7887 // in some cases. We can't reuse it in general, because the syntactic and
7888 // semantic forms are linked, and we can't know that semantic form will
7889 // match even if the syntactic form does.
7890 }
Mike Stump11289f42009-09-09 15:08:12 +00007891
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007892 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007893 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007894}
Mike Stump11289f42009-09-09 15:08:12 +00007895
Douglas Gregora16548e2009-08-11 05:31:07 +00007896template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007897ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007898TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007899 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007900
Douglas Gregorebe10102009-08-20 07:17:43 +00007901 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007902 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007903 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007904 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007905
Douglas Gregorebe10102009-08-20 07:17:43 +00007906 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007907 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007908 bool ExprChanged = false;
7909 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7910 DEnd = E->designators_end();
7911 D != DEnd; ++D) {
7912 if (D->isFieldDesignator()) {
7913 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7914 D->getDotLoc(),
7915 D->getFieldLoc()));
7916 continue;
7917 }
Mike Stump11289f42009-09-09 15:08:12 +00007918
Douglas Gregora16548e2009-08-11 05:31:07 +00007919 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007920 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007921 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007922 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007923
7924 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007925 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007926
Douglas Gregora16548e2009-08-11 05:31:07 +00007927 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007928 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007929 continue;
7930 }
Mike Stump11289f42009-09-09 15:08:12 +00007931
Douglas Gregora16548e2009-08-11 05:31:07 +00007932 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007933 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007934 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7935 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007936 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007937
John McCalldadc5752010-08-24 06:29:42 +00007938 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007939 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007940 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007941
7942 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007943 End.get(),
7944 D->getLBracketLoc(),
7945 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007946
Douglas Gregora16548e2009-08-11 05:31:07 +00007947 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7948 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007949
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007950 ArrayExprs.push_back(Start.get());
7951 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007952 }
Mike Stump11289f42009-09-09 15:08:12 +00007953
Douglas Gregora16548e2009-08-11 05:31:07 +00007954 if (!getDerived().AlwaysRebuild() &&
7955 Init.get() == E->getInit() &&
7956 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007957 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007958
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007959 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007960 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007961 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007962}
Mike Stump11289f42009-09-09 15:08:12 +00007963
Yunzhong Gaocb779302015-06-10 00:27:52 +00007964// Seems that if TransformInitListExpr() only works on the syntactic form of an
7965// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
7966template<typename Derived>
7967ExprResult
7968TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
7969 DesignatedInitUpdateExpr *E) {
7970 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
7971 "initializer");
7972 return ExprError();
7973}
7974
7975template<typename Derived>
7976ExprResult
7977TreeTransform<Derived>::TransformNoInitExpr(
7978 NoInitExpr *E) {
7979 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
7980 return ExprError();
7981}
7982
Douglas Gregora16548e2009-08-11 05:31:07 +00007983template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007984ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007985TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007986 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007987 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007988
Douglas Gregor3da3c062009-10-28 00:29:27 +00007989 // FIXME: Will we ever have proper type location here? Will we actually
7990 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007991 QualType T = getDerived().TransformType(E->getType());
7992 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007993 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007994
Douglas Gregora16548e2009-08-11 05:31:07 +00007995 if (!getDerived().AlwaysRebuild() &&
7996 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007997 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007998
Douglas Gregora16548e2009-08-11 05:31:07 +00007999 return getDerived().RebuildImplicitValueInitExpr(T);
8000}
Mike Stump11289f42009-09-09 15:08:12 +00008001
Douglas Gregora16548e2009-08-11 05:31:07 +00008002template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008003ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008004TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008005 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8006 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008007 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008008
John McCalldadc5752010-08-24 06:29:42 +00008009 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008010 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008011 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008012
Douglas Gregora16548e2009-08-11 05:31:07 +00008013 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008014 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008015 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008016 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008017
John McCallb268a282010-08-23 23:25:46 +00008018 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008019 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008020}
8021
8022template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008023ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008024TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008025 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008026 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008027 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8028 &ArgumentChanged))
8029 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008030
Douglas Gregora16548e2009-08-11 05:31:07 +00008031 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008032 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008033 E->getRParenLoc());
8034}
Mike Stump11289f42009-09-09 15:08:12 +00008035
Douglas Gregora16548e2009-08-11 05:31:07 +00008036/// \brief Transform an address-of-label expression.
8037///
8038/// By default, the transformation of an address-of-label expression always
8039/// rebuilds the expression, so that the label identifier can be resolved to
8040/// the corresponding label statement by semantic analysis.
8041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008042ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008043TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008044 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8045 E->getLabel());
8046 if (!LD)
8047 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008048
Douglas Gregora16548e2009-08-11 05:31:07 +00008049 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008050 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008051}
Mike Stump11289f42009-09-09 15:08:12 +00008052
8053template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008054ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008055TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008056 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008057 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008058 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008059 if (SubStmt.isInvalid()) {
8060 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008061 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008062 }
Mike Stump11289f42009-09-09 15:08:12 +00008063
Douglas Gregora16548e2009-08-11 05:31:07 +00008064 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008065 SubStmt.get() == E->getSubStmt()) {
8066 // Calling this an 'error' is unintuitive, but it does the right thing.
8067 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008068 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008069 }
Mike Stump11289f42009-09-09 15:08:12 +00008070
8071 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008072 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008073 E->getRParenLoc());
8074}
Mike Stump11289f42009-09-09 15:08:12 +00008075
Douglas Gregora16548e2009-08-11 05:31:07 +00008076template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008077ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008078TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008079 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008080 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008081 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008082
John McCalldadc5752010-08-24 06:29:42 +00008083 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008084 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008085 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008086
John McCalldadc5752010-08-24 06:29:42 +00008087 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008088 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008089 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008090
Douglas Gregora16548e2009-08-11 05:31:07 +00008091 if (!getDerived().AlwaysRebuild() &&
8092 Cond.get() == E->getCond() &&
8093 LHS.get() == E->getLHS() &&
8094 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008095 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008096
Douglas Gregora16548e2009-08-11 05:31:07 +00008097 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008098 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008099 E->getRParenLoc());
8100}
Mike Stump11289f42009-09-09 15:08:12 +00008101
Douglas Gregora16548e2009-08-11 05:31:07 +00008102template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008103ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008104TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008105 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008106}
8107
8108template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008109ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008110TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008111 switch (E->getOperator()) {
8112 case OO_New:
8113 case OO_Delete:
8114 case OO_Array_New:
8115 case OO_Array_Delete:
8116 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008117
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008118 case OO_Call: {
8119 // This is a call to an object's operator().
8120 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8121
8122 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008123 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008124 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008125 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008126
8127 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008128 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8129 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008130
8131 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008132 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008133 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008134 Args))
8135 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008136
John McCallb268a282010-08-23 23:25:46 +00008137 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008138 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008139 E->getLocEnd());
8140 }
8141
8142#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8143 case OO_##Name:
8144#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8145#include "clang/Basic/OperatorKinds.def"
8146 case OO_Subscript:
8147 // Handled below.
8148 break;
8149
8150 case OO_Conditional:
8151 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008152
8153 case OO_None:
8154 case NUM_OVERLOADED_OPERATORS:
8155 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008156 }
8157
John McCalldadc5752010-08-24 06:29:42 +00008158 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008159 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008160 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008161
Richard Smithdb2630f2012-10-21 03:28:35 +00008162 ExprResult First;
8163 if (E->getOperator() == OO_Amp)
8164 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8165 else
8166 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008167 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008168 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008169
John McCalldadc5752010-08-24 06:29:42 +00008170 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008171 if (E->getNumArgs() == 2) {
8172 Second = getDerived().TransformExpr(E->getArg(1));
8173 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008174 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008175 }
Mike Stump11289f42009-09-09 15:08:12 +00008176
Douglas Gregora16548e2009-08-11 05:31:07 +00008177 if (!getDerived().AlwaysRebuild() &&
8178 Callee.get() == E->getCallee() &&
8179 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008180 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008181 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008182
Lang Hames5de91cc2012-10-02 04:45:10 +00008183 Sema::FPContractStateRAII FPContractState(getSema());
8184 getSema().FPFeatures.fp_contract = E->isFPContractable();
8185
Douglas Gregora16548e2009-08-11 05:31:07 +00008186 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8187 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008188 Callee.get(),
8189 First.get(),
8190 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008191}
Mike Stump11289f42009-09-09 15:08:12 +00008192
Douglas Gregora16548e2009-08-11 05:31:07 +00008193template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008194ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008195TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8196 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008197}
Mike Stump11289f42009-09-09 15:08:12 +00008198
Douglas Gregora16548e2009-08-11 05:31:07 +00008199template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008200ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008201TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8202 // Transform the callee.
8203 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8204 if (Callee.isInvalid())
8205 return ExprError();
8206
8207 // Transform exec config.
8208 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8209 if (EC.isInvalid())
8210 return ExprError();
8211
8212 // Transform arguments.
8213 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008214 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008215 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008216 &ArgChanged))
8217 return ExprError();
8218
8219 if (!getDerived().AlwaysRebuild() &&
8220 Callee.get() == E->getCallee() &&
8221 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008222 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008223
8224 // FIXME: Wrong source location information for the '('.
8225 SourceLocation FakeLParenLoc
8226 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8227 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008228 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008229 E->getRParenLoc(), EC.get());
8230}
8231
8232template<typename Derived>
8233ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008234TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008235 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8236 if (!Type)
8237 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008238
John McCalldadc5752010-08-24 06:29:42 +00008239 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008240 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008241 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008242 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008243
Douglas Gregora16548e2009-08-11 05:31:07 +00008244 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008245 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008246 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008247 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008248 return getDerived().RebuildCXXNamedCastExpr(
8249 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8250 Type, E->getAngleBrackets().getEnd(),
8251 // FIXME. this should be '(' location
8252 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008253}
Mike Stump11289f42009-09-09 15:08:12 +00008254
Douglas Gregora16548e2009-08-11 05:31:07 +00008255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008256ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008257TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8258 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008259}
Mike Stump11289f42009-09-09 15:08:12 +00008260
8261template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008262ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008263TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8264 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008265}
8266
Douglas Gregora16548e2009-08-11 05:31:07 +00008267template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008268ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008269TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008270 CXXReinterpretCastExpr *E) {
8271 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008272}
Mike Stump11289f42009-09-09 15:08:12 +00008273
Douglas Gregora16548e2009-08-11 05:31:07 +00008274template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008275ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008276TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8277 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008278}
Mike Stump11289f42009-09-09 15:08:12 +00008279
Douglas Gregora16548e2009-08-11 05:31:07 +00008280template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008281ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008282TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008283 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008284 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8285 if (!Type)
8286 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008287
John McCalldadc5752010-08-24 06:29:42 +00008288 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008289 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008290 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008291 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008292
Douglas Gregora16548e2009-08-11 05:31:07 +00008293 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008294 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008295 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008296 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008297
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008298 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008299 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008300 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008301 E->getRParenLoc());
8302}
Mike Stump11289f42009-09-09 15:08:12 +00008303
Douglas Gregora16548e2009-08-11 05:31:07 +00008304template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008305ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008306TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008307 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008308 TypeSourceInfo *TInfo
8309 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8310 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008311 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008312
Douglas Gregora16548e2009-08-11 05:31:07 +00008313 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008314 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008315 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008316
Douglas Gregor9da64192010-04-26 22:37:10 +00008317 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8318 E->getLocStart(),
8319 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008320 E->getLocEnd());
8321 }
Mike Stump11289f42009-09-09 15:08:12 +00008322
Eli Friedman456f0182012-01-20 01:26:23 +00008323 // We don't know whether the subexpression is potentially evaluated until
8324 // after we perform semantic analysis. We speculatively assume it is
8325 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008326 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008327 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8328 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008329
John McCalldadc5752010-08-24 06:29:42 +00008330 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008331 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008332 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008333
Douglas Gregora16548e2009-08-11 05:31:07 +00008334 if (!getDerived().AlwaysRebuild() &&
8335 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008336 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008337
Douglas Gregor9da64192010-04-26 22:37:10 +00008338 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8339 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008340 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008341 E->getLocEnd());
8342}
8343
8344template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008345ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008346TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8347 if (E->isTypeOperand()) {
8348 TypeSourceInfo *TInfo
8349 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8350 if (!TInfo)
8351 return ExprError();
8352
8353 if (!getDerived().AlwaysRebuild() &&
8354 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008355 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008356
Douglas Gregor69735112011-03-06 17:40:41 +00008357 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008358 E->getLocStart(),
8359 TInfo,
8360 E->getLocEnd());
8361 }
8362
Francois Pichet9f4f2072010-09-08 12:20:18 +00008363 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8364
8365 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8366 if (SubExpr.isInvalid())
8367 return ExprError();
8368
8369 if (!getDerived().AlwaysRebuild() &&
8370 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008371 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008372
8373 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8374 E->getLocStart(),
8375 SubExpr.get(),
8376 E->getLocEnd());
8377}
8378
8379template<typename Derived>
8380ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008381TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008382 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008383}
Mike Stump11289f42009-09-09 15:08:12 +00008384
Douglas Gregora16548e2009-08-11 05:31:07 +00008385template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008386ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008387TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008388 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008389 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008390}
Mike Stump11289f42009-09-09 15:08:12 +00008391
Douglas Gregora16548e2009-08-11 05:31:07 +00008392template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008393ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008394TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008395 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008396
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008397 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8398 // Make sure that we capture 'this'.
8399 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008400 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008401 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008402
Douglas Gregorb15af892010-01-07 23:12:05 +00008403 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008404}
Mike Stump11289f42009-09-09 15:08:12 +00008405
Douglas Gregora16548e2009-08-11 05:31:07 +00008406template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008407ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008408TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008409 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008410 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008411 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008412
Douglas Gregora16548e2009-08-11 05:31:07 +00008413 if (!getDerived().AlwaysRebuild() &&
8414 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008415 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008416
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008417 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8418 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008419}
Mike Stump11289f42009-09-09 15:08:12 +00008420
Douglas Gregora16548e2009-08-11 05:31:07 +00008421template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008422ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008423TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008424 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008425 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8426 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008427 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008428 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008429
Chandler Carruth794da4c2010-02-08 06:42:49 +00008430 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008431 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008432 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008433
Douglas Gregor033f6752009-12-23 23:03:06 +00008434 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008435}
Mike Stump11289f42009-09-09 15:08:12 +00008436
Douglas Gregora16548e2009-08-11 05:31:07 +00008437template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008438ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008439TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8440 FieldDecl *Field
8441 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8442 E->getField()));
8443 if (!Field)
8444 return ExprError();
8445
8446 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008447 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008448
8449 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8450}
8451
8452template<typename Derived>
8453ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008454TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8455 CXXScalarValueInitExpr *E) {
8456 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8457 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008458 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008459
Douglas Gregora16548e2009-08-11 05:31:07 +00008460 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008461 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008462 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008463
Chad Rosier1dcde962012-08-08 18:46:20 +00008464 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008465 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008466 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008467}
Mike Stump11289f42009-09-09 15:08:12 +00008468
Douglas Gregora16548e2009-08-11 05:31:07 +00008469template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008470ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008471TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008472 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008473 TypeSourceInfo *AllocTypeInfo
8474 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8475 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008476 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008477
Douglas Gregora16548e2009-08-11 05:31:07 +00008478 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008479 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008480 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008481 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008482
Douglas Gregora16548e2009-08-11 05:31:07 +00008483 // Transform the placement arguments (if any).
8484 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008485 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008486 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008487 E->getNumPlacementArgs(), true,
8488 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008489 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008490
Sebastian Redl6047f072012-02-16 12:22:20 +00008491 // Transform the initializer (if any).
8492 Expr *OldInit = E->getInitializer();
8493 ExprResult NewInit;
8494 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008495 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008496 if (NewInit.isInvalid())
8497 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008498
Sebastian Redl6047f072012-02-16 12:22:20 +00008499 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008500 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008501 if (E->getOperatorNew()) {
8502 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008503 getDerived().TransformDecl(E->getLocStart(),
8504 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008505 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008506 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008507 }
8508
Craig Topperc3ec1492014-05-26 06:22:03 +00008509 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008510 if (E->getOperatorDelete()) {
8511 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008512 getDerived().TransformDecl(E->getLocStart(),
8513 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008514 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008515 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008516 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008517
Douglas Gregora16548e2009-08-11 05:31:07 +00008518 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008519 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008520 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008521 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008522 OperatorNew == E->getOperatorNew() &&
8523 OperatorDelete == E->getOperatorDelete() &&
8524 !ArgumentChanged) {
8525 // Mark any declarations we need as referenced.
8526 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008527 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008528 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008529 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008530 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008531
Sebastian Redl6047f072012-02-16 12:22:20 +00008532 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008533 QualType ElementType
8534 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8535 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8536 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8537 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008538 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008539 }
8540 }
8541 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008542
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008543 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008544 }
Mike Stump11289f42009-09-09 15:08:12 +00008545
Douglas Gregor0744ef62010-09-07 21:49:58 +00008546 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008547 if (!ArraySize.get()) {
8548 // If no array size was specified, but the new expression was
8549 // instantiated with an array type (e.g., "new T" where T is
8550 // instantiated with "int[4]"), extract the outer bound from the
8551 // array type as our array size. We do this with constant and
8552 // dependently-sized array types.
8553 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8554 if (!ArrayT) {
8555 // Do nothing
8556 } else if (const ConstantArrayType *ConsArrayT
8557 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008558 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8559 SemaRef.Context.getSizeType(),
8560 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008561 AllocType = ConsArrayT->getElementType();
8562 } else if (const DependentSizedArrayType *DepArrayT
8563 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8564 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008565 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008566 AllocType = DepArrayT->getElementType();
8567 }
8568 }
8569 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008570
Douglas Gregora16548e2009-08-11 05:31:07 +00008571 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8572 E->isGlobalNew(),
8573 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008574 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008575 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008576 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008577 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008578 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008579 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008580 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008581 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008582}
Mike Stump11289f42009-09-09 15:08:12 +00008583
Douglas Gregora16548e2009-08-11 05:31:07 +00008584template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008585ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008586TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008587 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008588 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008589 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008590
Douglas Gregord2d9da02010-02-26 00:38:10 +00008591 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008592 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008593 if (E->getOperatorDelete()) {
8594 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008595 getDerived().TransformDecl(E->getLocStart(),
8596 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008597 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008598 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008599 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008600
Douglas Gregora16548e2009-08-11 05:31:07 +00008601 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008602 Operand.get() == E->getArgument() &&
8603 OperatorDelete == E->getOperatorDelete()) {
8604 // Mark any declarations we need as referenced.
8605 // FIXME: instantiation-specific.
8606 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008607 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008608
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008609 if (!E->getArgument()->isTypeDependent()) {
8610 QualType Destroyed = SemaRef.Context.getBaseElementType(
8611 E->getDestroyedType());
8612 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8613 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008614 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008615 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008616 }
8617 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008618
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008619 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008620 }
Mike Stump11289f42009-09-09 15:08:12 +00008621
Douglas Gregora16548e2009-08-11 05:31:07 +00008622 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8623 E->isGlobalDelete(),
8624 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008625 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008626}
Mike Stump11289f42009-09-09 15:08:12 +00008627
Douglas Gregora16548e2009-08-11 05:31:07 +00008628template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008629ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008630TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008631 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008632 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008633 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008634 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008635
John McCallba7bf592010-08-24 05:47:05 +00008636 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008637 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008638 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008639 E->getOperatorLoc(),
8640 E->isArrow()? tok::arrow : tok::period,
8641 ObjectTypePtr,
8642 MayBePseudoDestructor);
8643 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008644 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008645
John McCallba7bf592010-08-24 05:47:05 +00008646 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008647 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8648 if (QualifierLoc) {
8649 QualifierLoc
8650 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8651 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008652 return ExprError();
8653 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008654 CXXScopeSpec SS;
8655 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008656
Douglas Gregor678f90d2010-02-25 01:56:36 +00008657 PseudoDestructorTypeStorage Destroyed;
8658 if (E->getDestroyedTypeInfo()) {
8659 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008660 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008661 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008662 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008663 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008664 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008665 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008666 // We aren't likely to be able to resolve the identifier down to a type
8667 // now anyway, so just retain the identifier.
8668 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8669 E->getDestroyedTypeLoc());
8670 } else {
8671 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008672 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008673 *E->getDestroyedTypeIdentifier(),
8674 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008675 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008676 SS, ObjectTypePtr,
8677 false);
8678 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008679 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008680
Douglas Gregor678f90d2010-02-25 01:56:36 +00008681 Destroyed
8682 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8683 E->getDestroyedTypeLoc());
8684 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008685
Craig Topperc3ec1492014-05-26 06:22:03 +00008686 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008687 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008688 CXXScopeSpec EmptySS;
8689 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008690 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008691 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008692 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008693 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008694
John McCallb268a282010-08-23 23:25:46 +00008695 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008696 E->getOperatorLoc(),
8697 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008698 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008699 ScopeTypeInfo,
8700 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008701 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008702 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008703}
Mike Stump11289f42009-09-09 15:08:12 +00008704
Douglas Gregorad8a3362009-09-04 17:36:40 +00008705template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008706ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008707TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008708 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008709 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8710 Sema::LookupOrdinaryName);
8711
8712 // Transform all the decls.
8713 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8714 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008715 NamedDecl *InstD = static_cast<NamedDecl*>(
8716 getDerived().TransformDecl(Old->getNameLoc(),
8717 *I));
John McCall84d87672009-12-10 09:41:52 +00008718 if (!InstD) {
8719 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8720 // This can happen because of dependent hiding.
8721 if (isa<UsingShadowDecl>(*I))
8722 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008723 else {
8724 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008725 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008726 }
John McCall84d87672009-12-10 09:41:52 +00008727 }
John McCalle66edc12009-11-24 19:00:30 +00008728
8729 // Expand using declarations.
8730 if (isa<UsingDecl>(InstD)) {
8731 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008732 for (auto *I : UD->shadows())
8733 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008734 continue;
8735 }
8736
8737 R.addDecl(InstD);
8738 }
8739
8740 // Resolve a kind, but don't do any further analysis. If it's
8741 // ambiguous, the callee needs to deal with it.
8742 R.resolveKind();
8743
8744 // Rebuild the nested-name qualifier, if present.
8745 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008746 if (Old->getQualifierLoc()) {
8747 NestedNameSpecifierLoc QualifierLoc
8748 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8749 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008750 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008751
Douglas Gregor0da1d432011-02-28 20:01:57 +00008752 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008753 }
8754
Douglas Gregor9262f472010-04-27 18:19:34 +00008755 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008756 CXXRecordDecl *NamingClass
8757 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8758 Old->getNameLoc(),
8759 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008760 if (!NamingClass) {
8761 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008762 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008763 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008764
Douglas Gregorda7be082010-04-27 16:10:10 +00008765 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008766 }
8767
Abramo Bagnara7945c982012-01-27 09:46:47 +00008768 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8769
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008770 // If we have neither explicit template arguments, nor the template keyword,
8771 // it's a normal declaration name.
8772 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008773 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8774
8775 // If we have template arguments, rebuild them, then rebuild the
8776 // templateid expression.
8777 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008778 if (Old->hasExplicitTemplateArgs() &&
8779 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008780 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008781 TransArgs)) {
8782 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008783 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008784 }
John McCalle66edc12009-11-24 19:00:30 +00008785
Abramo Bagnara7945c982012-01-27 09:46:47 +00008786 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008787 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008788}
Mike Stump11289f42009-09-09 15:08:12 +00008789
Douglas Gregora16548e2009-08-11 05:31:07 +00008790template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008791ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008792TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8793 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008794 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008795 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8796 TypeSourceInfo *From = E->getArg(I);
8797 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008798 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008799 TypeLocBuilder TLB;
8800 TLB.reserve(FromTL.getFullDataSize());
8801 QualType To = getDerived().TransformType(TLB, FromTL);
8802 if (To.isNull())
8803 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008804
Douglas Gregor29c42f22012-02-24 07:38:34 +00008805 if (To == From->getType())
8806 Args.push_back(From);
8807 else {
8808 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8809 ArgChanged = true;
8810 }
8811 continue;
8812 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008813
Douglas Gregor29c42f22012-02-24 07:38:34 +00008814 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008815
Douglas Gregor29c42f22012-02-24 07:38:34 +00008816 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008817 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008818 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8819 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8820 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008821
Douglas Gregor29c42f22012-02-24 07:38:34 +00008822 // Determine whether the set of unexpanded parameter packs can and should
8823 // be expanded.
8824 bool Expand = true;
8825 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008826 Optional<unsigned> OrigNumExpansions =
8827 ExpansionTL.getTypePtr()->getNumExpansions();
8828 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008829 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8830 PatternTL.getSourceRange(),
8831 Unexpanded,
8832 Expand, RetainExpansion,
8833 NumExpansions))
8834 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008835
Douglas Gregor29c42f22012-02-24 07:38:34 +00008836 if (!Expand) {
8837 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008838 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008839 // expansion.
8840 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008841
Douglas Gregor29c42f22012-02-24 07:38:34 +00008842 TypeLocBuilder TLB;
8843 TLB.reserve(From->getTypeLoc().getFullDataSize());
8844
8845 QualType To = getDerived().TransformType(TLB, PatternTL);
8846 if (To.isNull())
8847 return ExprError();
8848
Chad Rosier1dcde962012-08-08 18:46:20 +00008849 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008850 PatternTL.getSourceRange(),
8851 ExpansionTL.getEllipsisLoc(),
8852 NumExpansions);
8853 if (To.isNull())
8854 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008855
Douglas Gregor29c42f22012-02-24 07:38:34 +00008856 PackExpansionTypeLoc ToExpansionTL
8857 = TLB.push<PackExpansionTypeLoc>(To);
8858 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8859 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8860 continue;
8861 }
8862
8863 // Expand the pack expansion by substituting for each argument in the
8864 // pack(s).
8865 for (unsigned I = 0; I != *NumExpansions; ++I) {
8866 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8867 TypeLocBuilder TLB;
8868 TLB.reserve(PatternTL.getFullDataSize());
8869 QualType To = getDerived().TransformType(TLB, PatternTL);
8870 if (To.isNull())
8871 return ExprError();
8872
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008873 if (To->containsUnexpandedParameterPack()) {
8874 To = getDerived().RebuildPackExpansionType(To,
8875 PatternTL.getSourceRange(),
8876 ExpansionTL.getEllipsisLoc(),
8877 NumExpansions);
8878 if (To.isNull())
8879 return ExprError();
8880
8881 PackExpansionTypeLoc ToExpansionTL
8882 = TLB.push<PackExpansionTypeLoc>(To);
8883 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8884 }
8885
Douglas Gregor29c42f22012-02-24 07:38:34 +00008886 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8887 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008888
Douglas Gregor29c42f22012-02-24 07:38:34 +00008889 if (!RetainExpansion)
8890 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008891
Douglas Gregor29c42f22012-02-24 07:38:34 +00008892 // If we're supposed to retain a pack expansion, do so by temporarily
8893 // forgetting the partially-substituted parameter pack.
8894 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8895
8896 TypeLocBuilder TLB;
8897 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008898
Douglas Gregor29c42f22012-02-24 07:38:34 +00008899 QualType To = getDerived().TransformType(TLB, PatternTL);
8900 if (To.isNull())
8901 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008902
8903 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008904 PatternTL.getSourceRange(),
8905 ExpansionTL.getEllipsisLoc(),
8906 NumExpansions);
8907 if (To.isNull())
8908 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008909
Douglas Gregor29c42f22012-02-24 07:38:34 +00008910 PackExpansionTypeLoc ToExpansionTL
8911 = TLB.push<PackExpansionTypeLoc>(To);
8912 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8913 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8914 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008915
Douglas Gregor29c42f22012-02-24 07:38:34 +00008916 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008917 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008918
8919 return getDerived().RebuildTypeTrait(E->getTrait(),
8920 E->getLocStart(),
8921 Args,
8922 E->getLocEnd());
8923}
8924
8925template<typename Derived>
8926ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008927TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8928 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8929 if (!T)
8930 return ExprError();
8931
8932 if (!getDerived().AlwaysRebuild() &&
8933 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008934 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008935
8936 ExprResult SubExpr;
8937 {
8938 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8939 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8940 if (SubExpr.isInvalid())
8941 return ExprError();
8942
8943 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008944 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008945 }
8946
8947 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8948 E->getLocStart(),
8949 T,
8950 SubExpr.get(),
8951 E->getLocEnd());
8952}
8953
8954template<typename Derived>
8955ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008956TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8957 ExprResult SubExpr;
8958 {
8959 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8960 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8961 if (SubExpr.isInvalid())
8962 return ExprError();
8963
8964 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008965 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008966 }
8967
8968 return getDerived().RebuildExpressionTrait(
8969 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8970}
8971
Reid Kleckner32506ed2014-06-12 23:03:48 +00008972template <typename Derived>
8973ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8974 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8975 TypeSourceInfo **RecoveryTSI) {
8976 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8977 DRE, AddrTaken, RecoveryTSI);
8978
8979 // Propagate both errors and recovered types, which return ExprEmpty.
8980 if (!NewDRE.isUsable())
8981 return NewDRE;
8982
8983 // We got an expr, wrap it up in parens.
8984 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8985 return PE;
8986 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8987 PE->getRParen());
8988}
8989
8990template <typename Derived>
8991ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8992 DependentScopeDeclRefExpr *E) {
8993 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8994 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008995}
8996
8997template<typename Derived>
8998ExprResult
8999TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9000 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009001 bool IsAddressOfOperand,
9002 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009003 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009004 NestedNameSpecifierLoc QualifierLoc
9005 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9006 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009007 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009008 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009009
John McCall31f82722010-11-12 08:19:04 +00009010 // TODO: If this is a conversion-function-id, verify that the
9011 // destination type name (if present) resolves the same way after
9012 // instantiation as it did in the local scope.
9013
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009014 DeclarationNameInfo NameInfo
9015 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9016 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009017 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009018
John McCalle66edc12009-11-24 19:00:30 +00009019 if (!E->hasExplicitTemplateArgs()) {
9020 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009021 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009022 // Note: it is sufficient to compare the Name component of NameInfo:
9023 // if name has not changed, DNLoc has not changed either.
9024 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009025 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009026
Reid Kleckner32506ed2014-06-12 23:03:48 +00009027 return getDerived().RebuildDependentScopeDeclRefExpr(
9028 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9029 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009030 }
John McCall6b51f282009-11-23 01:53:49 +00009031
9032 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009033 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9034 E->getNumTemplateArgs(),
9035 TransArgs))
9036 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009037
Reid Kleckner32506ed2014-06-12 23:03:48 +00009038 return getDerived().RebuildDependentScopeDeclRefExpr(
9039 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9040 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009041}
9042
9043template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009044ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009045TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009046 // CXXConstructExprs other than for list-initialization and
9047 // CXXTemporaryObjectExpr are always implicit, so when we have
9048 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009049 if ((E->getNumArgs() == 1 ||
9050 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009051 (!getDerived().DropCallArgument(E->getArg(0))) &&
9052 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009053 return getDerived().TransformExpr(E->getArg(0));
9054
Douglas Gregora16548e2009-08-11 05:31:07 +00009055 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9056
9057 QualType T = getDerived().TransformType(E->getType());
9058 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009059 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009060
9061 CXXConstructorDecl *Constructor
9062 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009063 getDerived().TransformDecl(E->getLocStart(),
9064 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009065 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009066 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009067
Douglas Gregora16548e2009-08-11 05:31:07 +00009068 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009069 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009070 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009071 &ArgumentChanged))
9072 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009073
Douglas Gregora16548e2009-08-11 05:31:07 +00009074 if (!getDerived().AlwaysRebuild() &&
9075 T == E->getType() &&
9076 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009077 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009078 // Mark the constructor as referenced.
9079 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009080 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009081 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009082 }
Mike Stump11289f42009-09-09 15:08:12 +00009083
Douglas Gregordb121ba2009-12-14 16:27:04 +00009084 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9085 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009086 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009087 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009088 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009089 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009090 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009091 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009092 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009093}
Mike Stump11289f42009-09-09 15:08:12 +00009094
Douglas Gregora16548e2009-08-11 05:31:07 +00009095/// \brief Transform a C++ temporary-binding expression.
9096///
Douglas Gregor363b1512009-12-24 18:51:59 +00009097/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9098/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009099template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009100ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009101TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009102 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009103}
Mike Stump11289f42009-09-09 15:08:12 +00009104
John McCall5d413782010-12-06 08:20:24 +00009105/// \brief Transform a C++ expression that contains cleanups that should
9106/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009107///
John McCall5d413782010-12-06 08:20:24 +00009108/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009109/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009110template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009111ExprResult
John McCall5d413782010-12-06 08:20:24 +00009112TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009113 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009114}
Mike Stump11289f42009-09-09 15:08:12 +00009115
Douglas Gregora16548e2009-08-11 05:31:07 +00009116template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009117ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009118TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009119 CXXTemporaryObjectExpr *E) {
9120 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9121 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009122 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009123
Douglas Gregora16548e2009-08-11 05:31:07 +00009124 CXXConstructorDecl *Constructor
9125 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009126 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009127 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009128 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009129 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009130
Douglas Gregora16548e2009-08-11 05:31:07 +00009131 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009132 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009133 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009134 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009135 &ArgumentChanged))
9136 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009137
Douglas Gregora16548e2009-08-11 05:31:07 +00009138 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009139 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009140 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009141 !ArgumentChanged) {
9142 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009143 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009144 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009145 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009146
Richard Smithd59b8322012-12-19 01:39:02 +00009147 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009148 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9149 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009150 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009151 E->getLocEnd());
9152}
Mike Stump11289f42009-09-09 15:08:12 +00009153
Douglas Gregora16548e2009-08-11 05:31:07 +00009154template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009155ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009156TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009157 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009158 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009159 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009160 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9161 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009162 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009163 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009164 CEnd = E->capture_end();
9165 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009166 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009167 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009168 EnterExpressionEvaluationContext EEEC(getSema(),
9169 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009170 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9171 C->getCapturedVar()->getInit(),
9172 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009173
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009174 if (NewExprInitResult.isInvalid())
9175 return ExprError();
9176 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009177
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009178 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009179 QualType NewInitCaptureType =
9180 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
9181 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009182 NewExprInit);
9183 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009184 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9185 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009186 }
9187
Faisal Vali2cba1332013-10-23 06:44:28 +00009188 // Transform the template parameters, and add them to the current
9189 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009190 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009191 E->getTemplateParameterList());
9192
Richard Smith01014ce2014-11-20 23:53:14 +00009193 // Transform the type of the original lambda's call operator.
9194 // The transformation MUST be done in the CurrentInstantiationScope since
9195 // it introduces a mapping of the original to the newly created
9196 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009197 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009198 {
9199 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9200 FunctionProtoTypeLoc OldCallOpFPTL =
9201 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009202
9203 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009204 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009205 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009206 QualType NewCallOpType = TransformFunctionProtoType(
9207 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009208 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9209 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9210 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009211 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009212 if (NewCallOpType.isNull())
9213 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009214 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9215 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009216 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009217
Richard Smithc38498f2015-04-27 21:27:54 +00009218 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9219 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9220 LSI->GLTemplateParameterList = TPL;
9221
Eli Friedmand564afb2012-09-19 01:18:11 +00009222 // Create the local class that will describe the lambda.
9223 CXXRecordDecl *Class
9224 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009225 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009226 /*KnownDependent=*/false,
9227 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009228 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9229
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009230 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009231 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9232 Class, E->getIntroducerRange(), NewCallOpTSI,
9233 E->getCallOperator()->getLocEnd(),
9234 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009235 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009236
Faisal Vali2cba1332013-10-23 06:44:28 +00009237 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009238 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009239
Douglas Gregorb4328232012-02-14 00:00:48 +00009240 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009241 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009242 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009243
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009244 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009245 getSema().buildLambdaScope(LSI, NewCallOperator,
9246 E->getIntroducerRange(),
9247 E->getCaptureDefault(),
9248 E->getCaptureDefaultLoc(),
9249 E->hasExplicitParameters(),
9250 E->hasExplicitResultType(),
9251 E->isMutable());
9252
9253 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009254
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009255 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009256 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009257 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009258 CEnd = E->capture_end();
9259 C != CEnd; ++C) {
9260 // When we hit the first implicit capture, tell Sema that we've finished
9261 // the list of explicit captures.
9262 if (!FinishedExplicitCaptures && C->isImplicit()) {
9263 getSema().finishLambdaExplicitCaptures(LSI);
9264 FinishedExplicitCaptures = true;
9265 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009266
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009267 // Capturing 'this' is trivial.
9268 if (C->capturesThis()) {
9269 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9270 continue;
9271 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009272 // Captured expression will be recaptured during captured variables
9273 // rebuilding.
9274 if (C->capturesVLAType())
9275 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009276
Richard Smithba71c082013-05-16 06:20:58 +00009277 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +00009278 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009279 InitCaptureInfoTy InitExprTypePair =
9280 InitCaptureExprsAndTypes[C - E->capture_begin()];
9281 ExprResult Init = InitExprTypePair.first;
9282 QualType InitQualType = InitExprTypePair.second;
9283 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009284 Invalid = true;
9285 continue;
9286 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009287 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009288 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9289 OldVD->getLocation(), InitExprTypePair.second,
9290 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009291 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009292 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009293 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009294 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009295 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009296 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009297 continue;
9298 }
9299
9300 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9301
Douglas Gregor3e308b12012-02-14 19:27:52 +00009302 // Determine the capture kind for Sema.
9303 Sema::TryCaptureKind Kind
9304 = C->isImplicit()? Sema::TryCapture_Implicit
9305 : C->getCaptureKind() == LCK_ByCopy
9306 ? Sema::TryCapture_ExplicitByVal
9307 : Sema::TryCapture_ExplicitByRef;
9308 SourceLocation EllipsisLoc;
9309 if (C->isPackExpansion()) {
9310 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9311 bool ShouldExpand = false;
9312 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009313 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009314 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9315 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009316 Unexpanded,
9317 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009318 NumExpansions)) {
9319 Invalid = true;
9320 continue;
9321 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009322
Douglas Gregor3e308b12012-02-14 19:27:52 +00009323 if (ShouldExpand) {
9324 // The transform has determined that we should perform an expansion;
9325 // transform and capture each of the arguments.
9326 // expansion of the pattern. Do so.
9327 VarDecl *Pack = C->getCapturedVar();
9328 for (unsigned I = 0; I != *NumExpansions; ++I) {
9329 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9330 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009331 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009332 Pack));
9333 if (!CapturedVar) {
9334 Invalid = true;
9335 continue;
9336 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009337
Douglas Gregor3e308b12012-02-14 19:27:52 +00009338 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009339 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9340 }
Richard Smith9467be42014-06-06 17:33:35 +00009341
9342 // FIXME: Retain a pack expansion if RetainExpansion is true.
9343
Douglas Gregor3e308b12012-02-14 19:27:52 +00009344 continue;
9345 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009346
Douglas Gregor3e308b12012-02-14 19:27:52 +00009347 EllipsisLoc = C->getEllipsisLoc();
9348 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009349
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009350 // Transform the captured variable.
9351 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009352 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009353 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009354 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009355 Invalid = true;
9356 continue;
9357 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009358
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009359 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00009360 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009361 }
9362 if (!FinishedExplicitCaptures)
9363 getSema().finishLambdaExplicitCaptures(LSI);
9364
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009365 // Enter a new evaluation context to insulate the lambda from any
9366 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009367 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009368
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009369 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +00009370 StmtResult Body =
9371 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
9372
9373 // ActOnLambda* will pop the function scope for us.
9374 FuncScopeCleanup.disable();
9375
Douglas Gregorb4328232012-02-14 00:00:48 +00009376 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +00009377 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +00009378 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009379 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009380 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009381 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009382
Richard Smithc38498f2015-04-27 21:27:54 +00009383 // Copy the LSI before ActOnFinishFunctionBody removes it.
9384 // FIXME: This is dumb. Store the lambda information somewhere that outlives
9385 // the call operator.
9386 auto LSICopy = *LSI;
9387 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
9388 /*IsInstantiation*/ true);
9389 SavedContext.pop();
9390
9391 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
9392 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +00009393}
9394
9395template<typename Derived>
9396ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009397TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009398 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009399 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9400 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009401 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009402
Douglas Gregora16548e2009-08-11 05:31:07 +00009403 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009404 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009405 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009406 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009407 &ArgumentChanged))
9408 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009409
Douglas Gregora16548e2009-08-11 05:31:07 +00009410 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009411 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009412 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009413 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009414
Douglas Gregora16548e2009-08-11 05:31:07 +00009415 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009416 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009417 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009418 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009419 E->getRParenLoc());
9420}
Mike Stump11289f42009-09-09 15:08:12 +00009421
Douglas Gregora16548e2009-08-11 05:31:07 +00009422template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009423ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009424TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009425 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009426 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009427 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009428 Expr *OldBase;
9429 QualType BaseType;
9430 QualType ObjectType;
9431 if (!E->isImplicitAccess()) {
9432 OldBase = E->getBase();
9433 Base = getDerived().TransformExpr(OldBase);
9434 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009435 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009436
John McCall2d74de92009-12-01 22:10:20 +00009437 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009438 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009439 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009440 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009441 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009442 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009443 ObjectTy,
9444 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009445 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009446 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009447
John McCallba7bf592010-08-24 05:47:05 +00009448 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009449 BaseType = ((Expr*) Base.get())->getType();
9450 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009451 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009452 BaseType = getDerived().TransformType(E->getBaseType());
9453 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9454 }
Mike Stump11289f42009-09-09 15:08:12 +00009455
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009456 // Transform the first part of the nested-name-specifier that qualifies
9457 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009458 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009459 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009460 E->getFirstQualifierFoundInScope(),
9461 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009462
Douglas Gregore16af532011-02-28 18:50:33 +00009463 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009464 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009465 QualifierLoc
9466 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9467 ObjectType,
9468 FirstQualifierInScope);
9469 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009470 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009471 }
Mike Stump11289f42009-09-09 15:08:12 +00009472
Abramo Bagnara7945c982012-01-27 09:46:47 +00009473 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9474
John McCall31f82722010-11-12 08:19:04 +00009475 // TODO: If this is a conversion-function-id, verify that the
9476 // destination type name (if present) resolves the same way after
9477 // instantiation as it did in the local scope.
9478
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009479 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009480 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009481 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009482 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009483
John McCall2d74de92009-12-01 22:10:20 +00009484 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009485 // This is a reference to a member without an explicitly-specified
9486 // template argument list. Optimize for this common case.
9487 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009488 Base.get() == OldBase &&
9489 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009490 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009491 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009492 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009493 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009494
John McCallb268a282010-08-23 23:25:46 +00009495 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009496 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009497 E->isArrow(),
9498 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009499 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009500 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009501 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009502 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009503 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009504 }
9505
John McCall6b51f282009-11-23 01:53:49 +00009506 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009507 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9508 E->getNumTemplateArgs(),
9509 TransArgs))
9510 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009511
John McCallb268a282010-08-23 23:25:46 +00009512 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009513 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009514 E->isArrow(),
9515 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009516 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009517 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009518 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009519 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009520 &TransArgs);
9521}
9522
9523template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009524ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009525TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009526 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009527 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009528 QualType BaseType;
9529 if (!Old->isImplicitAccess()) {
9530 Base = getDerived().TransformExpr(Old->getBase());
9531 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009532 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009533 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009534 Old->isArrow());
9535 if (Base.isInvalid())
9536 return ExprError();
9537 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009538 } else {
9539 BaseType = getDerived().TransformType(Old->getBaseType());
9540 }
John McCall10eae182009-11-30 22:42:35 +00009541
Douglas Gregor0da1d432011-02-28 20:01:57 +00009542 NestedNameSpecifierLoc QualifierLoc;
9543 if (Old->getQualifierLoc()) {
9544 QualifierLoc
9545 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9546 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009547 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009548 }
9549
Abramo Bagnara7945c982012-01-27 09:46:47 +00009550 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9551
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009552 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009553 Sema::LookupOrdinaryName);
9554
9555 // Transform all the decls.
9556 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9557 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009558 NamedDecl *InstD = static_cast<NamedDecl*>(
9559 getDerived().TransformDecl(Old->getMemberLoc(),
9560 *I));
John McCall84d87672009-12-10 09:41:52 +00009561 if (!InstD) {
9562 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9563 // This can happen because of dependent hiding.
9564 if (isa<UsingShadowDecl>(*I))
9565 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009566 else {
9567 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009568 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009569 }
John McCall84d87672009-12-10 09:41:52 +00009570 }
John McCall10eae182009-11-30 22:42:35 +00009571
9572 // Expand using declarations.
9573 if (isa<UsingDecl>(InstD)) {
9574 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009575 for (auto *I : UD->shadows())
9576 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009577 continue;
9578 }
9579
9580 R.addDecl(InstD);
9581 }
9582
9583 R.resolveKind();
9584
Douglas Gregor9262f472010-04-27 18:19:34 +00009585 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009586 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009587 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009588 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009589 Old->getMemberLoc(),
9590 Old->getNamingClass()));
9591 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009592 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009593
Douglas Gregorda7be082010-04-27 16:10:10 +00009594 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009595 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009596
John McCall10eae182009-11-30 22:42:35 +00009597 TemplateArgumentListInfo TransArgs;
9598 if (Old->hasExplicitTemplateArgs()) {
9599 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9600 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009601 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9602 Old->getNumTemplateArgs(),
9603 TransArgs))
9604 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009605 }
John McCall38836f02010-01-15 08:34:02 +00009606
9607 // FIXME: to do this check properly, we will need to preserve the
9608 // first-qualifier-in-scope here, just in case we had a dependent
9609 // base (and therefore couldn't do the check) and a
9610 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009611 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009612
John McCallb268a282010-08-23 23:25:46 +00009613 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009614 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009615 Old->getOperatorLoc(),
9616 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009617 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009618 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009619 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009620 R,
9621 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009622 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009623}
9624
9625template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009626ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009627TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009628 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009629 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9630 if (SubExpr.isInvalid())
9631 return ExprError();
9632
9633 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009634 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009635
9636 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9637}
9638
9639template<typename Derived>
9640ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009641TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009642 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9643 if (Pattern.isInvalid())
9644 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009645
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009646 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009647 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009648
Douglas Gregorb8840002011-01-14 21:20:45 +00009649 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9650 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009651}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009652
9653template<typename Derived>
9654ExprResult
9655TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9656 // If E is not value-dependent, then nothing will change when we transform it.
9657 // Note: This is an instantiation-centric view.
9658 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009659 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009660
9661 // Note: None of the implementations of TryExpandParameterPacks can ever
9662 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009663 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009664 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9665 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009666 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009667 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009668 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009669 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009670 ShouldExpand, RetainExpansion,
9671 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009672 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009673
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009674 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009675 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009676
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009677 NamedDecl *Pack = E->getPack();
9678 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009679 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009680 Pack));
9681 if (!Pack)
9682 return ExprError();
9683 }
9684
Chad Rosier1dcde962012-08-08 18:46:20 +00009685
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009686 // We now know the length of the parameter pack, so build a new expression
9687 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009688 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9689 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009690 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009691}
9692
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009693template<typename Derived>
9694ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009695TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9696 SubstNonTypeTemplateParmPackExpr *E) {
9697 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009698 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009699}
9700
9701template<typename Derived>
9702ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009703TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9704 SubstNonTypeTemplateParmExpr *E) {
9705 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009706 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009707}
9708
9709template<typename Derived>
9710ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009711TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9712 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009713 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009714}
9715
9716template<typename Derived>
9717ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009718TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9719 MaterializeTemporaryExpr *E) {
9720 return getDerived().TransformExpr(E->GetTemporaryExpr());
9721}
Chad Rosier1dcde962012-08-08 18:46:20 +00009722
Douglas Gregorfe314812011-06-21 17:03:29 +00009723template<typename Derived>
9724ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +00009725TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
9726 Expr *Pattern = E->getPattern();
9727
9728 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9729 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
9730 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9731
9732 // Determine whether the set of unexpanded parameter packs can and should
9733 // be expanded.
9734 bool Expand = true;
9735 bool RetainExpansion = false;
9736 Optional<unsigned> NumExpansions;
9737 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
9738 Pattern->getSourceRange(),
9739 Unexpanded,
9740 Expand, RetainExpansion,
9741 NumExpansions))
9742 return true;
9743
9744 if (!Expand) {
9745 // Do not expand any packs here, just transform and rebuild a fold
9746 // expression.
9747 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9748
9749 ExprResult LHS =
9750 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
9751 if (LHS.isInvalid())
9752 return true;
9753
9754 ExprResult RHS =
9755 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
9756 if (RHS.isInvalid())
9757 return true;
9758
9759 if (!getDerived().AlwaysRebuild() &&
9760 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
9761 return E;
9762
9763 return getDerived().RebuildCXXFoldExpr(
9764 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
9765 RHS.get(), E->getLocEnd());
9766 }
9767
9768 // The transform has determined that we should perform an elementwise
9769 // expansion of the pattern. Do so.
9770 ExprResult Result = getDerived().TransformExpr(E->getInit());
9771 if (Result.isInvalid())
9772 return true;
9773 bool LeftFold = E->isLeftFold();
9774
9775 // If we're retaining an expansion for a right fold, it is the innermost
9776 // component and takes the init (if any).
9777 if (!LeftFold && RetainExpansion) {
9778 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9779
9780 ExprResult Out = getDerived().TransformExpr(Pattern);
9781 if (Out.isInvalid())
9782 return true;
9783
9784 Result = getDerived().RebuildCXXFoldExpr(
9785 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
9786 Result.get(), E->getLocEnd());
9787 if (Result.isInvalid())
9788 return true;
9789 }
9790
9791 for (unsigned I = 0; I != *NumExpansions; ++I) {
9792 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
9793 getSema(), LeftFold ? I : *NumExpansions - I - 1);
9794 ExprResult Out = getDerived().TransformExpr(Pattern);
9795 if (Out.isInvalid())
9796 return true;
9797
9798 if (Out.get()->containsUnexpandedParameterPack()) {
9799 // We still have a pack; retain a pack expansion for this slice.
9800 Result = getDerived().RebuildCXXFoldExpr(
9801 E->getLocStart(),
9802 LeftFold ? Result.get() : Out.get(),
9803 E->getOperator(), E->getEllipsisLoc(),
9804 LeftFold ? Out.get() : Result.get(),
9805 E->getLocEnd());
9806 } else if (Result.isUsable()) {
9807 // We've got down to a single element; build a binary operator.
9808 Result = getDerived().RebuildBinaryOperator(
9809 E->getEllipsisLoc(), E->getOperator(),
9810 LeftFold ? Result.get() : Out.get(),
9811 LeftFold ? Out.get() : Result.get());
9812 } else
9813 Result = Out;
9814
9815 if (Result.isInvalid())
9816 return true;
9817 }
9818
9819 // If we're retaining an expansion for a left fold, it is the outermost
9820 // component and takes the complete expansion so far as its init (if any).
9821 if (LeftFold && RetainExpansion) {
9822 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9823
9824 ExprResult Out = getDerived().TransformExpr(Pattern);
9825 if (Out.isInvalid())
9826 return true;
9827
9828 Result = getDerived().RebuildCXXFoldExpr(
9829 E->getLocStart(), Result.get(),
9830 E->getOperator(), E->getEllipsisLoc(),
9831 Out.get(), E->getLocEnd());
9832 if (Result.isInvalid())
9833 return true;
9834 }
9835
9836 // If we had no init and an empty pack, and we're not retaining an expansion,
9837 // then produce a fallback value or error.
9838 if (Result.isUnset())
9839 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
9840 E->getOperator());
9841
9842 return Result;
9843}
9844
9845template<typename Derived>
9846ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009847TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9848 CXXStdInitializerListExpr *E) {
9849 return getDerived().TransformExpr(E->getSubExpr());
9850}
9851
9852template<typename Derived>
9853ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009854TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009855 return SemaRef.MaybeBindToTemporary(E);
9856}
9857
9858template<typename Derived>
9859ExprResult
9860TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009861 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009862}
9863
9864template<typename Derived>
9865ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009866TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9867 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9868 if (SubExpr.isInvalid())
9869 return ExprError();
9870
9871 if (!getDerived().AlwaysRebuild() &&
9872 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009873 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009874
9875 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009876}
9877
9878template<typename Derived>
9879ExprResult
9880TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9881 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009882 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009883 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009884 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009885 /*IsCall=*/false, Elements, &ArgChanged))
9886 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009887
Ted Kremeneke65b0862012-03-06 20:05:56 +00009888 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9889 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009890
Ted Kremeneke65b0862012-03-06 20:05:56 +00009891 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9892 Elements.data(),
9893 Elements.size());
9894}
9895
9896template<typename Derived>
9897ExprResult
9898TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009899 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009900 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009901 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009902 bool ArgChanged = false;
9903 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9904 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009905
Ted Kremeneke65b0862012-03-06 20:05:56 +00009906 if (OrigElement.isPackExpansion()) {
9907 // This key/value element is a pack expansion.
9908 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9909 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9910 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9911 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9912
9913 // Determine whether the set of unexpanded parameter packs can
9914 // and should be expanded.
9915 bool Expand = true;
9916 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009917 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9918 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009919 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9920 OrigElement.Value->getLocEnd());
9921 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9922 PatternRange,
9923 Unexpanded,
9924 Expand, RetainExpansion,
9925 NumExpansions))
9926 return ExprError();
9927
9928 if (!Expand) {
9929 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009930 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009931 // expansion.
9932 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9933 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9934 if (Key.isInvalid())
9935 return ExprError();
9936
9937 if (Key.get() != OrigElement.Key)
9938 ArgChanged = true;
9939
9940 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9941 if (Value.isInvalid())
9942 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009943
Ted Kremeneke65b0862012-03-06 20:05:56 +00009944 if (Value.get() != OrigElement.Value)
9945 ArgChanged = true;
9946
Chad Rosier1dcde962012-08-08 18:46:20 +00009947 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009948 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9949 };
9950 Elements.push_back(Expansion);
9951 continue;
9952 }
9953
9954 // Record right away that the argument was changed. This needs
9955 // to happen even if the array expands to nothing.
9956 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009957
Ted Kremeneke65b0862012-03-06 20:05:56 +00009958 // The transform has determined that we should perform an elementwise
9959 // expansion of the pattern. Do so.
9960 for (unsigned I = 0; I != *NumExpansions; ++I) {
9961 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9962 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9963 if (Key.isInvalid())
9964 return ExprError();
9965
9966 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9967 if (Value.isInvalid())
9968 return ExprError();
9969
Chad Rosier1dcde962012-08-08 18:46:20 +00009970 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009971 Key.get(), Value.get(), SourceLocation(), NumExpansions
9972 };
9973
9974 // If any unexpanded parameter packs remain, we still have a
9975 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +00009976 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +00009977 if (Key.get()->containsUnexpandedParameterPack() ||
9978 Value.get()->containsUnexpandedParameterPack())
9979 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009980
Ted Kremeneke65b0862012-03-06 20:05:56 +00009981 Elements.push_back(Element);
9982 }
9983
Richard Smith9467be42014-06-06 17:33:35 +00009984 // FIXME: Retain a pack expansion if RetainExpansion is true.
9985
Ted Kremeneke65b0862012-03-06 20:05:56 +00009986 // We've finished with this pack expansion.
9987 continue;
9988 }
9989
9990 // Transform and check key.
9991 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9992 if (Key.isInvalid())
9993 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009994
Ted Kremeneke65b0862012-03-06 20:05:56 +00009995 if (Key.get() != OrigElement.Key)
9996 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009997
Ted Kremeneke65b0862012-03-06 20:05:56 +00009998 // Transform and check value.
9999 ExprResult Value
10000 = getDerived().TransformExpr(OrigElement.Value);
10001 if (Value.isInvalid())
10002 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010003
Ted Kremeneke65b0862012-03-06 20:05:56 +000010004 if (Value.get() != OrigElement.Value)
10005 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010006
10007 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010008 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010009 };
10010 Elements.push_back(Element);
10011 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010012
Ted Kremeneke65b0862012-03-06 20:05:56 +000010013 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10014 return SemaRef.MaybeBindToTemporary(E);
10015
10016 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
10017 Elements.data(),
10018 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +000010019}
10020
Mike Stump11289f42009-09-09 15:08:12 +000010021template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010022ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010023TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010024 TypeSourceInfo *EncodedTypeInfo
10025 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10026 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010027 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010028
Douglas Gregora16548e2009-08-11 05:31:07 +000010029 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010030 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010031 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010032
10033 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010034 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010035 E->getRParenLoc());
10036}
Mike Stump11289f42009-09-09 15:08:12 +000010037
Douglas Gregora16548e2009-08-11 05:31:07 +000010038template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010039ExprResult TreeTransform<Derived>::
10040TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010041 // This is a kind of implicit conversion, and it needs to get dropped
10042 // and recomputed for the same general reasons that ImplicitCastExprs
10043 // do, as well a more specific one: this expression is only valid when
10044 // it appears *immediately* as an argument expression.
10045 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010046}
10047
10048template<typename Derived>
10049ExprResult TreeTransform<Derived>::
10050TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010051 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010052 = getDerived().TransformType(E->getTypeInfoAsWritten());
10053 if (!TSInfo)
10054 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010055
John McCall31168b02011-06-15 23:02:42 +000010056 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010057 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010058 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010059
John McCall31168b02011-06-15 23:02:42 +000010060 if (!getDerived().AlwaysRebuild() &&
10061 TSInfo == E->getTypeInfoAsWritten() &&
10062 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010063 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010064
John McCall31168b02011-06-15 23:02:42 +000010065 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010066 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010067 Result.get());
10068}
10069
10070template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010071ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010072TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010073 // Transform arguments.
10074 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010075 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010076 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010077 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010078 &ArgChanged))
10079 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010080
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010081 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10082 // Class message: transform the receiver type.
10083 TypeSourceInfo *ReceiverTypeInfo
10084 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10085 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010086 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010087
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010088 // If nothing changed, just retain the existing message send.
10089 if (!getDerived().AlwaysRebuild() &&
10090 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010091 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010092
10093 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010094 SmallVector<SourceLocation, 16> SelLocs;
10095 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010096 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10097 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010098 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010099 E->getMethodDecl(),
10100 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010101 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010102 E->getRightLoc());
10103 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010104 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10105 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10106 // Build a new class message send to 'super'.
10107 SmallVector<SourceLocation, 16> SelLocs;
10108 E->getSelectorLocs(SelLocs);
10109 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10110 E->getSelector(),
10111 SelLocs,
10112 E->getMethodDecl(),
10113 E->getLeftLoc(),
10114 Args,
10115 E->getRightLoc());
10116 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010117
10118 // Instance message: transform the receiver
10119 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10120 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010121 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010122 = getDerived().TransformExpr(E->getInstanceReceiver());
10123 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010124 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010125
10126 // If nothing changed, just retain the existing message send.
10127 if (!getDerived().AlwaysRebuild() &&
10128 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010129 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010130
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010131 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010132 SmallVector<SourceLocation, 16> SelLocs;
10133 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010134 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010135 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010136 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010137 E->getMethodDecl(),
10138 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010139 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010140 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010141}
10142
Mike Stump11289f42009-09-09 15:08:12 +000010143template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010144ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010145TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010146 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010147}
10148
Mike Stump11289f42009-09-09 15:08:12 +000010149template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010150ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010151TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010152 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010153}
10154
Mike Stump11289f42009-09-09 15:08:12 +000010155template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010156ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010157TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010158 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010159 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010160 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010161 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010162
10163 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010164
Douglas Gregord51d90d2010-04-26 20:11:03 +000010165 // If nothing changed, just retain the existing expression.
10166 if (!getDerived().AlwaysRebuild() &&
10167 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010168 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010169
John McCallb268a282010-08-23 23:25:46 +000010170 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010171 E->getLocation(),
10172 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010173}
10174
Mike Stump11289f42009-09-09 15:08:12 +000010175template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010176ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010177TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010178 // 'super' and types never change. Property never changes. Just
10179 // retain the existing expression.
10180 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010181 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010182
Douglas Gregor9faee212010-04-26 20:47:02 +000010183 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010184 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010185 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010186 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010187
Douglas Gregor9faee212010-04-26 20:47:02 +000010188 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010189
Douglas Gregor9faee212010-04-26 20:47:02 +000010190 // If nothing changed, just retain the existing expression.
10191 if (!getDerived().AlwaysRebuild() &&
10192 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010193 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010194
John McCallb7bd14f2010-12-02 01:19:52 +000010195 if (E->isExplicitProperty())
10196 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10197 E->getExplicitProperty(),
10198 E->getLocation());
10199
10200 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010201 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010202 E->getImplicitPropertyGetter(),
10203 E->getImplicitPropertySetter(),
10204 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010205}
10206
Mike Stump11289f42009-09-09 15:08:12 +000010207template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010208ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010209TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10210 // Transform the base expression.
10211 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10212 if (Base.isInvalid())
10213 return ExprError();
10214
10215 // Transform the key expression.
10216 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10217 if (Key.isInvalid())
10218 return ExprError();
10219
10220 // If nothing changed, just retain the existing expression.
10221 if (!getDerived().AlwaysRebuild() &&
10222 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010223 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010224
Chad Rosier1dcde962012-08-08 18:46:20 +000010225 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010226 Base.get(), Key.get(),
10227 E->getAtIndexMethodDecl(),
10228 E->setAtIndexMethodDecl());
10229}
10230
10231template<typename Derived>
10232ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010233TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010234 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010235 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010236 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010237 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010238
Douglas Gregord51d90d2010-04-26 20:11:03 +000010239 // If nothing changed, just retain the existing expression.
10240 if (!getDerived().AlwaysRebuild() &&
10241 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010242 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010243
John McCallb268a282010-08-23 23:25:46 +000010244 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010245 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010246 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010247}
10248
Mike Stump11289f42009-09-09 15:08:12 +000010249template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010250ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010251TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010252 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010253 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010254 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010255 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010256 SubExprs, &ArgumentChanged))
10257 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010258
Douglas Gregora16548e2009-08-11 05:31:07 +000010259 if (!getDerived().AlwaysRebuild() &&
10260 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010261 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010262
Douglas Gregora16548e2009-08-11 05:31:07 +000010263 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010264 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010265 E->getRParenLoc());
10266}
10267
Mike Stump11289f42009-09-09 15:08:12 +000010268template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010269ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010270TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10271 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10272 if (SrcExpr.isInvalid())
10273 return ExprError();
10274
10275 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10276 if (!Type)
10277 return ExprError();
10278
10279 if (!getDerived().AlwaysRebuild() &&
10280 Type == E->getTypeSourceInfo() &&
10281 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010282 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010283
10284 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10285 SrcExpr.get(), Type,
10286 E->getRParenLoc());
10287}
10288
10289template<typename Derived>
10290ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010291TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010292 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010293
Craig Topperc3ec1492014-05-26 06:22:03 +000010294 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010295 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10296
10297 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010298 blockScope->TheDecl->setBlockMissingReturnType(
10299 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010300
Chris Lattner01cf8db2011-07-20 06:58:45 +000010301 SmallVector<ParmVarDecl*, 4> params;
10302 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010303
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010304 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010305 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
10306 oldBlock->param_begin(),
10307 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010308 nullptr, paramTypes, &params)) {
10309 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010310 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010311 }
John McCall490112f2011-02-04 18:33:18 +000010312
Jordan Rosea0a86be2013-03-08 22:25:36 +000010313 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000010314 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000010315 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000010316
Jordan Rose5c382722013-03-08 21:51:21 +000010317 QualType functionType =
10318 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010319 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000010320 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000010321
10322 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000010323 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000010324 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000010325
10326 if (!oldBlock->blockMissingReturnType()) {
10327 blockScope->HasImplicitReturnType = false;
10328 blockScope->ReturnType = exprResultType;
10329 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010330
John McCall3882ace2011-01-05 12:14:39 +000010331 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000010332 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010333 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010334 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000010335 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010336 }
John McCall3882ace2011-01-05 12:14:39 +000010337
John McCall490112f2011-02-04 18:33:18 +000010338#ifndef NDEBUG
10339 // In builds with assertions, make sure that we captured everything we
10340 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010341 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010342 for (const auto &I : oldBlock->captures()) {
10343 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010344
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010345 // Ignore parameter packs.
10346 if (isa<ParmVarDecl>(oldCapture) &&
10347 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10348 continue;
John McCall490112f2011-02-04 18:33:18 +000010349
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010350 VarDecl *newCapture =
10351 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10352 oldCapture));
10353 assert(blockScope->CaptureMap.count(newCapture));
10354 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010355 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010356 }
10357#endif
10358
10359 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010360 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010361}
10362
Mike Stump11289f42009-09-09 15:08:12 +000010363template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010364ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010365TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010366 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010367}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010368
10369template<typename Derived>
10370ExprResult
10371TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010372 QualType RetTy = getDerived().TransformType(E->getType());
10373 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010374 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010375 SubExprs.reserve(E->getNumSubExprs());
10376 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10377 SubExprs, &ArgumentChanged))
10378 return ExprError();
10379
10380 if (!getDerived().AlwaysRebuild() &&
10381 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010382 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010383
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010384 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010385 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010386}
Chad Rosier1dcde962012-08-08 18:46:20 +000010387
Douglas Gregora16548e2009-08-11 05:31:07 +000010388//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010389// Type reconstruction
10390//===----------------------------------------------------------------------===//
10391
Mike Stump11289f42009-09-09 15:08:12 +000010392template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010393QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10394 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010395 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010396 getDerived().getBaseEntity());
10397}
10398
Mike Stump11289f42009-09-09 15:08:12 +000010399template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010400QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10401 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010402 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010403 getDerived().getBaseEntity());
10404}
10405
Mike Stump11289f42009-09-09 15:08:12 +000010406template<typename Derived>
10407QualType
John McCall70dd5f62009-10-30 00:06:24 +000010408TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10409 bool WrittenAsLValue,
10410 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010411 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010412 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010413}
10414
10415template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010416QualType
John McCall70dd5f62009-10-30 00:06:24 +000010417TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10418 QualType ClassType,
10419 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010420 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10421 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010422}
10423
10424template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010425QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010426TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10427 ArrayType::ArraySizeModifier SizeMod,
10428 const llvm::APInt *Size,
10429 Expr *SizeExpr,
10430 unsigned IndexTypeQuals,
10431 SourceRange BracketsRange) {
10432 if (SizeExpr || !Size)
10433 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10434 IndexTypeQuals, BracketsRange,
10435 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010436
10437 QualType Types[] = {
10438 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10439 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10440 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010441 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010442 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010443 QualType SizeType;
10444 for (unsigned I = 0; I != NumTypes; ++I)
10445 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10446 SizeType = Types[I];
10447 break;
10448 }
Mike Stump11289f42009-09-09 15:08:12 +000010449
Eli Friedman9562f392012-01-25 23:20:27 +000010450 // Note that we can return a VariableArrayType here in the case where
10451 // the element type was a dependent VariableArrayType.
10452 IntegerLiteral *ArraySize
10453 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10454 /*FIXME*/BracketsRange.getBegin());
10455 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010456 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010457 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010458}
Mike Stump11289f42009-09-09 15:08:12 +000010459
Douglas Gregord6ff3322009-08-04 16:50:30 +000010460template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010461QualType
10462TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010463 ArrayType::ArraySizeModifier SizeMod,
10464 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010465 unsigned IndexTypeQuals,
10466 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010467 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010468 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010469}
10470
10471template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010472QualType
Mike Stump11289f42009-09-09 15:08:12 +000010473TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010474 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010475 unsigned IndexTypeQuals,
10476 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010477 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010478 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010479}
Mike Stump11289f42009-09-09 15:08:12 +000010480
Douglas Gregord6ff3322009-08-04 16:50:30 +000010481template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010482QualType
10483TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010484 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010485 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010486 unsigned IndexTypeQuals,
10487 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010488 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010489 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010490 IndexTypeQuals, BracketsRange);
10491}
10492
10493template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010494QualType
10495TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010496 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010497 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010498 unsigned IndexTypeQuals,
10499 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010500 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010501 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010502 IndexTypeQuals, BracketsRange);
10503}
10504
10505template<typename Derived>
10506QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010507 unsigned NumElements,
10508 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010509 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010510 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010511}
Mike Stump11289f42009-09-09 15:08:12 +000010512
Douglas Gregord6ff3322009-08-04 16:50:30 +000010513template<typename Derived>
10514QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10515 unsigned NumElements,
10516 SourceLocation AttributeLoc) {
10517 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10518 NumElements, true);
10519 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010520 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10521 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010522 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010523}
Mike Stump11289f42009-09-09 15:08:12 +000010524
Douglas Gregord6ff3322009-08-04 16:50:30 +000010525template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010526QualType
10527TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010528 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010529 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010530 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010531}
Mike Stump11289f42009-09-09 15:08:12 +000010532
Douglas Gregord6ff3322009-08-04 16:50:30 +000010533template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010534QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10535 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010536 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010537 const FunctionProtoType::ExtProtoInfo &EPI) {
10538 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010539 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010540 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010541 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010542}
Mike Stump11289f42009-09-09 15:08:12 +000010543
Douglas Gregord6ff3322009-08-04 16:50:30 +000010544template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010545QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10546 return SemaRef.Context.getFunctionNoProtoType(T);
10547}
10548
10549template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010550QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10551 assert(D && "no decl found");
10552 if (D->isInvalidDecl()) return QualType();
10553
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010554 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010555 TypeDecl *Ty;
10556 if (isa<UsingDecl>(D)) {
10557 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010558 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010559 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10560
10561 // A valid resolved using typename decl points to exactly one type decl.
10562 assert(++Using->shadow_begin() == Using->shadow_end());
10563 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010564
John McCallb96ec562009-12-04 22:46:56 +000010565 } else {
10566 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10567 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10568 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10569 }
10570
10571 return SemaRef.Context.getTypeDeclType(Ty);
10572}
10573
10574template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010575QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10576 SourceLocation Loc) {
10577 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010578}
10579
10580template<typename Derived>
10581QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10582 return SemaRef.Context.getTypeOfType(Underlying);
10583}
10584
10585template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010586QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10587 SourceLocation Loc) {
10588 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010589}
10590
10591template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010592QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10593 UnaryTransformType::UTTKind UKind,
10594 SourceLocation Loc) {
10595 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10596}
10597
10598template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010599QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010600 TemplateName Template,
10601 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010602 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010603 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010604}
Mike Stump11289f42009-09-09 15:08:12 +000010605
Douglas Gregor1135c352009-08-06 05:28:30 +000010606template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010607QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10608 SourceLocation KWLoc) {
10609 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10610}
10611
10612template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010613TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010614TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010615 bool TemplateKW,
10616 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010617 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010618 Template);
10619}
10620
10621template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010622TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010623TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10624 const IdentifierInfo &Name,
10625 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010626 QualType ObjectType,
10627 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010628 UnqualifiedId TemplateName;
10629 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010630 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010631 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010632 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010633 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010634 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010635 /*EnteringContext=*/false,
10636 Template);
John McCall31f82722010-11-12 08:19:04 +000010637 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010638}
Mike Stump11289f42009-09-09 15:08:12 +000010639
Douglas Gregora16548e2009-08-11 05:31:07 +000010640template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010641TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010642TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010643 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010644 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010645 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010646 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010647 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010648 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010649 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010650 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010651 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010652 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010653 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010654 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010655 /*EnteringContext=*/false,
10656 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010657 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010658}
Chad Rosier1dcde962012-08-08 18:46:20 +000010659
Douglas Gregor71395fa2009-11-04 00:56:37 +000010660template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010661ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010662TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10663 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010664 Expr *OrigCallee,
10665 Expr *First,
10666 Expr *Second) {
10667 Expr *Callee = OrigCallee->IgnoreParenCasts();
10668 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010669
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010670 if (First->getObjectKind() == OK_ObjCProperty) {
10671 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10672 if (BinaryOperator::isAssignmentOp(Opc))
10673 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10674 First, Second);
10675 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10676 if (Result.isInvalid())
10677 return ExprError();
10678 First = Result.get();
10679 }
10680
10681 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10682 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10683 if (Result.isInvalid())
10684 return ExprError();
10685 Second = Result.get();
10686 }
10687
Douglas Gregora16548e2009-08-11 05:31:07 +000010688 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010689 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010690 if (!First->getType()->isOverloadableType() &&
10691 !Second->getType()->isOverloadableType())
10692 return getSema().CreateBuiltinArraySubscriptExpr(First,
10693 Callee->getLocStart(),
10694 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010695 } else if (Op == OO_Arrow) {
10696 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010697 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10698 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010699 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010700 // The argument is not of overloadable type, so try to create a
10701 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010702 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010703 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010704
John McCallb268a282010-08-23 23:25:46 +000010705 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010706 }
10707 } else {
John McCallb268a282010-08-23 23:25:46 +000010708 if (!First->getType()->isOverloadableType() &&
10709 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010710 // Neither of the arguments is an overloadable type, so try to
10711 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010712 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010713 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010714 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010715 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010716 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010717
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010718 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010719 }
10720 }
Mike Stump11289f42009-09-09 15:08:12 +000010721
10722 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010723 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010724 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010725
John McCallb268a282010-08-23 23:25:46 +000010726 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010727 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010728 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010729 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010730 // If we've resolved this to a particular non-member function, just call
10731 // that function. If we resolved it to a member function,
10732 // CreateOverloaded* will find that function for us.
10733 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10734 if (!isa<CXXMethodDecl>(ND))
10735 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000010736 }
Mike Stump11289f42009-09-09 15:08:12 +000010737
Douglas Gregora16548e2009-08-11 05:31:07 +000010738 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000010739 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000010740 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000010741
Douglas Gregora16548e2009-08-11 05:31:07 +000010742 // Create the overloaded operator invocation for unary operators.
10743 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000010744 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010745 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000010746 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010747 }
Mike Stump11289f42009-09-09 15:08:12 +000010748
Douglas Gregore9d62932011-07-15 16:25:15 +000010749 if (Op == OO_Subscript) {
10750 SourceLocation LBrace;
10751 SourceLocation RBrace;
10752
10753 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000010754 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000010755 LBrace = SourceLocation::getFromRawEncoding(
10756 NameLoc.CXXOperatorName.BeginOpNameLoc);
10757 RBrace = SourceLocation::getFromRawEncoding(
10758 NameLoc.CXXOperatorName.EndOpNameLoc);
10759 } else {
10760 LBrace = Callee->getLocStart();
10761 RBrace = OpLoc;
10762 }
10763
10764 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10765 First, Second);
10766 }
Sebastian Redladba46e2009-10-29 20:17:01 +000010767
Douglas Gregora16548e2009-08-11 05:31:07 +000010768 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000010769 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010770 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000010771 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10772 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010773 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010774
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010775 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010776}
Mike Stump11289f42009-09-09 15:08:12 +000010777
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010778template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010779ExprResult
John McCallb268a282010-08-23 23:25:46 +000010780TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010781 SourceLocation OperatorLoc,
10782 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010783 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010784 TypeSourceInfo *ScopeType,
10785 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010786 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010787 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010788 QualType BaseType = Base->getType();
10789 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010790 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010791 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010792 !BaseType->getAs<PointerType>()->getPointeeType()
10793 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010794 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000010795 return SemaRef.BuildPseudoDestructorExpr(
10796 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
10797 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010798 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010799
Douglas Gregor678f90d2010-02-25 01:56:36 +000010800 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010801 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10802 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10803 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10804 NameInfo.setNamedTypeInfo(DestroyedType);
10805
Richard Smith8e4a3862012-05-15 06:15:11 +000010806 // The scope type is now known to be a valid nested name specifier
10807 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000010808 if (ScopeType) {
10809 if (!ScopeType->getType()->getAs<TagType>()) {
10810 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
10811 diag::err_expected_class_or_namespace)
10812 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
10813 return ExprError();
10814 }
10815 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
10816 CCLoc);
10817 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010818
Abramo Bagnara7945c982012-01-27 09:46:47 +000010819 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010820 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010821 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010822 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010823 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010824 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010825 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010826}
10827
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010828template<typename Derived>
10829StmtResult
10830TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010831 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010832 CapturedDecl *CD = S->getCapturedDecl();
10833 unsigned NumParams = CD->getNumParams();
10834 unsigned ContextParamPos = CD->getContextParamPosition();
10835 SmallVector<Sema::CapturedParamNameType, 4> Params;
10836 for (unsigned I = 0; I < NumParams; ++I) {
10837 if (I != ContextParamPos) {
10838 Params.push_back(
10839 std::make_pair(
10840 CD->getParam(I)->getName(),
10841 getDerived().TransformType(CD->getParam(I)->getType())));
10842 } else {
10843 Params.push_back(std::make_pair(StringRef(), QualType()));
10844 }
10845 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010846 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010847 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010848 StmtResult Body;
10849 {
10850 Sema::CompoundScopeRAII CompoundScope(getSema());
10851 Body = getDerived().TransformStmt(S->getCapturedStmt());
10852 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010853
10854 if (Body.isInvalid()) {
10855 getSema().ActOnCapturedRegionError();
10856 return StmtError();
10857 }
10858
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010859 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010860}
10861
Douglas Gregord6ff3322009-08-04 16:50:30 +000010862} // end namespace clang
10863
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000010864#endif