blob: 36abbb624af76fb143603db1c6009695d0fa99e4 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000016
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000101
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000106
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000114
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000119
Mike Stump11289f42009-09-09 15:08:12 +0000120public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000123
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 }
131
John McCalldadc5752010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000134
Douglas Gregord6ff3322009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000144 ///
145 /// We must always rebuild all AST nodes when performing variadic template
146 /// pack expansion, in order to avoid violating the AST invariant that each
147 /// statement node appears at most once in its containing declaration.
148 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregord6ff3322009-08-04 16:50:30 +0000150 /// \brief Returns the location of the entity being transformed, if that
151 /// information was not available elsewhere in the AST.
152 ///
Mike Stump11289f42009-09-09 15:08:12 +0000153 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000154 /// provide an alternative implementation that provides better location
155 /// information.
156 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregord6ff3322009-08-04 16:50:30 +0000158 /// \brief Returns the name of the entity being transformed, if that
159 /// information was not available elsewhere in the AST.
160 ///
161 /// By default, returns an empty name. Subclasses can provide an alternative
162 /// implementation with a more precise name.
163 DeclarationName getBaseEntity() { return DeclarationName(); }
164
Douglas Gregora16548e2009-08-11 05:31:07 +0000165 /// \brief Sets the "base" location and entity when that
166 /// information is known based on another transformation.
167 ///
168 /// By default, the source location and entity are ignored. Subclasses can
169 /// override this function to provide a customized implementation.
170 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000171
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 /// \brief RAII object that temporarily sets the base location and entity
173 /// used for reporting diagnostics in types.
174 class TemporaryBase {
175 TreeTransform &Self;
176 SourceLocation OldLocation;
177 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 public:
180 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000181 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000182 OldLocation = Self.getDerived().getBaseLocation();
183 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000184
Douglas Gregora518d5b2011-01-25 17:51:48 +0000185 if (Location.isValid())
186 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000187 }
Mike Stump11289f42009-09-09 15:08:12 +0000188
Douglas Gregora16548e2009-08-11 05:31:07 +0000189 ~TemporaryBase() {
190 Self.getDerived().setBase(OldLocation, OldEntity);
191 }
192 };
Mike Stump11289f42009-09-09 15:08:12 +0000193
194 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000195 /// transformed.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000198 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000199 /// not change. For example, template instantiation need not traverse
200 /// non-dependent types.
201 bool AlreadyTransformed(QualType T) {
202 return T.isNull();
203 }
204
Douglas Gregord196a582009-12-14 19:27:10 +0000205 /// \brief Determine whether the given call argument should be dropped, e.g.,
206 /// because it is a default argument.
207 ///
208 /// Subclasses can provide an alternative implementation of this routine to
209 /// determine which kinds of call arguments get dropped. By default,
210 /// CXXDefaultArgument nodes are dropped (prior to transformation).
211 bool DropCallArgument(Expr *E) {
212 return E->isDefaultArgument();
213 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000214
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000215 /// \brief Determine whether we should expand a pack expansion with the
216 /// given set of parameter packs into separate arguments by repeatedly
217 /// transforming the pattern.
218 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000219 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000220 /// Subclasses can override this routine to provide different behavior.
221 ///
222 /// \param EllipsisLoc The location of the ellipsis that identifies the
223 /// pack expansion.
224 ///
225 /// \param PatternRange The source range that covers the entire pattern of
226 /// the pack expansion.
227 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000228 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000229 /// pattern.
230 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// \param ShouldExpand Will be set to \c true if the transformer should
232 /// expand the corresponding pack expansions into separate arguments. When
233 /// set, \c NumExpansions must also be set.
234 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000235 /// \param RetainExpansion Whether the caller should add an unexpanded
236 /// pack expansion after all of the expanded arguments. This is used
237 /// when extending explicitly-specified template argument packs per
238 /// C++0x [temp.arg.explicit]p9.
239 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000241 /// the expanded form of the corresponding pack expansion. This is both an
242 /// input and an output parameter, which can be set by the caller if the
243 /// number of expansions is known a priori (e.g., due to a prior substitution)
244 /// and will be set by the callee when the number of expansions is known.
245 /// The callee must set this value when \c ShouldExpand is \c true; it may
246 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000247 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000248 /// \returns true if an error occurred (e.g., because the parameter packs
249 /// are to be instantiated with arguments of different lengths), false
250 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 /// must be set.
252 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
253 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000254 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000255 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000257 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000258 ShouldExpand = false;
259 return false;
260 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000261
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000262 /// \brief "Forget" about the partially-substituted pack template argument,
263 /// when performing an instantiation that must preserve the parameter pack
264 /// use.
265 ///
266 /// This routine is meant to be overridden by the template instantiator.
267 TemplateArgument ForgetPartiallySubstitutedPack() {
268 return TemplateArgument();
269 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000270
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000271 /// \brief "Remember" the partially-substituted pack template argument
272 /// after performing an instantiation that must preserve the parameter pack
273 /// use.
274 ///
275 /// This routine is meant to be overridden by the template instantiator.
276 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000277
Douglas Gregorf3010112011-01-07 16:43:16 +0000278 /// \brief Note to the derived class when a function parameter pack is
279 /// being expanded.
280 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transforms the given type into another type.
283 ///
John McCall550e0c22009-10-21 00:40:46 +0000284 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000285 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000286 /// function. This is expensive, but we don't mind, because
287 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000288 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
290 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000291 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000292
John McCall550e0c22009-10-21 00:40:46 +0000293 /// \brief Transforms the given type-with-location into a new
294 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000295 ///
John McCall550e0c22009-10-21 00:40:46 +0000296 /// By default, this routine transforms a type by delegating to the
297 /// appropriate TransformXXXType to build a new type. Subclasses
298 /// may override this function (to take over all type
299 /// transformations) or some set of the TransformXXXType functions
300 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000301 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000302
303 /// \brief Transform the given type-with-location into a new
304 /// type, collecting location information in the given builder
305 /// as necessary.
306 ///
John McCall31f82722010-11-12 08:19:04 +0000307 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000308
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000309 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000310 ///
Mike Stump11289f42009-09-09 15:08:12 +0000311 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000312 /// appropriate TransformXXXStmt function to transform a specific kind of
313 /// statement or the TransformExpr() function to transform an expression.
314 /// Subclasses may override this function to transform statements using some
315 /// other mechanism.
316 ///
317 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000318 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000319
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000320 /// \brief Transform the given statement.
321 ///
322 /// By default, this routine transforms a statement by delegating to the
323 /// appropriate TransformOMPXXXClause function to transform a specific kind
324 /// of clause. Subclasses may override this function to transform statements
325 /// using some other mechanism.
326 ///
327 /// \returns the transformed OpenMP clause.
328 OMPClause *TransformOMPClause(OMPClause *S);
329
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000330 /// \brief Transform the given attribute.
331 ///
332 /// By default, this routine transforms a statement by delegating to the
333 /// appropriate TransformXXXAttr function to transform a specific kind
334 /// of attribute. Subclasses may override this function to transform
335 /// attributed statements using some other mechanism.
336 ///
337 /// \returns the transformed attribute
338 const Attr *TransformAttr(const Attr *S);
339
340/// \brief Transform the specified attribute.
341///
342/// Subclasses should override the transformation of attributes with a pragma
343/// spelling to transform expressions stored within the attribute.
344///
345/// \returns the transformed attribute.
346#define ATTR(X)
347#define PRAGMA_SPELLING_ATTR(X) \
348 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
349#include "clang/Basic/AttrList.inc"
350
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000351 /// \brief Transform the given expression.
352 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000353 /// By default, this routine transforms an expression by delegating to the
354 /// appropriate TransformXXXExpr function to build a new expression.
355 /// Subclasses may override this function to transform expressions using some
356 /// other mechanism.
357 ///
358 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000359 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000360
Richard Smithd59b8322012-12-19 01:39:02 +0000361 /// \brief Transform the given initializer.
362 ///
363 /// By default, this routine transforms an initializer by stripping off the
364 /// semantic nodes added by initialization, then passing the result to
365 /// TransformExpr or TransformExprs.
366 ///
367 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000368 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000369
Douglas Gregora3efea12011-01-03 19:04:46 +0000370 /// \brief Transform the given list of expressions.
371 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000372 /// This routine transforms a list of expressions by invoking
373 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000374 /// support for variadic templates by expanding any pack expansions (if the
375 /// derived class permits such expansion) along the way. When pack expansions
376 /// are present, the number of outputs may not equal the number of inputs.
377 ///
378 /// \param Inputs The set of expressions to be transformed.
379 ///
380 /// \param NumInputs The number of expressions in \c Inputs.
381 ///
382 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000383 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000384 /// be.
385 ///
386 /// \param Outputs The transformed input expressions will be added to this
387 /// vector.
388 ///
389 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
390 /// due to transformation.
391 ///
392 /// \returns true if an error occurred, false otherwise.
393 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000394 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000395 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000396
Douglas Gregord6ff3322009-08-04 16:50:30 +0000397 /// \brief Transform the given declaration, which is referenced from a type
398 /// or expression.
399 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000400 /// By default, acts as the identity function on declarations, unless the
401 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000402 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000403 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000404 llvm::DenseMap<Decl *, Decl *>::iterator Known
405 = TransformedLocalDecls.find(D);
406 if (Known != TransformedLocalDecls.end())
407 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
409 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000410 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000411
Chad Rosier1dcde962012-08-08 18:46:20 +0000412 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000413 /// place them on the new declaration.
414 ///
415 /// By default, this operation does nothing. Subclasses may override this
416 /// behavior to transform attributes.
417 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000418
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000419 /// \brief Note that a local declaration has been transformed by this
420 /// transformer.
421 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000422 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000423 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
424 /// the transformer itself has to transform the declarations. This routine
425 /// can be overridden by a subclass that keeps track of such mappings.
426 void transformedLocalDecl(Decl *Old, Decl *New) {
427 TransformedLocalDecls[Old] = New;
428 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000429
Douglas Gregorebe10102009-08-20 07:17:43 +0000430 /// \brief Transform the definition of the given declaration.
431 ///
Mike Stump11289f42009-09-09 15:08:12 +0000432 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000433 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000434 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
435 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000436 }
Mike Stump11289f42009-09-09 15:08:12 +0000437
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000438 /// \brief Transform the given declaration, which was the first part of a
439 /// nested-name-specifier in a member access expression.
440 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000441 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000442 /// identifier in a nested-name-specifier of a member access expression, e.g.,
443 /// the \c T in \c x->T::member
444 ///
445 /// By default, invokes TransformDecl() to transform the declaration.
446 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000447 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
448 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000449 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000450
Douglas Gregor14454802011-02-25 02:25:35 +0000451 /// \brief Transform the given nested-name-specifier with source-location
452 /// information.
453 ///
454 /// By default, transforms all of the types and declarations within the
455 /// nested-name-specifier. Subclasses may override this function to provide
456 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000457 NestedNameSpecifierLoc
458 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
459 QualType ObjectType = QualType(),
460 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000461
Douglas Gregorf816bd72009-09-03 22:13:48 +0000462 /// \brief Transform the given declaration name.
463 ///
464 /// By default, transforms the types of conversion function, constructor,
465 /// and destructor names and then (if needed) rebuilds the declaration name.
466 /// Identifiers and selectors are returned unmodified. Sublcasses may
467 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000468 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000469 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000470
Douglas Gregord6ff3322009-08-04 16:50:30 +0000471 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000472 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000473 /// \param SS The nested-name-specifier that qualifies the template
474 /// name. This nested-name-specifier must already have been transformed.
475 ///
476 /// \param Name The template name to transform.
477 ///
478 /// \param NameLoc The source location of the template name.
479 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000480 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000481 /// access expression, this is the type of the object whose member template
482 /// is being referenced.
483 ///
484 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
485 /// also refers to a name within the current (lexical) scope, this is the
486 /// declaration it refers to.
487 ///
488 /// By default, transforms the template name by transforming the declarations
489 /// and nested-name-specifiers that occur within the template name.
490 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000491 TemplateName
492 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
493 SourceLocation NameLoc,
494 QualType ObjectType = QualType(),
495 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000496
Douglas Gregord6ff3322009-08-04 16:50:30 +0000497 /// \brief Transform the given template argument.
498 ///
Mike Stump11289f42009-09-09 15:08:12 +0000499 /// By default, this operation transforms the type, expression, or
500 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000501 /// new template argument from the transformed result. Subclasses may
502 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000503 ///
504 /// Returns true if there was an error.
505 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
506 TemplateArgumentLoc &Output);
507
Douglas Gregor62e06f22010-12-20 17:31:10 +0000508 /// \brief Transform the given set of template arguments.
509 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000510 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000511 /// in the input set using \c TransformTemplateArgument(), and appends
512 /// the transformed arguments to the output list.
513 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000514 /// Note that this overload of \c TransformTemplateArguments() is merely
515 /// a convenience function. Subclasses that wish to override this behavior
516 /// should override the iterator-based member template version.
517 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000518 /// \param Inputs The set of template arguments to be transformed.
519 ///
520 /// \param NumInputs The number of template arguments in \p Inputs.
521 ///
522 /// \param Outputs The set of transformed template arguments output by this
523 /// routine.
524 ///
525 /// Returns true if an error occurred.
526 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
527 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000528 TemplateArgumentListInfo &Outputs) {
529 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
530 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000531
532 /// \brief Transform the given set of template arguments.
533 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000534 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000535 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000536 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000537 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000538 /// \param First An iterator to the first template argument.
539 ///
540 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000541 ///
542 /// \param Outputs The set of transformed template arguments output by this
543 /// routine.
544 ///
545 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000546 template<typename InputIterator>
547 bool TransformTemplateArguments(InputIterator First,
548 InputIterator Last,
549 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000550
John McCall0ad16662009-10-29 08:12:44 +0000551 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
552 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
553 TemplateArgumentLoc &ArgLoc);
554
John McCallbcd03502009-12-07 02:54:59 +0000555 /// \brief Fakes up a TypeSourceInfo for a type.
556 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
557 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000558 getDerived().getBaseLocation());
559 }
Mike Stump11289f42009-09-09 15:08:12 +0000560
John McCall550e0c22009-10-21 00:40:46 +0000561#define ABSTRACT_TYPELOC(CLASS, PARENT)
562#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000563 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000564#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000565
Richard Smith2e321552014-11-12 02:00:47 +0000566 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000567 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
568 FunctionProtoTypeLoc TL,
569 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000570 unsigned ThisTypeQuals,
571 Fn TransformExceptionSpec);
572
573 bool TransformExceptionSpec(SourceLocation Loc,
574 FunctionProtoType::ExceptionSpecInfo &ESI,
575 SmallVectorImpl<QualType> &Exceptions,
576 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000577
David Majnemerfad8f482013-10-15 09:33:02 +0000578 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000579
Chad Rosier1dcde962012-08-08 18:46:20 +0000580 QualType
John McCall31f82722010-11-12 08:19:04 +0000581 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
582 TemplateSpecializationTypeLoc TL,
583 TemplateName Template);
584
Chad Rosier1dcde962012-08-08 18:46:20 +0000585 QualType
John McCall31f82722010-11-12 08:19:04 +0000586 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
587 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000588 TemplateName Template,
589 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000590
Nico Weberc153d242014-07-28 00:02:09 +0000591 QualType TransformDependentTemplateSpecializationType(
592 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
593 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000594
John McCall58f10c32010-03-11 09:03:00 +0000595 /// \brief Transforms the parameters of a function type into the
596 /// given vectors.
597 ///
598 /// The result vectors should be kept in sync; null entries in the
599 /// variables vector are acceptable.
600 ///
601 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000602 bool TransformFunctionTypeParams(SourceLocation Loc,
603 ParmVarDecl **Params, unsigned NumParams,
604 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000605 SmallVectorImpl<QualType> &PTypes,
606 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000607
608 /// \brief Transforms a single function-type parameter. Return null
609 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000610 ///
611 /// \param indexAdjustment - A number to add to the parameter's
612 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000613 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000614 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000615 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000616 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000617
John McCall31f82722010-11-12 08:19:04 +0000618 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000619
John McCalldadc5752010-08-24 06:29:42 +0000620 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
621 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000622
623 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000624 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000625 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
626 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000627
Faisal Vali2cba1332013-10-23 06:44:28 +0000628 TemplateParameterList *TransformTemplateParameterList(
629 TemplateParameterList *TPL) {
630 return TPL;
631 }
632
Richard Smithdb2630f2012-10-21 03:28:35 +0000633 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000634
Richard Smithdb2630f2012-10-21 03:28:35 +0000635 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000636 bool IsAddressOfOperand,
637 TypeSourceInfo **RecoveryTSI);
638
639 ExprResult TransformParenDependentScopeDeclRefExpr(
640 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
641 TypeSourceInfo **RecoveryTSI);
642
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000643 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000644
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000645// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
646// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000647#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000648 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000649 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000650#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000651 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000652 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000653#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000654#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000655
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000656#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000657 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000658 OMPClause *Transform ## Class(Class *S);
659#include "clang/Basic/OpenMPKinds.def"
660
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661 /// \brief Build a new pointer type given its pointee type.
662 ///
663 /// By default, performs semantic analysis when building the pointer type.
664 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000665 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666
667 /// \brief Build a new block pointer type given its pointee type.
668 ///
Mike Stump11289f42009-09-09 15:08:12 +0000669 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000670 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000671 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000672
John McCall70dd5f62009-10-30 00:06:24 +0000673 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000674 ///
John McCall70dd5f62009-10-30 00:06:24 +0000675 /// By default, performs semantic analysis when building the
676 /// reference type. Subclasses may override this routine to provide
677 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000678 ///
John McCall70dd5f62009-10-30 00:06:24 +0000679 /// \param LValue whether the type was written with an lvalue sigil
680 /// or an rvalue sigil.
681 QualType RebuildReferenceType(QualType ReferentType,
682 bool LValue,
683 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000684
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685 /// \brief Build a new member pointer type given the pointee type and the
686 /// class type it refers into.
687 ///
688 /// By default, performs semantic analysis when building the member pointer
689 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000690 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
691 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000692
Douglas Gregord6ff3322009-08-04 16:50:30 +0000693 /// \brief Build a new array type given the element type, size
694 /// modifier, size of the array (if known), size expression, and index type
695 /// qualifiers.
696 ///
697 /// By default, performs semantic analysis when building the array type.
698 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000699 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000700 QualType RebuildArrayType(QualType ElementType,
701 ArrayType::ArraySizeModifier SizeMod,
702 const llvm::APInt *Size,
703 Expr *SizeExpr,
704 unsigned IndexTypeQuals,
705 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000706
Douglas Gregord6ff3322009-08-04 16:50:30 +0000707 /// \brief Build a new constant array type given the element type, size
708 /// modifier, (known) size of the array, and index type qualifiers.
709 ///
710 /// By default, performs semantic analysis when building the array type.
711 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000712 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000713 ArrayType::ArraySizeModifier SizeMod,
714 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000715 unsigned IndexTypeQuals,
716 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000717
Douglas Gregord6ff3322009-08-04 16:50:30 +0000718 /// \brief Build a new incomplete array type given the element type, size
719 /// modifier, and index type qualifiers.
720 ///
721 /// By default, performs semantic analysis when building the array type.
722 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000723 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000725 unsigned IndexTypeQuals,
726 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000727
Mike Stump11289f42009-09-09 15:08:12 +0000728 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000729 /// size modifier, size expression, and index type qualifiers.
730 ///
731 /// By default, performs semantic analysis when building the array type.
732 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000733 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000734 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000735 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000736 unsigned IndexTypeQuals,
737 SourceRange BracketsRange);
738
Mike Stump11289f42009-09-09 15:08:12 +0000739 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 /// size modifier, size expression, and index type qualifiers.
741 ///
742 /// By default, performs semantic analysis when building the array type.
743 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000744 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000745 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000746 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000747 unsigned IndexTypeQuals,
748 SourceRange BracketsRange);
749
750 /// \brief Build a new vector type given the element type and
751 /// number of elements.
752 ///
753 /// By default, performs semantic analysis when building the vector type.
754 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000755 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000756 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000757
Douglas Gregord6ff3322009-08-04 16:50:30 +0000758 /// \brief Build a new extended vector type given the element type and
759 /// number of elements.
760 ///
761 /// By default, performs semantic analysis when building the vector type.
762 /// Subclasses may override this routine to provide different behavior.
763 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
764 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000765
766 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000767 /// given the element type and number of elements.
768 ///
769 /// By default, performs semantic analysis when building the vector type.
770 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000771 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000772 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000773 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000774
Douglas Gregord6ff3322009-08-04 16:50:30 +0000775 /// \brief Build a new function type.
776 ///
777 /// By default, performs semantic analysis when building the function type.
778 /// Subclasses may override this routine to provide different behavior.
779 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000780 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000781 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000782
John McCall550e0c22009-10-21 00:40:46 +0000783 /// \brief Build a new unprototyped function type.
784 QualType RebuildFunctionNoProtoType(QualType ResultType);
785
John McCallb96ec562009-12-04 22:46:56 +0000786 /// \brief Rebuild an unresolved typename type, given the decl that
787 /// the UnresolvedUsingTypenameDecl was transformed to.
788 QualType RebuildUnresolvedUsingType(Decl *D);
789
Douglas Gregord6ff3322009-08-04 16:50:30 +0000790 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000791 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000792 return SemaRef.Context.getTypeDeclType(Typedef);
793 }
794
795 /// \brief Build a new class/struct/union type.
796 QualType RebuildRecordType(RecordDecl *Record) {
797 return SemaRef.Context.getTypeDeclType(Record);
798 }
799
800 /// \brief Build a new Enum type.
801 QualType RebuildEnumType(EnumDecl *Enum) {
802 return SemaRef.Context.getTypeDeclType(Enum);
803 }
John McCallfcc33b02009-09-05 00:15:47 +0000804
Mike Stump11289f42009-09-09 15:08:12 +0000805 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000806 ///
807 /// By default, performs semantic analysis when building the typeof type.
808 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000809 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000810
Mike Stump11289f42009-09-09 15:08:12 +0000811 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000812 ///
813 /// By default, builds a new TypeOfType with the given underlying type.
814 QualType RebuildTypeOfType(QualType Underlying);
815
Alexis Hunte852b102011-05-24 22:41:36 +0000816 /// \brief Build a new unary transform type.
817 QualType RebuildUnaryTransformType(QualType BaseType,
818 UnaryTransformType::UTTKind UKind,
819 SourceLocation Loc);
820
Richard Smith74aeef52013-04-26 16:15:35 +0000821 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000822 ///
823 /// By default, performs semantic analysis when building the decltype type.
824 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000825 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000826
Richard Smith74aeef52013-04-26 16:15:35 +0000827 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000828 ///
829 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000830 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000831 // Note, IsDependent is always false here: we implicitly convert an 'auto'
832 // which has been deduced to a dependent type into an undeduced 'auto', so
833 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000834 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
835 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000836 }
837
Douglas Gregord6ff3322009-08-04 16:50:30 +0000838 /// \brief Build a new template specialization type.
839 ///
840 /// By default, performs semantic analysis when building the template
841 /// specialization type. Subclasses may override this routine to provide
842 /// different behavior.
843 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000844 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000845 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000846
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000847 /// \brief Build a new parenthesized type.
848 ///
849 /// By default, builds a new ParenType type from the inner type.
850 /// Subclasses may override this routine to provide different behavior.
851 QualType RebuildParenType(QualType InnerType) {
852 return SemaRef.Context.getParenType(InnerType);
853 }
854
Douglas Gregord6ff3322009-08-04 16:50:30 +0000855 /// \brief Build a new qualified name type.
856 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000857 /// By default, builds a new ElaboratedType type from the keyword,
858 /// the nested-name-specifier and the named type.
859 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000860 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
861 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000862 NestedNameSpecifierLoc QualifierLoc,
863 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000864 return SemaRef.Context.getElaboratedType(Keyword,
865 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000866 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000867 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000868
869 /// \brief Build a new typename type that refers to a template-id.
870 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000871 /// By default, builds a new DependentNameType type from the
872 /// nested-name-specifier and the given type. Subclasses may override
873 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000874 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000875 ElaboratedTypeKeyword Keyword,
876 NestedNameSpecifierLoc QualifierLoc,
877 const IdentifierInfo *Name,
878 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000879 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000880 // Rebuild the template name.
881 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000882 CXXScopeSpec SS;
883 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000884 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000885 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
886 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000887
Douglas Gregora7a795b2011-03-01 20:11:18 +0000888 if (InstName.isNull())
889 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000890
Douglas Gregora7a795b2011-03-01 20:11:18 +0000891 // If it's still dependent, make a dependent specialization.
892 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000893 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
894 QualifierLoc.getNestedNameSpecifier(),
895 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000896 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000897
Douglas Gregora7a795b2011-03-01 20:11:18 +0000898 // Otherwise, make an elaborated type wrapping a non-dependent
899 // specialization.
900 QualType T =
901 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
902 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000903
Craig Topperc3ec1492014-05-26 06:22:03 +0000904 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000905 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000906
907 return SemaRef.Context.getElaboratedType(Keyword,
908 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000909 T);
910 }
911
Douglas Gregord6ff3322009-08-04 16:50:30 +0000912 /// \brief Build a new typename type that refers to an identifier.
913 ///
914 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000915 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000916 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000917 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000918 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000919 NestedNameSpecifierLoc QualifierLoc,
920 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000921 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000922 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000923 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000924
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000925 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000926 // If the name is still dependent, just build a new dependent name type.
927 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000928 return SemaRef.Context.getDependentNameType(Keyword,
929 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000930 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000931 }
932
Abramo Bagnara6150c882010-05-11 21:36:43 +0000933 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000934 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000935 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000936
937 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
938
Abramo Bagnarad7548482010-05-19 21:37:53 +0000939 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000940 // into a non-dependent elaborated-type-specifier. Find the tag we're
941 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000942 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000943 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
944 if (!DC)
945 return QualType();
946
John McCallbf8c5192010-05-27 06:40:31 +0000947 if (SemaRef.RequireCompleteDeclContext(SS, DC))
948 return QualType();
949
Craig Topperc3ec1492014-05-26 06:22:03 +0000950 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000951 SemaRef.LookupQualifiedName(Result, DC);
952 switch (Result.getResultKind()) {
953 case LookupResult::NotFound:
954 case LookupResult::NotFoundInCurrentInstantiation:
955 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000956
Douglas Gregore677daf2010-03-31 22:19:08 +0000957 case LookupResult::Found:
958 Tag = Result.getAsSingle<TagDecl>();
959 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000960
Douglas Gregore677daf2010-03-31 22:19:08 +0000961 case LookupResult::FoundOverloaded:
962 case LookupResult::FoundUnresolvedValue:
963 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000964
Douglas Gregore677daf2010-03-31 22:19:08 +0000965 case LookupResult::Ambiguous:
966 // Let the LookupResult structure handle ambiguities.
967 return QualType();
968 }
969
970 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000971 // Check where the name exists but isn't a tag type and use that to emit
972 // better diagnostics.
973 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
974 SemaRef.LookupQualifiedName(Result, DC);
975 switch (Result.getResultKind()) {
976 case LookupResult::Found:
977 case LookupResult::FoundOverloaded:
978 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000979 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000980 unsigned Kind = 0;
981 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000982 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
983 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000984 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
985 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
986 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000987 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000988 default:
Nick Lewycky0c438082011-01-24 19:01:04 +0000989 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000990 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000991 break;
992 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000993 return QualType();
994 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000995
Richard Trieucaa33d32011-06-10 03:11:26 +0000996 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
997 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000998 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000999 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1000 return QualType();
1001 }
1002
1003 // Build the elaborated-type-specifier type.
1004 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001005 return SemaRef.Context.getElaboratedType(Keyword,
1006 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001007 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001008 }
Mike Stump11289f42009-09-09 15:08:12 +00001009
Douglas Gregor822d0302011-01-12 17:07:58 +00001010 /// \brief Build a new pack expansion type.
1011 ///
1012 /// By default, builds a new PackExpansionType type from the given pattern.
1013 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001014 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001015 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001016 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001017 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001018 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1019 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001020 }
1021
Eli Friedman0dfb8892011-10-06 23:00:33 +00001022 /// \brief Build a new atomic type given its value type.
1023 ///
1024 /// By default, performs semantic analysis when building the atomic type.
1025 /// Subclasses may override this routine to provide different behavior.
1026 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1027
Douglas Gregor71dc5092009-08-06 06:41:21 +00001028 /// \brief Build a new template name given a nested name specifier, a flag
1029 /// indicating whether the "template" keyword was provided, and the template
1030 /// that the template name refers to.
1031 ///
1032 /// By default, builds the new template name directly. Subclasses may override
1033 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001034 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001035 bool TemplateKW,
1036 TemplateDecl *Template);
1037
Douglas Gregor71dc5092009-08-06 06:41:21 +00001038 /// \brief Build a new template name given a nested name specifier and the
1039 /// name that is referred to as a template.
1040 ///
1041 /// By default, performs semantic analysis to determine whether the name can
1042 /// be resolved to a specific template, then builds the appropriate kind of
1043 /// template name. Subclasses may override this routine to provide different
1044 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001045 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1046 const IdentifierInfo &Name,
1047 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001048 QualType ObjectType,
1049 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001050
Douglas Gregor71395fa2009-11-04 00:56:37 +00001051 /// \brief Build a new template name given a nested name specifier and the
1052 /// overloaded operator name that is referred to as a template.
1053 ///
1054 /// By default, performs semantic analysis to determine whether the name can
1055 /// be resolved to a specific template, then builds the appropriate kind of
1056 /// template name. Subclasses may override this routine to provide different
1057 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001058 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001059 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001060 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001061 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001062
1063 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001064 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001065 ///
1066 /// By default, performs semantic analysis to determine whether the name can
1067 /// be resolved to a specific template, then builds the appropriate kind of
1068 /// template name. Subclasses may override this routine to provide different
1069 /// behavior.
1070 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1071 const TemplateArgument &ArgPack) {
1072 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1073 }
1074
Douglas Gregorebe10102009-08-20 07:17:43 +00001075 /// \brief Build a new compound statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001079 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001080 MultiStmtArg Statements,
1081 SourceLocation RBraceLoc,
1082 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001083 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001084 IsStmtExpr);
1085 }
1086
1087 /// \brief Build a new case statement.
1088 ///
1089 /// By default, performs semantic analysis to build the new statement.
1090 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001091 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001092 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001093 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001094 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001095 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001096 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001097 ColonLoc);
1098 }
Mike Stump11289f42009-09-09 15:08:12 +00001099
Douglas Gregorebe10102009-08-20 07:17:43 +00001100 /// \brief Attach the body to a new case statement.
1101 ///
1102 /// By default, performs semantic analysis to build the new statement.
1103 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001104 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001105 getSema().ActOnCaseStmtBody(S, Body);
1106 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001107 }
Mike Stump11289f42009-09-09 15:08:12 +00001108
Douglas Gregorebe10102009-08-20 07:17:43 +00001109 /// \brief Build a new default statement.
1110 ///
1111 /// By default, performs semantic analysis to build the new statement.
1112 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001113 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001114 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001115 Stmt *SubStmt) {
1116 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001117 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001118 }
Mike Stump11289f42009-09-09 15:08:12 +00001119
Douglas Gregorebe10102009-08-20 07:17:43 +00001120 /// \brief Build a new label statement.
1121 ///
1122 /// By default, performs semantic analysis to build the new statement.
1123 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001124 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1125 SourceLocation ColonLoc, Stmt *SubStmt) {
1126 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001127 }
Mike Stump11289f42009-09-09 15:08:12 +00001128
Richard Smithc202b282012-04-14 00:33:13 +00001129 /// \brief Build a new label statement.
1130 ///
1131 /// By default, performs semantic analysis to build the new statement.
1132 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001133 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1134 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001135 Stmt *SubStmt) {
1136 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1137 }
1138
Douglas Gregorebe10102009-08-20 07:17:43 +00001139 /// \brief Build a new "if" statement.
1140 ///
1141 /// By default, performs semantic analysis to build the new statement.
1142 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001143 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001144 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001145 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001146 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001147 }
Mike Stump11289f42009-09-09 15:08:12 +00001148
Douglas Gregorebe10102009-08-20 07:17:43 +00001149 /// \brief Start building a new switch statement.
1150 ///
1151 /// By default, performs semantic analysis to build the new statement.
1152 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001153 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001154 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001155 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001156 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001157 }
Mike Stump11289f42009-09-09 15:08:12 +00001158
Douglas Gregorebe10102009-08-20 07:17:43 +00001159 /// \brief Attach the body to the switch statement.
1160 ///
1161 /// By default, performs semantic analysis to build the new statement.
1162 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001163 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001164 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001165 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001166 }
1167
1168 /// \brief Build a new while statement.
1169 ///
1170 /// By default, performs semantic analysis to build the new statement.
1171 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001172 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1173 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001174 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001175 }
Mike Stump11289f42009-09-09 15:08:12 +00001176
Douglas Gregorebe10102009-08-20 07:17:43 +00001177 /// \brief Build a new do-while statement.
1178 ///
1179 /// By default, performs semantic analysis to build the new statement.
1180 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001181 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001182 SourceLocation WhileLoc, SourceLocation LParenLoc,
1183 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001184 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1185 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001186 }
1187
1188 /// \brief Build a new for statement.
1189 ///
1190 /// By default, performs semantic analysis to build the new statement.
1191 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001192 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001193 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001194 VarDecl *CondVar, Sema::FullExprArg Inc,
1195 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001196 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001197 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001198 }
Mike Stump11289f42009-09-09 15:08:12 +00001199
Douglas Gregorebe10102009-08-20 07:17:43 +00001200 /// \brief Build a new goto statement.
1201 ///
1202 /// By default, performs semantic analysis to build the new statement.
1203 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001204 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1205 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001206 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001207 }
1208
1209 /// \brief Build a new indirect goto statement.
1210 ///
1211 /// By default, performs semantic analysis to build the new statement.
1212 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001213 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001214 SourceLocation StarLoc,
1215 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001216 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001217 }
Mike Stump11289f42009-09-09 15:08:12 +00001218
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 /// \brief Build a new return statement.
1220 ///
1221 /// By default, performs semantic analysis to build the new statement.
1222 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001223 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001224 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001225 }
Mike Stump11289f42009-09-09 15:08:12 +00001226
Douglas Gregorebe10102009-08-20 07:17:43 +00001227 /// \brief Build a new declaration statement.
1228 ///
1229 /// By default, performs semantic analysis to build the new statement.
1230 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001231 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001232 SourceLocation StartLoc, SourceLocation EndLoc) {
1233 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001234 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001235 }
Mike Stump11289f42009-09-09 15:08:12 +00001236
Anders Carlssonaaeef072010-01-24 05:50:09 +00001237 /// \brief Build a new inline asm statement.
1238 ///
1239 /// By default, performs semantic analysis to build the new statement.
1240 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001241 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1242 bool IsVolatile, unsigned NumOutputs,
1243 unsigned NumInputs, IdentifierInfo **Names,
1244 MultiExprArg Constraints, MultiExprArg Exprs,
1245 Expr *AsmString, MultiExprArg Clobbers,
1246 SourceLocation RParenLoc) {
1247 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1248 NumInputs, Names, Constraints, Exprs,
1249 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001250 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001251
Chad Rosier32503022012-06-11 20:47:18 +00001252 /// \brief Build a new MS style inline asm statement.
1253 ///
1254 /// By default, performs semantic analysis to build the new statement.
1255 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001256 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001257 ArrayRef<Token> AsmToks,
1258 StringRef AsmString,
1259 unsigned NumOutputs, unsigned NumInputs,
1260 ArrayRef<StringRef> Constraints,
1261 ArrayRef<StringRef> Clobbers,
1262 ArrayRef<Expr*> Exprs,
1263 SourceLocation EndLoc) {
1264 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1265 NumOutputs, NumInputs,
1266 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001267 }
1268
James Dennett2a4d13c2012-06-15 07:13:21 +00001269 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001270 ///
1271 /// By default, performs semantic analysis to build the new statement.
1272 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001273 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001274 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001275 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001276 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001277 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001278 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001279 }
1280
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001281 /// \brief Rebuild an Objective-C exception declaration.
1282 ///
1283 /// By default, performs semantic analysis to build the new declaration.
1284 /// Subclasses may override this routine to provide different behavior.
1285 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1286 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001287 return getSema().BuildObjCExceptionDecl(TInfo, T,
1288 ExceptionDecl->getInnerLocStart(),
1289 ExceptionDecl->getLocation(),
1290 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001291 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001292
James Dennett2a4d13c2012-06-15 07:13:21 +00001293 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001294 ///
1295 /// By default, performs semantic analysis to build the new statement.
1296 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001297 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001298 SourceLocation RParenLoc,
1299 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001300 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001301 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001302 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001303 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001304
James Dennett2a4d13c2012-06-15 07:13:21 +00001305 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001306 ///
1307 /// By default, performs semantic analysis to build the new statement.
1308 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001309 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001310 Stmt *Body) {
1311 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001312 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001313
James Dennett2a4d13c2012-06-15 07:13:21 +00001314 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001315 ///
1316 /// By default, performs semantic analysis to build the new statement.
1317 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001318 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001319 Expr *Operand) {
1320 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001321 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001322
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001323 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001324 ///
1325 /// By default, performs semantic analysis to build the new statement.
1326 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001327 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001328 DeclarationNameInfo DirName,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001329 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001330 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001331 SourceLocation EndLoc) {
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001332 return getSema().ActOnOpenMPExecutableDirective(Kind, DirName, Clauses,
1333 AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001334 }
1335
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001336 /// \brief Build a new OpenMP 'if' clause.
1337 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001338 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001339 /// Subclasses may override this routine to provide different behavior.
1340 OMPClause *RebuildOMPIfClause(Expr *Condition,
1341 SourceLocation StartLoc,
1342 SourceLocation LParenLoc,
1343 SourceLocation EndLoc) {
1344 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1345 LParenLoc, EndLoc);
1346 }
1347
Alexey Bataev3778b602014-07-17 07:32:53 +00001348 /// \brief Build a new OpenMP 'final' clause.
1349 ///
1350 /// By default, performs semantic analysis to build the new OpenMP clause.
1351 /// Subclasses may override this routine to provide different behavior.
1352 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1353 SourceLocation LParenLoc,
1354 SourceLocation EndLoc) {
1355 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1356 EndLoc);
1357 }
1358
Alexey Bataev568a8332014-03-06 06:15:19 +00001359 /// \brief Build a new OpenMP 'num_threads' clause.
1360 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001361 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001362 /// Subclasses may override this routine to provide different behavior.
1363 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1364 SourceLocation StartLoc,
1365 SourceLocation LParenLoc,
1366 SourceLocation EndLoc) {
1367 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1368 LParenLoc, EndLoc);
1369 }
1370
Alexey Bataev62c87d22014-03-21 04:51:18 +00001371 /// \brief Build a new OpenMP 'safelen' clause.
1372 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001373 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001374 /// Subclasses may override this routine to provide different behavior.
1375 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1376 SourceLocation LParenLoc,
1377 SourceLocation EndLoc) {
1378 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1379 }
1380
Alexander Musman8bd31e62014-05-27 15:12:19 +00001381 /// \brief Build a new OpenMP 'collapse' clause.
1382 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001383 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001384 /// Subclasses may override this routine to provide different behavior.
1385 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1386 SourceLocation LParenLoc,
1387 SourceLocation EndLoc) {
1388 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1389 EndLoc);
1390 }
1391
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001392 /// \brief Build a new OpenMP 'default' clause.
1393 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001394 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001395 /// Subclasses may override this routine to provide different behavior.
1396 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1397 SourceLocation KindKwLoc,
1398 SourceLocation StartLoc,
1399 SourceLocation LParenLoc,
1400 SourceLocation EndLoc) {
1401 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1402 StartLoc, LParenLoc, EndLoc);
1403 }
1404
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001405 /// \brief Build a new OpenMP 'proc_bind' clause.
1406 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001407 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001408 /// Subclasses may override this routine to provide different behavior.
1409 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1410 SourceLocation KindKwLoc,
1411 SourceLocation StartLoc,
1412 SourceLocation LParenLoc,
1413 SourceLocation EndLoc) {
1414 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1415 StartLoc, LParenLoc, EndLoc);
1416 }
1417
Alexey Bataev56dafe82014-06-20 07:16:17 +00001418 /// \brief Build a new OpenMP 'schedule' clause.
1419 ///
1420 /// By default, performs semantic analysis to build the new OpenMP clause.
1421 /// Subclasses may override this routine to provide different behavior.
1422 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1423 Expr *ChunkSize,
1424 SourceLocation StartLoc,
1425 SourceLocation LParenLoc,
1426 SourceLocation KindLoc,
1427 SourceLocation CommaLoc,
1428 SourceLocation EndLoc) {
1429 return getSema().ActOnOpenMPScheduleClause(
1430 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1431 }
1432
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001433 /// \brief Build a new OpenMP 'private' clause.
1434 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001435 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001436 /// Subclasses may override this routine to provide different behavior.
1437 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1438 SourceLocation StartLoc,
1439 SourceLocation LParenLoc,
1440 SourceLocation EndLoc) {
1441 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1442 EndLoc);
1443 }
1444
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001445 /// \brief Build a new OpenMP 'firstprivate' clause.
1446 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001447 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001448 /// Subclasses may override this routine to provide different behavior.
1449 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1450 SourceLocation StartLoc,
1451 SourceLocation LParenLoc,
1452 SourceLocation EndLoc) {
1453 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1454 EndLoc);
1455 }
1456
Alexander Musman1bb328c2014-06-04 13:06:39 +00001457 /// \brief Build a new OpenMP 'lastprivate' clause.
1458 ///
1459 /// By default, performs semantic analysis to build the new OpenMP clause.
1460 /// Subclasses may override this routine to provide different behavior.
1461 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1462 SourceLocation StartLoc,
1463 SourceLocation LParenLoc,
1464 SourceLocation EndLoc) {
1465 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1466 EndLoc);
1467 }
1468
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001469 /// \brief Build a new OpenMP 'shared' clause.
1470 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001471 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001472 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001473 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1474 SourceLocation StartLoc,
1475 SourceLocation LParenLoc,
1476 SourceLocation EndLoc) {
1477 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1478 EndLoc);
1479 }
1480
Alexey Bataevc5e02582014-06-16 07:08:35 +00001481 /// \brief Build a new OpenMP 'reduction' clause.
1482 ///
1483 /// By default, performs semantic analysis to build the new statement.
1484 /// Subclasses may override this routine to provide different behavior.
1485 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1486 SourceLocation StartLoc,
1487 SourceLocation LParenLoc,
1488 SourceLocation ColonLoc,
1489 SourceLocation EndLoc,
1490 CXXScopeSpec &ReductionIdScopeSpec,
1491 const DeclarationNameInfo &ReductionId) {
1492 return getSema().ActOnOpenMPReductionClause(
1493 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1494 ReductionId);
1495 }
1496
Alexander Musman8dba6642014-04-22 13:09:42 +00001497 /// \brief Build a new OpenMP 'linear' clause.
1498 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001499 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001500 /// Subclasses may override this routine to provide different behavior.
1501 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1502 SourceLocation StartLoc,
1503 SourceLocation LParenLoc,
1504 SourceLocation ColonLoc,
1505 SourceLocation EndLoc) {
1506 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1507 ColonLoc, EndLoc);
1508 }
1509
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001510 /// \brief Build a new OpenMP 'aligned' clause.
1511 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001512 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001513 /// Subclasses may override this routine to provide different behavior.
1514 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1515 SourceLocation StartLoc,
1516 SourceLocation LParenLoc,
1517 SourceLocation ColonLoc,
1518 SourceLocation EndLoc) {
1519 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1520 LParenLoc, ColonLoc, EndLoc);
1521 }
1522
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001523 /// \brief Build a new OpenMP 'copyin' clause.
1524 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001525 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001526 /// Subclasses may override this routine to provide different behavior.
1527 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1528 SourceLocation StartLoc,
1529 SourceLocation LParenLoc,
1530 SourceLocation EndLoc) {
1531 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1532 EndLoc);
1533 }
1534
Alexey Bataevbae9a792014-06-27 10:37:06 +00001535 /// \brief Build a new OpenMP 'copyprivate' clause.
1536 ///
1537 /// By default, performs semantic analysis to build the new OpenMP clause.
1538 /// Subclasses may override this routine to provide different behavior.
1539 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1540 SourceLocation StartLoc,
1541 SourceLocation LParenLoc,
1542 SourceLocation EndLoc) {
1543 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1544 EndLoc);
1545 }
1546
Alexey Bataev6125da92014-07-21 11:26:11 +00001547 /// \brief Build a new OpenMP 'flush' pseudo clause.
1548 ///
1549 /// By default, performs semantic analysis to build the new OpenMP clause.
1550 /// Subclasses may override this routine to provide different behavior.
1551 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1552 SourceLocation StartLoc,
1553 SourceLocation LParenLoc,
1554 SourceLocation EndLoc) {
1555 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1556 EndLoc);
1557 }
1558
James Dennett2a4d13c2012-06-15 07:13:21 +00001559 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001560 ///
1561 /// By default, performs semantic analysis to build the new statement.
1562 /// Subclasses may override this routine to provide different behavior.
1563 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1564 Expr *object) {
1565 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1566 }
1567
James Dennett2a4d13c2012-06-15 07:13:21 +00001568 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001569 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001570 /// By default, performs semantic analysis to build the new statement.
1571 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001572 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001573 Expr *Object, Stmt *Body) {
1574 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001575 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001576
James Dennett2a4d13c2012-06-15 07:13:21 +00001577 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001578 ///
1579 /// By default, performs semantic analysis to build the new statement.
1580 /// Subclasses may override this routine to provide different behavior.
1581 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1582 Stmt *Body) {
1583 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1584 }
John McCall53848232011-07-27 01:07:15 +00001585
Douglas Gregorf68a5082010-04-22 23:10:45 +00001586 /// \brief Build a new Objective-C fast enumeration statement.
1587 ///
1588 /// By default, performs semantic analysis to build the new statement.
1589 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001590 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001591 Stmt *Element,
1592 Expr *Collection,
1593 SourceLocation RParenLoc,
1594 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001595 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001596 Element,
John McCallb268a282010-08-23 23:25:46 +00001597 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001598 RParenLoc);
1599 if (ForEachStmt.isInvalid())
1600 return StmtError();
1601
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001602 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001603 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001604
Douglas Gregorebe10102009-08-20 07:17:43 +00001605 /// \brief Build a new C++ exception declaration.
1606 ///
1607 /// By default, performs semantic analysis to build the new decaration.
1608 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001609 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001610 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001611 SourceLocation StartLoc,
1612 SourceLocation IdLoc,
1613 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001614 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001615 StartLoc, IdLoc, Id);
1616 if (Var)
1617 getSema().CurContext->addDecl(Var);
1618 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001619 }
1620
1621 /// \brief Build a new C++ catch statement.
1622 ///
1623 /// By default, performs semantic analysis to build the new statement.
1624 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001625 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001626 VarDecl *ExceptionDecl,
1627 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001628 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1629 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001630 }
Mike Stump11289f42009-09-09 15:08:12 +00001631
Douglas Gregorebe10102009-08-20 07:17:43 +00001632 /// \brief Build a new C++ try statement.
1633 ///
1634 /// By default, performs semantic analysis to build the new statement.
1635 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001636 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1637 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001638 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001639 }
Mike Stump11289f42009-09-09 15:08:12 +00001640
Richard Smith02e85f32011-04-14 22:09:26 +00001641 /// \brief Build a new C++0x range-based for statement.
1642 ///
1643 /// By default, performs semantic analysis to build the new statement.
1644 /// Subclasses may override this routine to provide different behavior.
1645 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1646 SourceLocation ColonLoc,
1647 Stmt *Range, Stmt *BeginEnd,
1648 Expr *Cond, Expr *Inc,
1649 Stmt *LoopVar,
1650 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001651 // If we've just learned that the range is actually an Objective-C
1652 // collection, treat this as an Objective-C fast enumeration loop.
1653 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1654 if (RangeStmt->isSingleDecl()) {
1655 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001656 if (RangeVar->isInvalidDecl())
1657 return StmtError();
1658
Douglas Gregorf7106af2013-04-08 18:40:13 +00001659 Expr *RangeExpr = RangeVar->getInit();
1660 if (!RangeExpr->isTypeDependent() &&
1661 RangeExpr->getType()->isObjCObjectPointerType())
1662 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1663 RParenLoc);
1664 }
1665 }
1666 }
1667
Richard Smith02e85f32011-04-14 22:09:26 +00001668 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001669 Cond, Inc, LoopVar, RParenLoc,
1670 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001671 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001672
1673 /// \brief Build a new C++0x range-based for statement.
1674 ///
1675 /// By default, performs semantic analysis to build the new statement.
1676 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001677 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001678 bool IsIfExists,
1679 NestedNameSpecifierLoc QualifierLoc,
1680 DeclarationNameInfo NameInfo,
1681 Stmt *Nested) {
1682 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1683 QualifierLoc, NameInfo, Nested);
1684 }
1685
Richard Smith02e85f32011-04-14 22:09:26 +00001686 /// \brief Attach body to a C++0x range-based for statement.
1687 ///
1688 /// By default, performs semantic analysis to finish the new statement.
1689 /// Subclasses may override this routine to provide different behavior.
1690 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1691 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1692 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001693
David Majnemerfad8f482013-10-15 09:33:02 +00001694 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001695 Stmt *TryBlock, Stmt *Handler) {
1696 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001697 }
1698
David Majnemerfad8f482013-10-15 09:33:02 +00001699 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001700 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001701 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001702 }
1703
David Majnemerfad8f482013-10-15 09:33:02 +00001704 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1705 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001706 }
1707
Alexey Bataevec474782014-10-09 08:45:04 +00001708 /// \brief Build a new predefined expression.
1709 ///
1710 /// By default, performs semantic analysis to build the new expression.
1711 /// Subclasses may override this routine to provide different behavior.
1712 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1713 PredefinedExpr::IdentType IT) {
1714 return getSema().BuildPredefinedExpr(Loc, IT);
1715 }
1716
Douglas Gregora16548e2009-08-11 05:31:07 +00001717 /// \brief Build a new expression that references a declaration.
1718 ///
1719 /// By default, performs semantic analysis to build the new expression.
1720 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001721 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001722 LookupResult &R,
1723 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001724 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1725 }
1726
1727
1728 /// \brief Build a new expression that references a declaration.
1729 ///
1730 /// By default, performs semantic analysis to build the new expression.
1731 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001732 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001733 ValueDecl *VD,
1734 const DeclarationNameInfo &NameInfo,
1735 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001736 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001737 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001738
1739 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001740
1741 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001742 }
Mike Stump11289f42009-09-09 15:08:12 +00001743
Douglas Gregora16548e2009-08-11 05:31:07 +00001744 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001745 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001746 /// By default, performs semantic analysis to build the new expression.
1747 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001748 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001749 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001750 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001751 }
1752
Douglas Gregorad8a3362009-09-04 17:36:40 +00001753 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001754 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001755 /// By default, performs semantic analysis to build the new expression.
1756 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001757 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001758 SourceLocation OperatorLoc,
1759 bool isArrow,
1760 CXXScopeSpec &SS,
1761 TypeSourceInfo *ScopeType,
1762 SourceLocation CCLoc,
1763 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001764 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001765
Douglas Gregora16548e2009-08-11 05:31:07 +00001766 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001767 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001768 /// By default, performs semantic analysis to build the new expression.
1769 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001770 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001771 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001772 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001773 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001774 }
Mike Stump11289f42009-09-09 15:08:12 +00001775
Douglas Gregor882211c2010-04-28 22:16:22 +00001776 /// \brief Build a new builtin offsetof expression.
1777 ///
1778 /// By default, performs semantic analysis to build the new expression.
1779 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001780 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001781 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001782 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001783 unsigned NumComponents,
1784 SourceLocation RParenLoc) {
1785 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1786 NumComponents, RParenLoc);
1787 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001788
1789 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001790 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001791 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 /// By default, performs semantic analysis to build the new expression.
1793 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001794 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1795 SourceLocation OpLoc,
1796 UnaryExprOrTypeTrait ExprKind,
1797 SourceRange R) {
1798 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001799 }
1800
Peter Collingbournee190dee2011-03-11 19:24:49 +00001801 /// \brief Build a new sizeof, alignof or vec step expression with an
1802 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001803 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 /// By default, performs semantic analysis to build the new expression.
1805 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001806 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1807 UnaryExprOrTypeTrait ExprKind,
1808 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001809 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001810 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001811 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001812 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001813
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001814 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001815 }
Mike Stump11289f42009-09-09 15:08:12 +00001816
Douglas Gregora16548e2009-08-11 05:31:07 +00001817 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001818 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001819 /// By default, performs semantic analysis to build the new expression.
1820 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001821 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001822 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001823 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001824 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001825 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001826 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001827 RBracketLoc);
1828 }
1829
1830 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001831 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001832 /// By default, performs semantic analysis to build the new expression.
1833 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001834 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001835 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001836 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001837 Expr *ExecConfig = nullptr) {
1838 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001839 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001840 }
1841
1842 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001843 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 /// By default, performs semantic analysis to build the new expression.
1845 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001846 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001847 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001848 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001849 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001850 const DeclarationNameInfo &MemberNameInfo,
1851 ValueDecl *Member,
1852 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001853 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001854 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001855 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1856 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001857 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001858 // We have a reference to an unnamed field. This is always the
1859 // base of an anonymous struct/union member access, i.e. the
1860 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001861 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001862 assert(Member->getType()->isRecordType() &&
1863 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001864
Richard Smithcab9a7d2011-10-26 19:06:56 +00001865 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001866 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001867 QualifierLoc.getNestedNameSpecifier(),
1868 FoundDecl, Member);
1869 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001870 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001871 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001872 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001873 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001874 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001875 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001876 cast<FieldDecl>(Member)->getType(),
1877 VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001878 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001879 }
Mike Stump11289f42009-09-09 15:08:12 +00001880
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001881 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001882 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001883
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001884 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001885 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001886
John McCall16df1e52010-03-30 21:47:33 +00001887 // FIXME: this involves duplicating earlier analysis in a lot of
1888 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001889 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001890 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001891 R.resolveKind();
1892
John McCallb268a282010-08-23 23:25:46 +00001893 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001894 SS, TemplateKWLoc,
1895 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001896 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001897 }
Mike Stump11289f42009-09-09 15:08:12 +00001898
Douglas Gregora16548e2009-08-11 05:31:07 +00001899 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001900 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001901 /// By default, performs semantic analysis to build the new expression.
1902 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001903 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001904 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001905 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001906 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001907 }
1908
1909 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001910 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001911 /// By default, performs semantic analysis to build the new expression.
1912 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001913 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001914 SourceLocation QuestionLoc,
1915 Expr *LHS,
1916 SourceLocation ColonLoc,
1917 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001918 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1919 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001920 }
1921
Douglas Gregora16548e2009-08-11 05:31:07 +00001922 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001923 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001924 /// By default, performs semantic analysis to build the new expression.
1925 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001926 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001927 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001929 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001930 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001931 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001932 }
Mike Stump11289f42009-09-09 15:08:12 +00001933
Douglas Gregora16548e2009-08-11 05:31:07 +00001934 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001935 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001936 /// By default, performs semantic analysis to build the new expression.
1937 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001938 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001939 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001941 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001942 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001943 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 }
Mike Stump11289f42009-09-09 15:08:12 +00001945
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001947 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 /// By default, performs semantic analysis to build the new expression.
1949 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001950 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 SourceLocation OpLoc,
1952 SourceLocation AccessorLoc,
1953 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001954
John McCall10eae182009-11-30 22:42:35 +00001955 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001956 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001957 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001958 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001959 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001960 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001961 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001962 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001963 }
Mike Stump11289f42009-09-09 15:08:12 +00001964
Douglas Gregora16548e2009-08-11 05:31:07 +00001965 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001966 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 /// By default, performs semantic analysis to build the new expression.
1968 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001969 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001970 MultiExprArg Inits,
1971 SourceLocation RBraceLoc,
1972 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001973 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001974 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001975 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001976 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001977
Douglas Gregord3d93062009-11-09 17:16:50 +00001978 // Patch in the result type we were given, which may have been computed
1979 // when the initial InitListExpr was built.
1980 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1981 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001982 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 }
Mike Stump11289f42009-09-09 15:08:12 +00001984
Douglas Gregora16548e2009-08-11 05:31:07 +00001985 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001986 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001987 /// By default, performs semantic analysis to build the new expression.
1988 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001989 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001990 MultiExprArg ArrayExprs,
1991 SourceLocation EqualOrColonLoc,
1992 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001993 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001994 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001996 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001997 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001998 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001999
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002000 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002001 }
Mike Stump11289f42009-09-09 15:08:12 +00002002
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002004 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002005 /// By default, builds the implicit value initialization without performing
2006 /// any semantic analysis. Subclasses may override this routine to provide
2007 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002008 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002009 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002010 }
Mike Stump11289f42009-09-09 15:08:12 +00002011
Douglas Gregora16548e2009-08-11 05:31:07 +00002012 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002013 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002014 /// By default, performs semantic analysis to build the new expression.
2015 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002016 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002017 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002018 SourceLocation RParenLoc) {
2019 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002020 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002021 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002022 }
2023
2024 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002025 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002026 /// By default, performs semantic analysis to build the new expression.
2027 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002028 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002029 MultiExprArg SubExprs,
2030 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002031 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002032 }
Mike Stump11289f42009-09-09 15:08:12 +00002033
Douglas Gregora16548e2009-08-11 05:31:07 +00002034 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002035 ///
2036 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002037 /// rather than attempting to map the label statement itself.
2038 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002039 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002040 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002041 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002042 }
Mike Stump11289f42009-09-09 15:08:12 +00002043
Douglas Gregora16548e2009-08-11 05:31:07 +00002044 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002045 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002046 /// By default, performs semantic analysis to build the new expression.
2047 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002048 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002049 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002050 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002051 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002052 }
Mike Stump11289f42009-09-09 15:08:12 +00002053
Douglas Gregora16548e2009-08-11 05:31:07 +00002054 /// \brief Build a new __builtin_choose_expr expression.
2055 ///
2056 /// By default, performs semantic analysis to build the new expression.
2057 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002058 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002059 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002060 SourceLocation RParenLoc) {
2061 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002062 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002063 RParenLoc);
2064 }
Mike Stump11289f42009-09-09 15:08:12 +00002065
Peter Collingbourne91147592011-04-15 00:35:48 +00002066 /// \brief Build a new generic selection expression.
2067 ///
2068 /// By default, performs semantic analysis to build the new expression.
2069 /// Subclasses may override this routine to provide different behavior.
2070 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2071 SourceLocation DefaultLoc,
2072 SourceLocation RParenLoc,
2073 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002074 ArrayRef<TypeSourceInfo *> Types,
2075 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002076 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002077 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002078 }
2079
Douglas Gregora16548e2009-08-11 05:31:07 +00002080 /// \brief Build a new overloaded operator call expression.
2081 ///
2082 /// By default, performs semantic analysis to build the new expression.
2083 /// The semantic analysis provides the behavior of template instantiation,
2084 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002085 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002086 /// argument-dependent lookup, etc. Subclasses may override this routine to
2087 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002088 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002089 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002090 Expr *Callee,
2091 Expr *First,
2092 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002093
2094 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002095 /// reinterpret_cast.
2096 ///
2097 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002098 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002099 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002100 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002101 Stmt::StmtClass Class,
2102 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002103 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002104 SourceLocation RAngleLoc,
2105 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002106 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002107 SourceLocation RParenLoc) {
2108 switch (Class) {
2109 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002110 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002111 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002112 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002113
2114 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002115 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002116 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002117 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002118
Douglas Gregora16548e2009-08-11 05:31:07 +00002119 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002120 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002121 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002122 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002123 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002124
Douglas Gregora16548e2009-08-11 05:31:07 +00002125 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002126 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002127 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002128 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002129
Douglas Gregora16548e2009-08-11 05:31:07 +00002130 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002131 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002132 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002133 }
Mike Stump11289f42009-09-09 15:08:12 +00002134
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 /// \brief Build a new C++ static_cast expression.
2136 ///
2137 /// By default, performs semantic analysis to build the new expression.
2138 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002139 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002140 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002141 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002142 SourceLocation RAngleLoc,
2143 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002144 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002145 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002146 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002147 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002148 SourceRange(LAngleLoc, RAngleLoc),
2149 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002150 }
2151
2152 /// \brief Build a new C++ dynamic_cast expression.
2153 ///
2154 /// By default, performs semantic analysis to build the new expression.
2155 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002156 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002157 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002158 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002159 SourceLocation RAngleLoc,
2160 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002161 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002162 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002163 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002164 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002165 SourceRange(LAngleLoc, RAngleLoc),
2166 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002167 }
2168
2169 /// \brief Build a new C++ reinterpret_cast expression.
2170 ///
2171 /// By default, performs semantic analysis to build the new expression.
2172 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002173 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002174 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002175 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002176 SourceLocation RAngleLoc,
2177 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002178 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002179 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002180 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002181 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002182 SourceRange(LAngleLoc, RAngleLoc),
2183 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 }
2185
2186 /// \brief Build a new C++ const_cast expression.
2187 ///
2188 /// By default, performs semantic analysis to build the new expression.
2189 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002190 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002191 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002192 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002193 SourceLocation RAngleLoc,
2194 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002195 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002196 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002197 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002198 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002199 SourceRange(LAngleLoc, RAngleLoc),
2200 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002201 }
Mike Stump11289f42009-09-09 15:08:12 +00002202
Douglas Gregora16548e2009-08-11 05:31:07 +00002203 /// \brief Build a new C++ functional-style cast expression.
2204 ///
2205 /// By default, performs semantic analysis to build the new expression.
2206 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002207 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2208 SourceLocation LParenLoc,
2209 Expr *Sub,
2210 SourceLocation RParenLoc) {
2211 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002212 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002213 RParenLoc);
2214 }
Mike Stump11289f42009-09-09 15:08:12 +00002215
Douglas Gregora16548e2009-08-11 05:31:07 +00002216 /// \brief Build a new C++ typeid(type) expression.
2217 ///
2218 /// By default, performs semantic analysis to build the new expression.
2219 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002220 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002221 SourceLocation TypeidLoc,
2222 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002223 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002224 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002225 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002226 }
Mike Stump11289f42009-09-09 15:08:12 +00002227
Francois Pichet9f4f2072010-09-08 12:20:18 +00002228
Douglas Gregora16548e2009-08-11 05:31:07 +00002229 /// \brief Build a new C++ typeid(expr) expression.
2230 ///
2231 /// By default, performs semantic analysis to build the new expression.
2232 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002233 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002234 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002235 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002236 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002237 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002238 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002239 }
2240
Francois Pichet9f4f2072010-09-08 12:20:18 +00002241 /// \brief Build a new C++ __uuidof(type) expression.
2242 ///
2243 /// By default, performs semantic analysis to build the new expression.
2244 /// Subclasses may override this routine to provide different behavior.
2245 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2246 SourceLocation TypeidLoc,
2247 TypeSourceInfo *Operand,
2248 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002249 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002250 RParenLoc);
2251 }
2252
2253 /// \brief Build a new C++ __uuidof(expr) expression.
2254 ///
2255 /// By default, performs semantic analysis to build the new expression.
2256 /// Subclasses may override this routine to provide different behavior.
2257 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2258 SourceLocation TypeidLoc,
2259 Expr *Operand,
2260 SourceLocation RParenLoc) {
2261 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2262 RParenLoc);
2263 }
2264
Douglas Gregora16548e2009-08-11 05:31:07 +00002265 /// \brief Build a new C++ "this" expression.
2266 ///
2267 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002268 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002269 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002270 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002271 QualType ThisType,
2272 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002273 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002274 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002275 }
2276
2277 /// \brief Build a new C++ throw expression.
2278 ///
2279 /// By default, performs semantic analysis to build the new expression.
2280 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002281 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2282 bool IsThrownVariableInScope) {
2283 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002284 }
2285
2286 /// \brief Build a new C++ default-argument expression.
2287 ///
2288 /// By default, builds a new default-argument expression, which does not
2289 /// require any semantic analysis. Subclasses may override this routine to
2290 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002291 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002292 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002293 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002294 }
2295
Richard Smith852c9db2013-04-20 22:23:05 +00002296 /// \brief Build a new C++11 default-initialization expression.
2297 ///
2298 /// By default, builds a new default field initialization expression, which
2299 /// does not require any semantic analysis. Subclasses may override this
2300 /// routine to provide different behavior.
2301 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2302 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002303 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002304 }
2305
Douglas Gregora16548e2009-08-11 05:31:07 +00002306 /// \brief Build a new C++ zero-initialization expression.
2307 ///
2308 /// By default, performs semantic analysis to build the new expression.
2309 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002310 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2311 SourceLocation LParenLoc,
2312 SourceLocation RParenLoc) {
2313 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002314 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002315 }
Mike Stump11289f42009-09-09 15:08:12 +00002316
Douglas Gregora16548e2009-08-11 05:31:07 +00002317 /// \brief Build a new C++ "new" expression.
2318 ///
2319 /// By default, performs semantic analysis to build the new expression.
2320 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002321 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002322 bool UseGlobal,
2323 SourceLocation PlacementLParen,
2324 MultiExprArg PlacementArgs,
2325 SourceLocation PlacementRParen,
2326 SourceRange TypeIdParens,
2327 QualType AllocatedType,
2328 TypeSourceInfo *AllocatedTypeInfo,
2329 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002330 SourceRange DirectInitRange,
2331 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002332 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002333 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002334 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002335 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002336 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002337 AllocatedType,
2338 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002339 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002340 DirectInitRange,
2341 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002342 }
Mike Stump11289f42009-09-09 15:08:12 +00002343
Douglas Gregora16548e2009-08-11 05:31:07 +00002344 /// \brief Build a new C++ "delete" expression.
2345 ///
2346 /// By default, performs semantic analysis to build the new expression.
2347 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002348 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002349 bool IsGlobalDelete,
2350 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002351 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002352 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002353 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002354 }
Mike Stump11289f42009-09-09 15:08:12 +00002355
Douglas Gregor29c42f22012-02-24 07:38:34 +00002356 /// \brief Build a new type trait expression.
2357 ///
2358 /// By default, performs semantic analysis to build the new expression.
2359 /// Subclasses may override this routine to provide different behavior.
2360 ExprResult RebuildTypeTrait(TypeTrait Trait,
2361 SourceLocation StartLoc,
2362 ArrayRef<TypeSourceInfo *> Args,
2363 SourceLocation RParenLoc) {
2364 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2365 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002366
John Wiegley6242b6a2011-04-28 00:16:57 +00002367 /// \brief Build a new array type trait expression.
2368 ///
2369 /// By default, performs semantic analysis to build the new expression.
2370 /// Subclasses may override this routine to provide different behavior.
2371 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2372 SourceLocation StartLoc,
2373 TypeSourceInfo *TSInfo,
2374 Expr *DimExpr,
2375 SourceLocation RParenLoc) {
2376 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2377 }
2378
John Wiegleyf9f65842011-04-25 06:54:41 +00002379 /// \brief Build a new expression trait expression.
2380 ///
2381 /// By default, performs semantic analysis to build the new expression.
2382 /// Subclasses may override this routine to provide different behavior.
2383 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2384 SourceLocation StartLoc,
2385 Expr *Queried,
2386 SourceLocation RParenLoc) {
2387 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2388 }
2389
Mike Stump11289f42009-09-09 15:08:12 +00002390 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002391 /// expression.
2392 ///
2393 /// By default, performs semantic analysis to build the new expression.
2394 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002395 ExprResult RebuildDependentScopeDeclRefExpr(
2396 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002397 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002398 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002399 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002400 bool IsAddressOfOperand,
2401 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002402 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002403 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002404
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002405 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002406 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2407 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002408
Reid Kleckner32506ed2014-06-12 23:03:48 +00002409 return getSema().BuildQualifiedDeclarationNameExpr(
2410 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002411 }
2412
2413 /// \brief Build a new template-id expression.
2414 ///
2415 /// By default, performs semantic analysis to build the new expression.
2416 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002417 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002418 SourceLocation TemplateKWLoc,
2419 LookupResult &R,
2420 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002421 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002422 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2423 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002424 }
2425
2426 /// \brief Build a new object-construction expression.
2427 ///
2428 /// By default, performs semantic analysis to build the new expression.
2429 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002430 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002431 SourceLocation Loc,
2432 CXXConstructorDecl *Constructor,
2433 bool IsElidable,
2434 MultiExprArg Args,
2435 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002436 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002437 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002438 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002439 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002440 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002441 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002442 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002443 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002444 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002445
Douglas Gregordb121ba2009-12-14 16:27:04 +00002446 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002447 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002448 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002449 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002450 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002451 RequiresZeroInit, ConstructKind,
2452 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002453 }
2454
2455 /// \brief Build a new object-construction expression.
2456 ///
2457 /// By default, performs semantic analysis to build the new expression.
2458 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002459 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2460 SourceLocation LParenLoc,
2461 MultiExprArg Args,
2462 SourceLocation RParenLoc) {
2463 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002464 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002465 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002466 RParenLoc);
2467 }
2468
2469 /// \brief Build a new object-construction expression.
2470 ///
2471 /// By default, performs semantic analysis to build the new expression.
2472 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002473 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2474 SourceLocation LParenLoc,
2475 MultiExprArg Args,
2476 SourceLocation RParenLoc) {
2477 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002478 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002479 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002480 RParenLoc);
2481 }
Mike Stump11289f42009-09-09 15:08:12 +00002482
Douglas Gregora16548e2009-08-11 05:31:07 +00002483 /// \brief Build a new member reference expression.
2484 ///
2485 /// By default, performs semantic analysis to build the new expression.
2486 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002487 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002488 QualType BaseType,
2489 bool IsArrow,
2490 SourceLocation OperatorLoc,
2491 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002492 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002493 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002494 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002495 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002496 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002497 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002498
John McCallb268a282010-08-23 23:25:46 +00002499 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002500 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002501 SS, TemplateKWLoc,
2502 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002503 MemberNameInfo,
2504 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002505 }
2506
John McCall10eae182009-11-30 22:42:35 +00002507 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002508 ///
2509 /// By default, performs semantic analysis to build the new expression.
2510 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002511 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2512 SourceLocation OperatorLoc,
2513 bool IsArrow,
2514 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002515 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002516 NamedDecl *FirstQualifierInScope,
2517 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002518 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002519 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002520 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002521
John McCallb268a282010-08-23 23:25:46 +00002522 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002523 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002524 SS, TemplateKWLoc,
2525 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002526 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002527 }
Mike Stump11289f42009-09-09 15:08:12 +00002528
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002529 /// \brief Build a new noexcept expression.
2530 ///
2531 /// By default, performs semantic analysis to build the new expression.
2532 /// Subclasses may override this routine to provide different behavior.
2533 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2534 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2535 }
2536
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002537 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002538 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2539 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002540 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002541 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002542 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002543 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2544 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002545 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002546
2547 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2548 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002549 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002550 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002551
Patrick Beard0caa3942012-04-19 00:25:12 +00002552 /// \brief Build a new Objective-C boxed expression.
2553 ///
2554 /// By default, performs semantic analysis to build the new expression.
2555 /// Subclasses may override this routine to provide different behavior.
2556 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2557 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2558 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002559
Ted Kremeneke65b0862012-03-06 20:05:56 +00002560 /// \brief Build a new Objective-C array literal.
2561 ///
2562 /// By default, performs semantic analysis to build the new expression.
2563 /// Subclasses may override this routine to provide different behavior.
2564 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2565 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002566 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002567 MultiExprArg(Elements, NumElements));
2568 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002569
2570 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002571 Expr *Base, Expr *Key,
2572 ObjCMethodDecl *getterMethod,
2573 ObjCMethodDecl *setterMethod) {
2574 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2575 getterMethod, setterMethod);
2576 }
2577
2578 /// \brief Build a new Objective-C dictionary literal.
2579 ///
2580 /// By default, performs semantic analysis to build the new expression.
2581 /// Subclasses may override this routine to provide different behavior.
2582 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2583 ObjCDictionaryElement *Elements,
2584 unsigned NumElements) {
2585 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2586 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002587
James Dennett2a4d13c2012-06-15 07:13:21 +00002588 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002589 ///
2590 /// By default, performs semantic analysis to build the new expression.
2591 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002592 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002593 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002594 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002595 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002596 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002597
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002598 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002599 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002600 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002601 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002602 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002603 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002604 MultiExprArg Args,
2605 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002606 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2607 ReceiverTypeInfo->getType(),
2608 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002609 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002610 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002611 }
2612
2613 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002614 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002615 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002616 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002617 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002618 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002619 MultiExprArg Args,
2620 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002621 return SemaRef.BuildInstanceMessage(Receiver,
2622 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002623 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002624 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002625 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002626 }
2627
Douglas Gregord51d90d2010-04-26 20:11:03 +00002628 /// \brief Build a new Objective-C ivar reference expression.
2629 ///
2630 /// By default, performs semantic analysis to build the new expression.
2631 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002632 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002633 SourceLocation IvarLoc,
2634 bool IsArrow, bool IsFreeIvar) {
2635 // FIXME: We lose track of the IsFreeIvar bit.
2636 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002637 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2638 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002639 /*FIXME:*/IvarLoc, IsArrow,
2640 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002641 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002642 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002643 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002644 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002645
2646 /// \brief Build a new Objective-C property reference expression.
2647 ///
2648 /// By default, performs semantic analysis to build the new expression.
2649 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002650 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002651 ObjCPropertyDecl *Property,
2652 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002653 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002654 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2655 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2656 /*FIXME:*/PropertyLoc,
2657 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002658 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002659 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002660 NameInfo,
2661 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002662 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002663
John McCallb7bd14f2010-12-02 01:19:52 +00002664 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002665 ///
2666 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002667 /// Subclasses may override this routine to provide different behavior.
2668 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2669 ObjCMethodDecl *Getter,
2670 ObjCMethodDecl *Setter,
2671 SourceLocation PropertyLoc) {
2672 // Since these expressions can only be value-dependent, we do not
2673 // need to perform semantic analysis again.
2674 return Owned(
2675 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2676 VK_LValue, OK_ObjCProperty,
2677 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002678 }
2679
Douglas Gregord51d90d2010-04-26 20:11:03 +00002680 /// \brief Build a new Objective-C "isa" expression.
2681 ///
2682 /// By default, performs semantic analysis to build the new expression.
2683 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002684 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002685 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002686 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002687 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2688 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002689 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002690 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002691 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002692 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002693 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002694 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002695
Douglas Gregora16548e2009-08-11 05:31:07 +00002696 /// \brief Build a new shuffle vector expression.
2697 ///
2698 /// By default, performs semantic analysis to build the new expression.
2699 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002700 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002701 MultiExprArg SubExprs,
2702 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002703 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002704 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002705 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2706 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2707 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002708 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002709
Douglas Gregora16548e2009-08-11 05:31:07 +00002710 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002711 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002712 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2713 SemaRef.Context.BuiltinFnTy,
2714 VK_RValue, BuiltinLoc);
2715 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2716 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002717 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002718
2719 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002720 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002721 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002722 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002723
Douglas Gregora16548e2009-08-11 05:31:07 +00002724 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002725 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002726 }
John McCall31f82722010-11-12 08:19:04 +00002727
Hal Finkelc4d7c822013-09-18 03:29:45 +00002728 /// \brief Build a new convert vector expression.
2729 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2730 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2731 SourceLocation RParenLoc) {
2732 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2733 BuiltinLoc, RParenLoc);
2734 }
2735
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002736 /// \brief Build a new template argument pack expansion.
2737 ///
2738 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002739 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002740 /// different behavior.
2741 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002742 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002743 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002744 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002745 case TemplateArgument::Expression: {
2746 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002747 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2748 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002749 if (Result.isInvalid())
2750 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002751
Douglas Gregor98318c22011-01-03 21:37:45 +00002752 return TemplateArgumentLoc(Result.get(), Result.get());
2753 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002754
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002755 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002756 return TemplateArgumentLoc(TemplateArgument(
2757 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002758 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002759 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002760 Pattern.getTemplateNameLoc(),
2761 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002762
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002763 case TemplateArgument::Null:
2764 case TemplateArgument::Integral:
2765 case TemplateArgument::Declaration:
2766 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002767 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002768 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002769 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002770
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002771 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002772 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002773 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002774 EllipsisLoc,
2775 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002776 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2777 Expansion);
2778 break;
2779 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002780
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002781 return TemplateArgumentLoc();
2782 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002783
Douglas Gregor968f23a2011-01-03 19:31:53 +00002784 /// \brief Build a new expression pack expansion.
2785 ///
2786 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002787 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002788 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002789 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002790 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002791 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002792 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002793
Richard Smith0f0af192014-11-08 05:07:16 +00002794 /// \brief Build a new C++1z fold-expression.
2795 ///
2796 /// By default, performs semantic analysis in order to build a new fold
2797 /// expression.
2798 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
2799 BinaryOperatorKind Operator,
2800 SourceLocation EllipsisLoc, Expr *RHS,
2801 SourceLocation RParenLoc) {
2802 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
2803 RHS, RParenLoc);
2804 }
2805
2806 /// \brief Build an empty C++1z fold-expression with the given operator.
2807 ///
2808 /// By default, produces the fallback value for the fold-expression, or
2809 /// produce an error if there is no fallback value.
2810 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
2811 BinaryOperatorKind Operator) {
2812 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
2813 }
2814
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002815 /// \brief Build a new atomic operation expression.
2816 ///
2817 /// By default, performs semantic analysis to build the new expression.
2818 /// Subclasses may override this routine to provide different behavior.
2819 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2820 MultiExprArg SubExprs,
2821 QualType RetTy,
2822 AtomicExpr::AtomicOp Op,
2823 SourceLocation RParenLoc) {
2824 // Just create the expression; there is not any interesting semantic
2825 // analysis here because we can't actually build an AtomicExpr until
2826 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002827 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002828 RParenLoc);
2829 }
2830
John McCall31f82722010-11-12 08:19:04 +00002831private:
Douglas Gregor14454802011-02-25 02:25:35 +00002832 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2833 QualType ObjectType,
2834 NamedDecl *FirstQualifierInScope,
2835 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002836
2837 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2838 QualType ObjectType,
2839 NamedDecl *FirstQualifierInScope,
2840 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002841
2842 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2843 NamedDecl *FirstQualifierInScope,
2844 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002845};
Douglas Gregora16548e2009-08-11 05:31:07 +00002846
Douglas Gregorebe10102009-08-20 07:17:43 +00002847template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002848StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002849 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002850 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002851
Douglas Gregorebe10102009-08-20 07:17:43 +00002852 switch (S->getStmtClass()) {
2853 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002854
Douglas Gregorebe10102009-08-20 07:17:43 +00002855 // Transform individual statement nodes
2856#define STMT(Node, Parent) \
2857 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002858#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002859#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002860#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002861
Douglas Gregorebe10102009-08-20 07:17:43 +00002862 // Transform expressions by calling TransformExpr.
2863#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002864#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002865#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002866#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002867 {
John McCalldadc5752010-08-24 06:29:42 +00002868 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002869 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002870 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002871
Richard Smith945f8d32013-01-14 22:39:08 +00002872 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002873 }
Mike Stump11289f42009-09-09 15:08:12 +00002874 }
2875
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002876 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002877}
Mike Stump11289f42009-09-09 15:08:12 +00002878
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002879template<typename Derived>
2880OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2881 if (!S)
2882 return S;
2883
2884 switch (S->getClauseKind()) {
2885 default: break;
2886 // Transform individual clause nodes
2887#define OPENMP_CLAUSE(Name, Class) \
2888 case OMPC_ ## Name : \
2889 return getDerived().Transform ## Class(cast<Class>(S));
2890#include "clang/Basic/OpenMPKinds.def"
2891 }
2892
2893 return S;
2894}
2895
Mike Stump11289f42009-09-09 15:08:12 +00002896
Douglas Gregore922c772009-08-04 22:27:00 +00002897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002898ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002899 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002900 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002901
2902 switch (E->getStmtClass()) {
2903 case Stmt::NoStmtClass: break;
2904#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002905#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002906#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002907 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002908#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002909 }
2910
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002911 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002912}
2913
2914template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002915ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00002916 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00002917 // Initializers are instantiated like expressions, except that various outer
2918 // layers are stripped.
2919 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002920 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002921
2922 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2923 Init = ExprTemp->getSubExpr();
2924
Richard Smithe6ca4752013-05-30 22:40:16 +00002925 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2926 Init = MTE->GetTemporaryExpr();
2927
Richard Smithd59b8322012-12-19 01:39:02 +00002928 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2929 Init = Binder->getSubExpr();
2930
2931 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2932 Init = ICE->getSubExprAsWritten();
2933
Richard Smithcc1b96d2013-06-12 22:31:48 +00002934 if (CXXStdInitializerListExpr *ILE =
2935 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00002936 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00002937
Richard Smithc6abd962014-07-25 01:12:44 +00002938 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00002939 // InitListExprs. Other forms of copy-initialization will be a no-op if
2940 // the initializer is already the right type.
2941 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00002942 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00002943 return getDerived().TransformExpr(Init);
2944
2945 // Revert value-initialization back to empty parens.
2946 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2947 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002948 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002949 Parens.getEnd());
2950 }
2951
2952 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2953 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002954 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002955 SourceLocation());
2956
2957 // Revert initialization by constructor back to a parenthesized or braced list
2958 // of expressions. Any other form of initializer can just be reused directly.
2959 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002960 return getDerived().TransformExpr(Init);
2961
Richard Smithf8adcdc2014-07-17 05:12:35 +00002962 // If the initialization implicitly converted an initializer list to a
2963 // std::initializer_list object, unwrap the std::initializer_list too.
2964 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00002965 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00002966
Richard Smithd59b8322012-12-19 01:39:02 +00002967 SmallVector<Expr*, 8> NewArgs;
2968 bool ArgChanged = false;
2969 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00002970 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00002971 return ExprError();
2972
2973 // If this was list initialization, revert to list form.
2974 if (Construct->isListInitialization())
2975 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2976 Construct->getLocEnd(),
2977 Construct->getType());
2978
Richard Smithd59b8322012-12-19 01:39:02 +00002979 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002980 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00002981 if (Parens.isInvalid()) {
2982 // This was a variable declaration's initialization for which no initializer
2983 // was specified.
2984 assert(NewArgs.empty() &&
2985 "no parens or braces but have direct init with arguments?");
2986 return ExprEmpty();
2987 }
Richard Smithd59b8322012-12-19 01:39:02 +00002988 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2989 Parens.getEnd());
2990}
2991
2992template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002993bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2994 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002995 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002996 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002997 bool *ArgChanged) {
2998 for (unsigned I = 0; I != NumInputs; ++I) {
2999 // If requested, drop call arguments that need to be dropped.
3000 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3001 if (ArgChanged)
3002 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003003
Douglas Gregora3efea12011-01-03 19:04:46 +00003004 break;
3005 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003006
Douglas Gregor968f23a2011-01-03 19:31:53 +00003007 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3008 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003009
Chris Lattner01cf8db2011-07-20 06:58:45 +00003010 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003011 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3012 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003013
Douglas Gregor968f23a2011-01-03 19:31:53 +00003014 // Determine whether the set of unexpanded parameter packs can and should
3015 // be expanded.
3016 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003017 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003018 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3019 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003020 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3021 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003022 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003023 Expand, RetainExpansion,
3024 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003025 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003026
Douglas Gregor968f23a2011-01-03 19:31:53 +00003027 if (!Expand) {
3028 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003029 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003030 // expansion.
3031 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3032 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3033 if (OutPattern.isInvalid())
3034 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003035
3036 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003037 Expansion->getEllipsisLoc(),
3038 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003039 if (Out.isInvalid())
3040 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003041
Douglas Gregor968f23a2011-01-03 19:31:53 +00003042 if (ArgChanged)
3043 *ArgChanged = true;
3044 Outputs.push_back(Out.get());
3045 continue;
3046 }
John McCall542e7c62011-07-06 07:30:07 +00003047
3048 // Record right away that the argument was changed. This needs
3049 // to happen even if the array expands to nothing.
3050 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003051
Douglas Gregor968f23a2011-01-03 19:31:53 +00003052 // The transform has determined that we should perform an elementwise
3053 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003054 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003055 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3056 ExprResult Out = getDerived().TransformExpr(Pattern);
3057 if (Out.isInvalid())
3058 return true;
3059
Richard Smith9467be42014-06-06 17:33:35 +00003060 // FIXME: Can this happen? We should not try to expand the pack
3061 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003062 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003063 Out = getDerived().RebuildPackExpansion(
3064 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003065 if (Out.isInvalid())
3066 return true;
3067 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003068
Douglas Gregor968f23a2011-01-03 19:31:53 +00003069 Outputs.push_back(Out.get());
3070 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003071
Richard Smith9467be42014-06-06 17:33:35 +00003072 // If we're supposed to retain a pack expansion, do so by temporarily
3073 // forgetting the partially-substituted parameter pack.
3074 if (RetainExpansion) {
3075 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3076
3077 ExprResult Out = getDerived().TransformExpr(Pattern);
3078 if (Out.isInvalid())
3079 return true;
3080
3081 Out = getDerived().RebuildPackExpansion(
3082 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3083 if (Out.isInvalid())
3084 return true;
3085
3086 Outputs.push_back(Out.get());
3087 }
3088
Douglas Gregor968f23a2011-01-03 19:31:53 +00003089 continue;
3090 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003091
Richard Smithd59b8322012-12-19 01:39:02 +00003092 ExprResult Result =
3093 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3094 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003095 if (Result.isInvalid())
3096 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003097
Douglas Gregora3efea12011-01-03 19:04:46 +00003098 if (Result.get() != Inputs[I] && ArgChanged)
3099 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003100
3101 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003102 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003103
Douglas Gregora3efea12011-01-03 19:04:46 +00003104 return false;
3105}
3106
3107template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003108NestedNameSpecifierLoc
3109TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3110 NestedNameSpecifierLoc NNS,
3111 QualType ObjectType,
3112 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003113 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003114 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003115 Qualifier = Qualifier.getPrefix())
3116 Qualifiers.push_back(Qualifier);
3117
3118 CXXScopeSpec SS;
3119 while (!Qualifiers.empty()) {
3120 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3121 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003122
Douglas Gregor14454802011-02-25 02:25:35 +00003123 switch (QNNS->getKind()) {
3124 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003125 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003126 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003127 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003128 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003129 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003130 FirstQualifierInScope, false))
3131 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003132
Douglas Gregor14454802011-02-25 02:25:35 +00003133 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003134
Douglas Gregor14454802011-02-25 02:25:35 +00003135 case NestedNameSpecifier::Namespace: {
3136 NamespaceDecl *NS
3137 = cast_or_null<NamespaceDecl>(
3138 getDerived().TransformDecl(
3139 Q.getLocalBeginLoc(),
3140 QNNS->getAsNamespace()));
3141 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3142 break;
3143 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003144
Douglas Gregor14454802011-02-25 02:25:35 +00003145 case NestedNameSpecifier::NamespaceAlias: {
3146 NamespaceAliasDecl *Alias
3147 = cast_or_null<NamespaceAliasDecl>(
3148 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3149 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003150 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003151 Q.getLocalEndLoc());
3152 break;
3153 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003154
Douglas Gregor14454802011-02-25 02:25:35 +00003155 case NestedNameSpecifier::Global:
3156 // There is no meaningful transformation that one could perform on the
3157 // global scope.
3158 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3159 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003160
Nikola Smiljanic67860242014-09-26 00:28:20 +00003161 case NestedNameSpecifier::Super: {
3162 CXXRecordDecl *RD =
3163 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3164 SourceLocation(), QNNS->getAsRecordDecl()));
3165 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3166 break;
3167 }
3168
Douglas Gregor14454802011-02-25 02:25:35 +00003169 case NestedNameSpecifier::TypeSpecWithTemplate:
3170 case NestedNameSpecifier::TypeSpec: {
3171 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3172 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003173
Douglas Gregor14454802011-02-25 02:25:35 +00003174 if (!TL)
3175 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003176
Douglas Gregor14454802011-02-25 02:25:35 +00003177 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003178 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003179 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003180 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003181 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003182 if (TL.getType()->isEnumeralType())
3183 SemaRef.Diag(TL.getBeginLoc(),
3184 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003185 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3186 Q.getLocalEndLoc());
3187 break;
3188 }
Richard Trieude756fb2011-05-07 01:36:37 +00003189 // If the nested-name-specifier is an invalid type def, don't emit an
3190 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003191 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3192 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003193 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003194 << TL.getType() << SS.getRange();
3195 }
Douglas Gregor14454802011-02-25 02:25:35 +00003196 return NestedNameSpecifierLoc();
3197 }
Douglas Gregore16af532011-02-28 18:50:33 +00003198 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003199
Douglas Gregore16af532011-02-28 18:50:33 +00003200 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003201 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003202 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003203 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003204
Douglas Gregor14454802011-02-25 02:25:35 +00003205 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003206 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003207 !getDerived().AlwaysRebuild())
3208 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003209
3210 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003211 // nested-name-specifier, do so.
3212 if (SS.location_size() == NNS.getDataLength() &&
3213 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3214 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3215
3216 // Allocate new nested-name-specifier location information.
3217 return SS.getWithLocInContext(SemaRef.Context);
3218}
3219
3220template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003221DeclarationNameInfo
3222TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003223::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003224 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003225 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003226 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003227
3228 switch (Name.getNameKind()) {
3229 case DeclarationName::Identifier:
3230 case DeclarationName::ObjCZeroArgSelector:
3231 case DeclarationName::ObjCOneArgSelector:
3232 case DeclarationName::ObjCMultiArgSelector:
3233 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003234 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003235 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003236 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003237
Douglas Gregorf816bd72009-09-03 22:13:48 +00003238 case DeclarationName::CXXConstructorName:
3239 case DeclarationName::CXXDestructorName:
3240 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003241 TypeSourceInfo *NewTInfo;
3242 CanQualType NewCanTy;
3243 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003244 NewTInfo = getDerived().TransformType(OldTInfo);
3245 if (!NewTInfo)
3246 return DeclarationNameInfo();
3247 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003248 }
3249 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003250 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003251 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003252 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003253 if (NewT.isNull())
3254 return DeclarationNameInfo();
3255 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3256 }
Mike Stump11289f42009-09-09 15:08:12 +00003257
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003258 DeclarationName NewName
3259 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3260 NewCanTy);
3261 DeclarationNameInfo NewNameInfo(NameInfo);
3262 NewNameInfo.setName(NewName);
3263 NewNameInfo.setNamedTypeInfo(NewTInfo);
3264 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003265 }
Mike Stump11289f42009-09-09 15:08:12 +00003266 }
3267
David Blaikie83d382b2011-09-23 05:06:16 +00003268 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003269}
3270
3271template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003272TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003273TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3274 TemplateName Name,
3275 SourceLocation NameLoc,
3276 QualType ObjectType,
3277 NamedDecl *FirstQualifierInScope) {
3278 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3279 TemplateDecl *Template = QTN->getTemplateDecl();
3280 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003281
Douglas Gregor9db53502011-03-02 18:07:45 +00003282 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003283 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003284 Template));
3285 if (!TransTemplate)
3286 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003287
Douglas Gregor9db53502011-03-02 18:07:45 +00003288 if (!getDerived().AlwaysRebuild() &&
3289 SS.getScopeRep() == QTN->getQualifier() &&
3290 TransTemplate == Template)
3291 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003292
Douglas Gregor9db53502011-03-02 18:07:45 +00003293 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3294 TransTemplate);
3295 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003296
Douglas Gregor9db53502011-03-02 18:07:45 +00003297 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3298 if (SS.getScopeRep()) {
3299 // These apply to the scope specifier, not the template.
3300 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003301 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003302 }
3303
Douglas Gregor9db53502011-03-02 18:07:45 +00003304 if (!getDerived().AlwaysRebuild() &&
3305 SS.getScopeRep() == DTN->getQualifier() &&
3306 ObjectType.isNull())
3307 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003308
Douglas Gregor9db53502011-03-02 18:07:45 +00003309 if (DTN->isIdentifier()) {
3310 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003311 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003312 NameLoc,
3313 ObjectType,
3314 FirstQualifierInScope);
3315 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003316
Douglas Gregor9db53502011-03-02 18:07:45 +00003317 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3318 ObjectType);
3319 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003320
Douglas Gregor9db53502011-03-02 18:07:45 +00003321 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3322 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003323 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003324 Template));
3325 if (!TransTemplate)
3326 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003327
Douglas Gregor9db53502011-03-02 18:07:45 +00003328 if (!getDerived().AlwaysRebuild() &&
3329 TransTemplate == Template)
3330 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003331
Douglas Gregor9db53502011-03-02 18:07:45 +00003332 return TemplateName(TransTemplate);
3333 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003334
Douglas Gregor9db53502011-03-02 18:07:45 +00003335 if (SubstTemplateTemplateParmPackStorage *SubstPack
3336 = Name.getAsSubstTemplateTemplateParmPack()) {
3337 TemplateTemplateParmDecl *TransParam
3338 = cast_or_null<TemplateTemplateParmDecl>(
3339 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3340 if (!TransParam)
3341 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003342
Douglas Gregor9db53502011-03-02 18:07:45 +00003343 if (!getDerived().AlwaysRebuild() &&
3344 TransParam == SubstPack->getParameterPack())
3345 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003346
3347 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003348 SubstPack->getArgumentPack());
3349 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003350
Douglas Gregor9db53502011-03-02 18:07:45 +00003351 // These should be getting filtered out before they reach the AST.
3352 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003353}
3354
3355template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003356void TreeTransform<Derived>::InventTemplateArgumentLoc(
3357 const TemplateArgument &Arg,
3358 TemplateArgumentLoc &Output) {
3359 SourceLocation Loc = getDerived().getBaseLocation();
3360 switch (Arg.getKind()) {
3361 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003362 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003363 break;
3364
3365 case TemplateArgument::Type:
3366 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003367 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003368
John McCall0ad16662009-10-29 08:12:44 +00003369 break;
3370
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003371 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003372 case TemplateArgument::TemplateExpansion: {
3373 NestedNameSpecifierLocBuilder Builder;
3374 TemplateName Template = Arg.getAsTemplate();
3375 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3376 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3377 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3378 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003379
Douglas Gregor9d802122011-03-02 17:09:35 +00003380 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003381 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003382 Builder.getWithLocInContext(SemaRef.Context),
3383 Loc);
3384 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003385 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003386 Builder.getWithLocInContext(SemaRef.Context),
3387 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003388
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003389 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003390 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003391
John McCall0ad16662009-10-29 08:12:44 +00003392 case TemplateArgument::Expression:
3393 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3394 break;
3395
3396 case TemplateArgument::Declaration:
3397 case TemplateArgument::Integral:
3398 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003399 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003400 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003401 break;
3402 }
3403}
3404
3405template<typename Derived>
3406bool TreeTransform<Derived>::TransformTemplateArgument(
3407 const TemplateArgumentLoc &Input,
3408 TemplateArgumentLoc &Output) {
3409 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003410 switch (Arg.getKind()) {
3411 case TemplateArgument::Null:
3412 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003413 case TemplateArgument::Pack:
3414 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003415 case TemplateArgument::NullPtr:
3416 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003417
Douglas Gregore922c772009-08-04 22:27:00 +00003418 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003419 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003420 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003421 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003422
3423 DI = getDerived().TransformType(DI);
3424 if (!DI) return true;
3425
3426 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3427 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003428 }
Mike Stump11289f42009-09-09 15:08:12 +00003429
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003430 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003431 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3432 if (QualifierLoc) {
3433 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3434 if (!QualifierLoc)
3435 return true;
3436 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003437
Douglas Gregordf846d12011-03-02 18:46:51 +00003438 CXXScopeSpec SS;
3439 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003440 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003441 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3442 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003443 if (Template.isNull())
3444 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003445
Douglas Gregor9d802122011-03-02 17:09:35 +00003446 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003447 Input.getTemplateNameLoc());
3448 return false;
3449 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003450
3451 case TemplateArgument::TemplateExpansion:
3452 llvm_unreachable("Caller should expand pack expansions");
3453
Douglas Gregore922c772009-08-04 22:27:00 +00003454 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003455 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003456 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003457 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003458
John McCall0ad16662009-10-29 08:12:44 +00003459 Expr *InputExpr = Input.getSourceExpression();
3460 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3461
Chris Lattnercdb591a2011-04-25 20:37:58 +00003462 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003463 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003464 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003465 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003466 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003467 }
Douglas Gregore922c772009-08-04 22:27:00 +00003468 }
Mike Stump11289f42009-09-09 15:08:12 +00003469
Douglas Gregore922c772009-08-04 22:27:00 +00003470 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003471 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003472}
3473
Douglas Gregorfe921a72010-12-20 23:36:19 +00003474/// \brief Iterator adaptor that invents template argument location information
3475/// for each of the template arguments in its underlying iterator.
3476template<typename Derived, typename InputIterator>
3477class TemplateArgumentLocInventIterator {
3478 TreeTransform<Derived> &Self;
3479 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003480
Douglas Gregorfe921a72010-12-20 23:36:19 +00003481public:
3482 typedef TemplateArgumentLoc value_type;
3483 typedef TemplateArgumentLoc reference;
3484 typedef typename std::iterator_traits<InputIterator>::difference_type
3485 difference_type;
3486 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003487
Douglas Gregorfe921a72010-12-20 23:36:19 +00003488 class pointer {
3489 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003490
Douglas Gregorfe921a72010-12-20 23:36:19 +00003491 public:
3492 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003493
Douglas Gregorfe921a72010-12-20 23:36:19 +00003494 const TemplateArgumentLoc *operator->() const { return &Arg; }
3495 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003496
Douglas Gregorfe921a72010-12-20 23:36:19 +00003497 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003498
Douglas Gregorfe921a72010-12-20 23:36:19 +00003499 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3500 InputIterator Iter)
3501 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003502
Douglas Gregorfe921a72010-12-20 23:36:19 +00003503 TemplateArgumentLocInventIterator &operator++() {
3504 ++Iter;
3505 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003506 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003507
Douglas Gregorfe921a72010-12-20 23:36:19 +00003508 TemplateArgumentLocInventIterator operator++(int) {
3509 TemplateArgumentLocInventIterator Old(*this);
3510 ++(*this);
3511 return Old;
3512 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003513
Douglas Gregorfe921a72010-12-20 23:36:19 +00003514 reference operator*() const {
3515 TemplateArgumentLoc Result;
3516 Self.InventTemplateArgumentLoc(*Iter, Result);
3517 return Result;
3518 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003519
Douglas Gregorfe921a72010-12-20 23:36:19 +00003520 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003521
Douglas Gregorfe921a72010-12-20 23:36:19 +00003522 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3523 const TemplateArgumentLocInventIterator &Y) {
3524 return X.Iter == Y.Iter;
3525 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003526
Douglas Gregorfe921a72010-12-20 23:36:19 +00003527 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3528 const TemplateArgumentLocInventIterator &Y) {
3529 return X.Iter != Y.Iter;
3530 }
3531};
Chad Rosier1dcde962012-08-08 18:46:20 +00003532
Douglas Gregor42cafa82010-12-20 17:42:22 +00003533template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003534template<typename InputIterator>
3535bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3536 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003537 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003538 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003539 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003540 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003541
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003542 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3543 // Unpack argument packs, which we translate them into separate
3544 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003545 // FIXME: We could do much better if we could guarantee that the
3546 // TemplateArgumentLocInfo for the pack expansion would be usable for
3547 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003548 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003549 TemplateArgument::pack_iterator>
3550 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003551 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003552 In.getArgument().pack_begin()),
3553 PackLocIterator(*this,
3554 In.getArgument().pack_end()),
3555 Outputs))
3556 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003557
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003558 continue;
3559 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003560
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003561 if (In.getArgument().isPackExpansion()) {
3562 // We have a pack expansion, for which we will be substituting into
3563 // the pattern.
3564 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003565 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003566 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003567 = getSema().getTemplateArgumentPackExpansionPattern(
3568 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003569
Chris Lattner01cf8db2011-07-20 06:58:45 +00003570 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003571 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3572 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003573
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003574 // Determine whether the set of unexpanded parameter packs can and should
3575 // be expanded.
3576 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003577 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003578 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003579 if (getDerived().TryExpandParameterPacks(Ellipsis,
3580 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003581 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003582 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003583 RetainExpansion,
3584 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003585 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003586
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003587 if (!Expand) {
3588 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003589 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003590 // expansion.
3591 TemplateArgumentLoc OutPattern;
3592 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3593 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3594 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003595
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003596 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3597 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003598 if (Out.getArgument().isNull())
3599 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003600
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003601 Outputs.addArgument(Out);
3602 continue;
3603 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003604
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003605 // The transform has determined that we should perform an elementwise
3606 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003607 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003608 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3609
3610 if (getDerived().TransformTemplateArgument(Pattern, Out))
3611 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003612
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003613 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003614 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3615 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003616 if (Out.getArgument().isNull())
3617 return true;
3618 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003619
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003620 Outputs.addArgument(Out);
3621 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003622
Douglas Gregor48d24112011-01-10 20:53:55 +00003623 // If we're supposed to retain a pack expansion, do so by temporarily
3624 // forgetting the partially-substituted parameter pack.
3625 if (RetainExpansion) {
3626 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003627
Douglas Gregor48d24112011-01-10 20:53:55 +00003628 if (getDerived().TransformTemplateArgument(Pattern, Out))
3629 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003630
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003631 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3632 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003633 if (Out.getArgument().isNull())
3634 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003635
Douglas Gregor48d24112011-01-10 20:53:55 +00003636 Outputs.addArgument(Out);
3637 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003638
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003639 continue;
3640 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003641
3642 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003643 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003644 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003645
Douglas Gregor42cafa82010-12-20 17:42:22 +00003646 Outputs.addArgument(Out);
3647 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003648
Douglas Gregor42cafa82010-12-20 17:42:22 +00003649 return false;
3650
3651}
3652
Douglas Gregord6ff3322009-08-04 16:50:30 +00003653//===----------------------------------------------------------------------===//
3654// Type transformation
3655//===----------------------------------------------------------------------===//
3656
3657template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003658QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003659 if (getDerived().AlreadyTransformed(T))
3660 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003661
John McCall550e0c22009-10-21 00:40:46 +00003662 // Temporary workaround. All of these transformations should
3663 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003664 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3665 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003666
John McCall31f82722010-11-12 08:19:04 +00003667 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003668
John McCall550e0c22009-10-21 00:40:46 +00003669 if (!NewDI)
3670 return QualType();
3671
3672 return NewDI->getType();
3673}
3674
3675template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003676TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003677 // Refine the base location to the type's location.
3678 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3679 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003680 if (getDerived().AlreadyTransformed(DI->getType()))
3681 return DI;
3682
3683 TypeLocBuilder TLB;
3684
3685 TypeLoc TL = DI->getTypeLoc();
3686 TLB.reserve(TL.getFullDataSize());
3687
John McCall31f82722010-11-12 08:19:04 +00003688 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003689 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003690 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003691
John McCallbcd03502009-12-07 02:54:59 +00003692 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003693}
3694
3695template<typename Derived>
3696QualType
John McCall31f82722010-11-12 08:19:04 +00003697TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003698 switch (T.getTypeLocClass()) {
3699#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003700#define TYPELOC(CLASS, PARENT) \
3701 case TypeLoc::CLASS: \
3702 return getDerived().Transform##CLASS##Type(TLB, \
3703 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003704#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003705 }
Mike Stump11289f42009-09-09 15:08:12 +00003706
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003707 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003708}
3709
3710/// FIXME: By default, this routine adds type qualifiers only to types
3711/// that can have qualifiers, and silently suppresses those qualifiers
3712/// that are not permitted (e.g., qualifiers on reference or function
3713/// types). This is the right thing for template instantiation, but
3714/// probably not for other clients.
3715template<typename Derived>
3716QualType
3717TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003718 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003719 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003720
John McCall31f82722010-11-12 08:19:04 +00003721 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003722 if (Result.isNull())
3723 return QualType();
3724
3725 // Silently suppress qualifiers if the result type can't be qualified.
3726 // FIXME: this is the right thing for template instantiation, but
3727 // probably not for other clients.
3728 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003729 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003730
John McCall31168b02011-06-15 23:02:42 +00003731 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003732 // resulting type.
3733 if (Quals.hasObjCLifetime()) {
3734 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3735 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003736 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003737 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003738 // A lifetime qualifier applied to a substituted template parameter
3739 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003740 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003741 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003742 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3743 QualType Replacement = SubstTypeParam->getReplacementType();
3744 Qualifiers Qs = Replacement.getQualifiers();
3745 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003746 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003747 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3748 Qs);
3749 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003750 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003751 Replacement);
3752 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003753 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3754 // 'auto' types behave the same way as template parameters.
3755 QualType Deduced = AutoTy->getDeducedType();
3756 Qualifiers Qs = Deduced.getQualifiers();
3757 Qs.removeObjCLifetime();
3758 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3759 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003760 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3761 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003762 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003763 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003764 // Otherwise, complain about the addition of a qualifier to an
3765 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003766 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003767 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003768 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003769
Douglas Gregore46db902011-06-17 22:11:49 +00003770 Quals.removeObjCLifetime();
3771 }
3772 }
3773 }
John McCallcb0f89a2010-06-05 06:41:15 +00003774 if (!Quals.empty()) {
3775 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003776 // BuildQualifiedType might not add qualifiers if they are invalid.
3777 if (Result.hasLocalQualifiers())
3778 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003779 // No location information to preserve.
3780 }
John McCall550e0c22009-10-21 00:40:46 +00003781
3782 return Result;
3783}
3784
Douglas Gregor14454802011-02-25 02:25:35 +00003785template<typename Derived>
3786TypeLoc
3787TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3788 QualType ObjectType,
3789 NamedDecl *UnqualLookup,
3790 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003791 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003792 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003793
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003794 TypeSourceInfo *TSI =
3795 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3796 if (TSI)
3797 return TSI->getTypeLoc();
3798 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003799}
3800
Douglas Gregor579c15f2011-03-02 18:32:08 +00003801template<typename Derived>
3802TypeSourceInfo *
3803TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3804 QualType ObjectType,
3805 NamedDecl *UnqualLookup,
3806 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003807 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003808 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003809
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003810 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3811 UnqualLookup, SS);
3812}
3813
3814template <typename Derived>
3815TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3816 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3817 CXXScopeSpec &SS) {
3818 QualType T = TL.getType();
3819 assert(!getDerived().AlreadyTransformed(T));
3820
Douglas Gregor579c15f2011-03-02 18:32:08 +00003821 TypeLocBuilder TLB;
3822 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003823
Douglas Gregor579c15f2011-03-02 18:32:08 +00003824 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003825 TemplateSpecializationTypeLoc SpecTL =
3826 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003827
Douglas Gregor579c15f2011-03-02 18:32:08 +00003828 TemplateName Template
3829 = getDerived().TransformTemplateName(SS,
3830 SpecTL.getTypePtr()->getTemplateName(),
3831 SpecTL.getTemplateNameLoc(),
3832 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003833 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003834 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003835
3836 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003837 Template);
3838 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003839 DependentTemplateSpecializationTypeLoc SpecTL =
3840 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003841
Douglas Gregor579c15f2011-03-02 18:32:08 +00003842 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003843 = getDerived().RebuildTemplateName(SS,
3844 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003845 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003846 ObjectType, UnqualLookup);
3847 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003848 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003849
3850 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003851 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003852 Template,
3853 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003854 } else {
3855 // Nothing special needs to be done for these.
3856 Result = getDerived().TransformType(TLB, TL);
3857 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003858
3859 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003860 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003861
Douglas Gregor579c15f2011-03-02 18:32:08 +00003862 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3863}
3864
John McCall550e0c22009-10-21 00:40:46 +00003865template <class TyLoc> static inline
3866QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3867 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3868 NewT.setNameLoc(T.getNameLoc());
3869 return T.getType();
3870}
3871
John McCall550e0c22009-10-21 00:40:46 +00003872template<typename Derived>
3873QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003874 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003875 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3876 NewT.setBuiltinLoc(T.getBuiltinLoc());
3877 if (T.needsExtraLocalData())
3878 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3879 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003880}
Mike Stump11289f42009-09-09 15:08:12 +00003881
Douglas Gregord6ff3322009-08-04 16:50:30 +00003882template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003883QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003884 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003885 // FIXME: recurse?
3886 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003887}
Mike Stump11289f42009-09-09 15:08:12 +00003888
Reid Kleckner0503a872013-12-05 01:23:43 +00003889template <typename Derived>
3890QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3891 AdjustedTypeLoc TL) {
3892 // Adjustments applied during transformation are handled elsewhere.
3893 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3894}
3895
Douglas Gregord6ff3322009-08-04 16:50:30 +00003896template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003897QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3898 DecayedTypeLoc TL) {
3899 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3900 if (OriginalType.isNull())
3901 return QualType();
3902
3903 QualType Result = TL.getType();
3904 if (getDerived().AlwaysRebuild() ||
3905 OriginalType != TL.getOriginalLoc().getType())
3906 Result = SemaRef.Context.getDecayedType(OriginalType);
3907 TLB.push<DecayedTypeLoc>(Result);
3908 // Nothing to set for DecayedTypeLoc.
3909 return Result;
3910}
3911
3912template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003913QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003914 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003915 QualType PointeeType
3916 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003917 if (PointeeType.isNull())
3918 return QualType();
3919
3920 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003921 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003922 // A dependent pointer type 'T *' has is being transformed such
3923 // that an Objective-C class type is being replaced for 'T'. The
3924 // resulting pointer type is an ObjCObjectPointerType, not a
3925 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003926 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003927
John McCall8b07ec22010-05-15 11:32:37 +00003928 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3929 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003930 return Result;
3931 }
John McCall31f82722010-11-12 08:19:04 +00003932
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003933 if (getDerived().AlwaysRebuild() ||
3934 PointeeType != TL.getPointeeLoc().getType()) {
3935 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3936 if (Result.isNull())
3937 return QualType();
3938 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003939
John McCall31168b02011-06-15 23:02:42 +00003940 // Objective-C ARC can add lifetime qualifiers to the type that we're
3941 // pointing to.
3942 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003943
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003944 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3945 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003946 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003947}
Mike Stump11289f42009-09-09 15:08:12 +00003948
3949template<typename Derived>
3950QualType
John McCall550e0c22009-10-21 00:40:46 +00003951TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003952 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003953 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003954 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3955 if (PointeeType.isNull())
3956 return QualType();
3957
3958 QualType Result = TL.getType();
3959 if (getDerived().AlwaysRebuild() ||
3960 PointeeType != TL.getPointeeLoc().getType()) {
3961 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003962 TL.getSigilLoc());
3963 if (Result.isNull())
3964 return QualType();
3965 }
3966
Douglas Gregor049211a2010-04-22 16:50:51 +00003967 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003968 NewT.setSigilLoc(TL.getSigilLoc());
3969 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003970}
3971
John McCall70dd5f62009-10-30 00:06:24 +00003972/// Transforms a reference type. Note that somewhat paradoxically we
3973/// don't care whether the type itself is an l-value type or an r-value
3974/// type; we only care if the type was *written* as an l-value type
3975/// or an r-value type.
3976template<typename Derived>
3977QualType
3978TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003979 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003980 const ReferenceType *T = TL.getTypePtr();
3981
3982 // Note that this works with the pointee-as-written.
3983 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3984 if (PointeeType.isNull())
3985 return QualType();
3986
3987 QualType Result = TL.getType();
3988 if (getDerived().AlwaysRebuild() ||
3989 PointeeType != T->getPointeeTypeAsWritten()) {
3990 Result = getDerived().RebuildReferenceType(PointeeType,
3991 T->isSpelledAsLValue(),
3992 TL.getSigilLoc());
3993 if (Result.isNull())
3994 return QualType();
3995 }
3996
John McCall31168b02011-06-15 23:02:42 +00003997 // Objective-C ARC can add lifetime qualifiers to the type that we're
3998 // referring to.
3999 TLB.TypeWasModifiedSafely(
4000 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4001
John McCall70dd5f62009-10-30 00:06:24 +00004002 // r-value references can be rebuilt as l-value references.
4003 ReferenceTypeLoc NewTL;
4004 if (isa<LValueReferenceType>(Result))
4005 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4006 else
4007 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4008 NewTL.setSigilLoc(TL.getSigilLoc());
4009
4010 return Result;
4011}
4012
Mike Stump11289f42009-09-09 15:08:12 +00004013template<typename Derived>
4014QualType
John McCall550e0c22009-10-21 00:40:46 +00004015TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004016 LValueReferenceTypeLoc TL) {
4017 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004018}
4019
Mike Stump11289f42009-09-09 15:08:12 +00004020template<typename Derived>
4021QualType
John McCall550e0c22009-10-21 00:40:46 +00004022TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004023 RValueReferenceTypeLoc TL) {
4024 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004025}
Mike Stump11289f42009-09-09 15:08:12 +00004026
Douglas Gregord6ff3322009-08-04 16:50:30 +00004027template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004028QualType
John McCall550e0c22009-10-21 00:40:46 +00004029TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004030 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004031 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004032 if (PointeeType.isNull())
4033 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004034
Abramo Bagnara509357842011-03-05 14:42:21 +00004035 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004036 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004037 if (OldClsTInfo) {
4038 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4039 if (!NewClsTInfo)
4040 return QualType();
4041 }
4042
4043 const MemberPointerType *T = TL.getTypePtr();
4044 QualType OldClsType = QualType(T->getClass(), 0);
4045 QualType NewClsType;
4046 if (NewClsTInfo)
4047 NewClsType = NewClsTInfo->getType();
4048 else {
4049 NewClsType = getDerived().TransformType(OldClsType);
4050 if (NewClsType.isNull())
4051 return QualType();
4052 }
Mike Stump11289f42009-09-09 15:08:12 +00004053
John McCall550e0c22009-10-21 00:40:46 +00004054 QualType Result = TL.getType();
4055 if (getDerived().AlwaysRebuild() ||
4056 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004057 NewClsType != OldClsType) {
4058 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004059 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004060 if (Result.isNull())
4061 return QualType();
4062 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004063
Reid Kleckner0503a872013-12-05 01:23:43 +00004064 // If we had to adjust the pointee type when building a member pointer, make
4065 // sure to push TypeLoc info for it.
4066 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4067 if (MPT && PointeeType != MPT->getPointeeType()) {
4068 assert(isa<AdjustedType>(MPT->getPointeeType()));
4069 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4070 }
4071
John McCall550e0c22009-10-21 00:40:46 +00004072 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4073 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004074 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004075
4076 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004077}
4078
Mike Stump11289f42009-09-09 15:08:12 +00004079template<typename Derived>
4080QualType
John McCall550e0c22009-10-21 00:40:46 +00004081TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004082 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004083 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004084 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004085 if (ElementType.isNull())
4086 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004087
John McCall550e0c22009-10-21 00:40:46 +00004088 QualType Result = TL.getType();
4089 if (getDerived().AlwaysRebuild() ||
4090 ElementType != T->getElementType()) {
4091 Result = getDerived().RebuildConstantArrayType(ElementType,
4092 T->getSizeModifier(),
4093 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004094 T->getIndexTypeCVRQualifiers(),
4095 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004096 if (Result.isNull())
4097 return QualType();
4098 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004099
4100 // We might have either a ConstantArrayType or a VariableArrayType now:
4101 // a ConstantArrayType is allowed to have an element type which is a
4102 // VariableArrayType if the type is dependent. Fortunately, all array
4103 // types have the same location layout.
4104 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004105 NewTL.setLBracketLoc(TL.getLBracketLoc());
4106 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004107
John McCall550e0c22009-10-21 00:40:46 +00004108 Expr *Size = TL.getSizeExpr();
4109 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004110 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4111 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004112 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4113 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004114 }
4115 NewTL.setSizeExpr(Size);
4116
4117 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004118}
Mike Stump11289f42009-09-09 15:08:12 +00004119
Douglas Gregord6ff3322009-08-04 16:50:30 +00004120template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004121QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004122 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004123 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004124 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004125 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004126 if (ElementType.isNull())
4127 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004128
John McCall550e0c22009-10-21 00:40:46 +00004129 QualType Result = TL.getType();
4130 if (getDerived().AlwaysRebuild() ||
4131 ElementType != T->getElementType()) {
4132 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004133 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004134 T->getIndexTypeCVRQualifiers(),
4135 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004136 if (Result.isNull())
4137 return QualType();
4138 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004139
John McCall550e0c22009-10-21 00:40:46 +00004140 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4141 NewTL.setLBracketLoc(TL.getLBracketLoc());
4142 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004143 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004144
4145 return Result;
4146}
4147
4148template<typename Derived>
4149QualType
4150TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004151 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004152 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004153 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4154 if (ElementType.isNull())
4155 return QualType();
4156
John McCalldadc5752010-08-24 06:29:42 +00004157 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004158 = getDerived().TransformExpr(T->getSizeExpr());
4159 if (SizeResult.isInvalid())
4160 return QualType();
4161
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004162 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004163
4164 QualType Result = TL.getType();
4165 if (getDerived().AlwaysRebuild() ||
4166 ElementType != T->getElementType() ||
4167 Size != T->getSizeExpr()) {
4168 Result = getDerived().RebuildVariableArrayType(ElementType,
4169 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004170 Size,
John McCall550e0c22009-10-21 00:40:46 +00004171 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004172 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004173 if (Result.isNull())
4174 return QualType();
4175 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004176
Serge Pavlov774c6d02014-02-06 03:49:11 +00004177 // We might have constant size array now, but fortunately it has the same
4178 // location layout.
4179 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004180 NewTL.setLBracketLoc(TL.getLBracketLoc());
4181 NewTL.setRBracketLoc(TL.getRBracketLoc());
4182 NewTL.setSizeExpr(Size);
4183
4184 return Result;
4185}
4186
4187template<typename Derived>
4188QualType
4189TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004190 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004191 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004192 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4193 if (ElementType.isNull())
4194 return QualType();
4195
Richard Smith764d2fe2011-12-20 02:08:33 +00004196 // Array bounds are constant expressions.
4197 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4198 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004199
John McCall33ddac02011-01-19 10:06:00 +00004200 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4201 Expr *origSize = TL.getSizeExpr();
4202 if (!origSize) origSize = T->getSizeExpr();
4203
4204 ExprResult sizeResult
4205 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004206 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004207 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004208 return QualType();
4209
John McCall33ddac02011-01-19 10:06:00 +00004210 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004211
4212 QualType Result = TL.getType();
4213 if (getDerived().AlwaysRebuild() ||
4214 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004215 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004216 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4217 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004218 size,
John McCall550e0c22009-10-21 00:40:46 +00004219 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004220 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004221 if (Result.isNull())
4222 return QualType();
4223 }
John McCall550e0c22009-10-21 00:40:46 +00004224
4225 // We might have any sort of array type now, but fortunately they
4226 // all have the same location layout.
4227 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4228 NewTL.setLBracketLoc(TL.getLBracketLoc());
4229 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004230 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004231
4232 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004233}
Mike Stump11289f42009-09-09 15:08:12 +00004234
4235template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004236QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004237 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004238 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004239 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004240
4241 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004242 QualType ElementType = getDerived().TransformType(T->getElementType());
4243 if (ElementType.isNull())
4244 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004245
Richard Smith764d2fe2011-12-20 02:08:33 +00004246 // Vector sizes are constant expressions.
4247 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4248 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004249
John McCalldadc5752010-08-24 06:29:42 +00004250 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004251 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004252 if (Size.isInvalid())
4253 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004254
John McCall550e0c22009-10-21 00:40:46 +00004255 QualType Result = TL.getType();
4256 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004257 ElementType != T->getElementType() ||
4258 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004259 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004260 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004261 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004262 if (Result.isNull())
4263 return QualType();
4264 }
John McCall550e0c22009-10-21 00:40:46 +00004265
4266 // Result might be dependent or not.
4267 if (isa<DependentSizedExtVectorType>(Result)) {
4268 DependentSizedExtVectorTypeLoc NewTL
4269 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4270 NewTL.setNameLoc(TL.getNameLoc());
4271 } else {
4272 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4273 NewTL.setNameLoc(TL.getNameLoc());
4274 }
4275
4276 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004277}
Mike Stump11289f42009-09-09 15:08:12 +00004278
4279template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004280QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004281 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004282 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004283 QualType ElementType = getDerived().TransformType(T->getElementType());
4284 if (ElementType.isNull())
4285 return QualType();
4286
John McCall550e0c22009-10-21 00:40:46 +00004287 QualType Result = TL.getType();
4288 if (getDerived().AlwaysRebuild() ||
4289 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004290 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004291 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004292 if (Result.isNull())
4293 return QualType();
4294 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004295
John McCall550e0c22009-10-21 00:40:46 +00004296 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4297 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004298
John McCall550e0c22009-10-21 00:40:46 +00004299 return Result;
4300}
4301
4302template<typename Derived>
4303QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004304 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004305 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004306 QualType ElementType = getDerived().TransformType(T->getElementType());
4307 if (ElementType.isNull())
4308 return QualType();
4309
4310 QualType Result = TL.getType();
4311 if (getDerived().AlwaysRebuild() ||
4312 ElementType != T->getElementType()) {
4313 Result = getDerived().RebuildExtVectorType(ElementType,
4314 T->getNumElements(),
4315 /*FIXME*/ SourceLocation());
4316 if (Result.isNull())
4317 return QualType();
4318 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004319
John McCall550e0c22009-10-21 00:40:46 +00004320 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4321 NewTL.setNameLoc(TL.getNameLoc());
4322
4323 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004324}
Mike Stump11289f42009-09-09 15:08:12 +00004325
David Blaikie05785d12013-02-20 22:23:23 +00004326template <typename Derived>
4327ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4328 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4329 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004330 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004331 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004332
Douglas Gregor715e4612011-01-14 22:40:04 +00004333 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004334 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004335 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004336 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004337 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004338
Douglas Gregor715e4612011-01-14 22:40:04 +00004339 TypeLocBuilder TLB;
4340 TypeLoc NewTL = OldDI->getTypeLoc();
4341 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004342
4343 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004344 OldExpansionTL.getPatternLoc());
4345 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004346 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004347
4348 Result = RebuildPackExpansionType(Result,
4349 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004350 OldExpansionTL.getEllipsisLoc(),
4351 NumExpansions);
4352 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004353 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004354
Douglas Gregor715e4612011-01-14 22:40:04 +00004355 PackExpansionTypeLoc NewExpansionTL
4356 = TLB.push<PackExpansionTypeLoc>(Result);
4357 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4358 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4359 } else
4360 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004361 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004362 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004363
John McCall8fb0d9d2011-05-01 22:35:37 +00004364 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004365 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004366
4367 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4368 OldParm->getDeclContext(),
4369 OldParm->getInnerLocStart(),
4370 OldParm->getLocation(),
4371 OldParm->getIdentifier(),
4372 NewDI->getType(),
4373 NewDI,
4374 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004375 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004376 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4377 OldParm->getFunctionScopeIndex() + indexAdjustment);
4378 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004379}
4380
4381template<typename Derived>
4382bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004383 TransformFunctionTypeParams(SourceLocation Loc,
4384 ParmVarDecl **Params, unsigned NumParams,
4385 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004386 SmallVectorImpl<QualType> &OutParamTypes,
4387 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004388 int indexAdjustment = 0;
4389
Douglas Gregordd472162011-01-07 00:20:55 +00004390 for (unsigned i = 0; i != NumParams; ++i) {
4391 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004392 assert(OldParm->getFunctionScopeIndex() == i);
4393
David Blaikie05785d12013-02-20 22:23:23 +00004394 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004395 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004396 if (OldParm->isParameterPack()) {
4397 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004398 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004399
Douglas Gregor5499af42011-01-05 23:12:31 +00004400 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004401 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004402 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004403 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4404 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004405 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4406
Douglas Gregor5499af42011-01-05 23:12:31 +00004407 // Determine whether we should expand the parameter packs.
4408 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004409 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004410 Optional<unsigned> OrigNumExpansions =
4411 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004412 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004413 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4414 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004415 Unexpanded,
4416 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004417 RetainExpansion,
4418 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004419 return true;
4420 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004421
Douglas Gregor5499af42011-01-05 23:12:31 +00004422 if (ShouldExpand) {
4423 // Expand the function parameter pack into multiple, separate
4424 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004425 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004426 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004427 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004428 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004429 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004430 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004431 OrigNumExpansions,
4432 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004433 if (!NewParm)
4434 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004435
Douglas Gregordd472162011-01-07 00:20:55 +00004436 OutParamTypes.push_back(NewParm->getType());
4437 if (PVars)
4438 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004439 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004440
4441 // If we're supposed to retain a pack expansion, do so by temporarily
4442 // forgetting the partially-substituted parameter pack.
4443 if (RetainExpansion) {
4444 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004445 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004446 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004447 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004448 OrigNumExpansions,
4449 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004450 if (!NewParm)
4451 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004452
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004453 OutParamTypes.push_back(NewParm->getType());
4454 if (PVars)
4455 PVars->push_back(NewParm);
4456 }
4457
John McCall8fb0d9d2011-05-01 22:35:37 +00004458 // The next parameter should have the same adjustment as the
4459 // last thing we pushed, but we post-incremented indexAdjustment
4460 // on every push. Also, if we push nothing, the adjustment should
4461 // go down by one.
4462 indexAdjustment--;
4463
Douglas Gregor5499af42011-01-05 23:12:31 +00004464 // We're done with the pack expansion.
4465 continue;
4466 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004467
4468 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004469 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004470 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4471 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004472 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004473 NumExpansions,
4474 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004475 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004476 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004477 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004478 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004479
John McCall58f10c32010-03-11 09:03:00 +00004480 if (!NewParm)
4481 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004482
Douglas Gregordd472162011-01-07 00:20:55 +00004483 OutParamTypes.push_back(NewParm->getType());
4484 if (PVars)
4485 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004486 continue;
4487 }
John McCall58f10c32010-03-11 09:03:00 +00004488
4489 // Deal with the possibility that we don't have a parameter
4490 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004491 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004492 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004493 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004494 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004495 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004496 = dyn_cast<PackExpansionType>(OldType)) {
4497 // We have a function parameter pack that may need to be expanded.
4498 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004499 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004500 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004501
Douglas Gregor5499af42011-01-05 23:12:31 +00004502 // Determine whether we should expand the parameter packs.
4503 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004504 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004505 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004506 Unexpanded,
4507 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004508 RetainExpansion,
4509 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004510 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004511 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004512
Douglas Gregor5499af42011-01-05 23:12:31 +00004513 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004514 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004515 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004516 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004517 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4518 QualType NewType = getDerived().TransformType(Pattern);
4519 if (NewType.isNull())
4520 return true;
John McCall58f10c32010-03-11 09:03:00 +00004521
Douglas Gregordd472162011-01-07 00:20:55 +00004522 OutParamTypes.push_back(NewType);
4523 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004524 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004525 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004526
Douglas Gregor5499af42011-01-05 23:12:31 +00004527 // We're done with the pack expansion.
4528 continue;
4529 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004530
Douglas Gregor48d24112011-01-10 20:53:55 +00004531 // If we're supposed to retain a pack expansion, do so by temporarily
4532 // forgetting the partially-substituted parameter pack.
4533 if (RetainExpansion) {
4534 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4535 QualType NewType = getDerived().TransformType(Pattern);
4536 if (NewType.isNull())
4537 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004538
Douglas Gregor48d24112011-01-10 20:53:55 +00004539 OutParamTypes.push_back(NewType);
4540 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004541 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004542 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004543
Chad Rosier1dcde962012-08-08 18:46:20 +00004544 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004545 // expansion.
4546 OldType = Expansion->getPattern();
4547 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004548 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4549 NewType = getDerived().TransformType(OldType);
4550 } else {
4551 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004552 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004553
Douglas Gregor5499af42011-01-05 23:12:31 +00004554 if (NewType.isNull())
4555 return true;
4556
4557 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004558 NewType = getSema().Context.getPackExpansionType(NewType,
4559 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004560
Douglas Gregordd472162011-01-07 00:20:55 +00004561 OutParamTypes.push_back(NewType);
4562 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004563 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004564 }
4565
John McCall8fb0d9d2011-05-01 22:35:37 +00004566#ifndef NDEBUG
4567 if (PVars) {
4568 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4569 if (ParmVarDecl *parm = (*PVars)[i])
4570 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004571 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004572#endif
4573
4574 return false;
4575}
John McCall58f10c32010-03-11 09:03:00 +00004576
4577template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004578QualType
John McCall550e0c22009-10-21 00:40:46 +00004579TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004580 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004581 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004582 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004583 return getDerived().TransformFunctionProtoType(
4584 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004585 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4586 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4587 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004588 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004589}
4590
Richard Smith2e321552014-11-12 02:00:47 +00004591template<typename Derived> template<typename Fn>
4592QualType TreeTransform<Derived>::TransformFunctionProtoType(
4593 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4594 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004595 // Transform the parameters and return type.
4596 //
Richard Smithf623c962012-04-17 00:58:00 +00004597 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004598 // When the function has a trailing return type, we instantiate the
4599 // parameters before the return type, since the return type can then refer
4600 // to the parameters themselves (via decltype, sizeof, etc.).
4601 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004602 SmallVector<QualType, 4> ParamTypes;
4603 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004604 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004605
Douglas Gregor7fb25412010-10-01 18:44:50 +00004606 QualType ResultType;
4607
Richard Smith1226c602012-08-14 22:51:13 +00004608 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004609 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004610 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004611 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004612 return QualType();
4613
Douglas Gregor3024f072012-04-16 07:05:22 +00004614 {
4615 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004616 // If a declaration declares a member function or member function
4617 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004618 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004619 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004620 // declarator.
4621 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004622
Alp Toker42a16a62014-01-25 23:51:36 +00004623 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004624 if (ResultType.isNull())
4625 return QualType();
4626 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004627 }
4628 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004629 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004630 if (ResultType.isNull())
4631 return QualType();
4632
Alp Toker9cacbab2014-01-20 20:26:09 +00004633 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004634 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004635 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004636 return QualType();
4637 }
4638
Richard Smith2e321552014-11-12 02:00:47 +00004639 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4640
4641 bool EPIChanged = false;
4642 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4643 return QualType();
4644
4645 // FIXME: Need to transform ConsumedParameters for variadic template
4646 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004647
John McCall550e0c22009-10-21 00:40:46 +00004648 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004649 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004650 T->getNumParams() != ParamTypes.size() ||
4651 !std::equal(T->param_type_begin(), T->param_type_end(),
Richard Smith2e321552014-11-12 02:00:47 +00004652 ParamTypes.begin()) || EPIChanged) {
4653 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004654 if (Result.isNull())
4655 return QualType();
4656 }
Mike Stump11289f42009-09-09 15:08:12 +00004657
John McCall550e0c22009-10-21 00:40:46 +00004658 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004659 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004660 NewTL.setLParenLoc(TL.getLParenLoc());
4661 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004662 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004663 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4664 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004665
4666 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004667}
Mike Stump11289f42009-09-09 15:08:12 +00004668
Douglas Gregord6ff3322009-08-04 16:50:30 +00004669template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004670bool TreeTransform<Derived>::TransformExceptionSpec(
4671 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4672 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4673 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4674
4675 // Instantiate a dynamic noexcept expression, if any.
4676 if (ESI.Type == EST_ComputedNoexcept) {
4677 EnterExpressionEvaluationContext Unevaluated(getSema(),
4678 Sema::ConstantEvaluated);
4679 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4680 if (NoexceptExpr.isInvalid())
4681 return true;
4682
4683 NoexceptExpr = getSema().CheckBooleanCondition(
4684 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4685 if (NoexceptExpr.isInvalid())
4686 return true;
4687
4688 if (!NoexceptExpr.get()->isValueDependent()) {
4689 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4690 NoexceptExpr.get(), nullptr,
4691 diag::err_noexcept_needs_constant_expression,
4692 /*AllowFold*/false);
4693 if (NoexceptExpr.isInvalid())
4694 return true;
4695 }
4696
4697 if (ESI.NoexceptExpr != NoexceptExpr.get())
4698 Changed = true;
4699 ESI.NoexceptExpr = NoexceptExpr.get();
4700 }
4701
4702 if (ESI.Type != EST_Dynamic)
4703 return false;
4704
4705 // Instantiate a dynamic exception specification's type.
4706 for (QualType T : ESI.Exceptions) {
4707 if (const PackExpansionType *PackExpansion =
4708 T->getAs<PackExpansionType>()) {
4709 Changed = true;
4710
4711 // We have a pack expansion. Instantiate it.
4712 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4713 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4714 Unexpanded);
4715 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4716
4717 // Determine whether the set of unexpanded parameter packs can and
4718 // should
4719 // be expanded.
4720 bool Expand = false;
4721 bool RetainExpansion = false;
4722 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4723 // FIXME: Track the location of the ellipsis (and track source location
4724 // information for the types in the exception specification in general).
4725 if (getDerived().TryExpandParameterPacks(
4726 Loc, SourceRange(), Unexpanded, Expand,
4727 RetainExpansion, NumExpansions))
4728 return true;
4729
4730 if (!Expand) {
4731 // We can't expand this pack expansion into separate arguments yet;
4732 // just substitute into the pattern and create a new pack expansion
4733 // type.
4734 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4735 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4736 if (U.isNull())
4737 return true;
4738
4739 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4740 Exceptions.push_back(U);
4741 continue;
4742 }
4743
4744 // Substitute into the pack expansion pattern for each slice of the
4745 // pack.
4746 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4747 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4748
4749 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4750 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4751 return true;
4752
4753 Exceptions.push_back(U);
4754 }
4755 } else {
4756 QualType U = getDerived().TransformType(T);
4757 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4758 return true;
4759 if (T != U)
4760 Changed = true;
4761
4762 Exceptions.push_back(U);
4763 }
4764 }
4765
4766 ESI.Exceptions = Exceptions;
4767 return false;
4768}
4769
4770template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004771QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004772 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004773 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004774 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004775 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004776 if (ResultType.isNull())
4777 return QualType();
4778
4779 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004780 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004781 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4782
4783 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004784 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004785 NewTL.setLParenLoc(TL.getLParenLoc());
4786 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004787 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004788
4789 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004790}
Mike Stump11289f42009-09-09 15:08:12 +00004791
John McCallb96ec562009-12-04 22:46:56 +00004792template<typename Derived> QualType
4793TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004794 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004795 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004796 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004797 if (!D)
4798 return QualType();
4799
4800 QualType Result = TL.getType();
4801 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4802 Result = getDerived().RebuildUnresolvedUsingType(D);
4803 if (Result.isNull())
4804 return QualType();
4805 }
4806
4807 // We might get an arbitrary type spec type back. We should at
4808 // least always get a type spec type, though.
4809 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4810 NewTL.setNameLoc(TL.getNameLoc());
4811
4812 return Result;
4813}
4814
Douglas Gregord6ff3322009-08-04 16:50:30 +00004815template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004816QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004817 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004818 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004819 TypedefNameDecl *Typedef
4820 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4821 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004822 if (!Typedef)
4823 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004824
John McCall550e0c22009-10-21 00:40:46 +00004825 QualType Result = TL.getType();
4826 if (getDerived().AlwaysRebuild() ||
4827 Typedef != T->getDecl()) {
4828 Result = getDerived().RebuildTypedefType(Typedef);
4829 if (Result.isNull())
4830 return QualType();
4831 }
Mike Stump11289f42009-09-09 15:08:12 +00004832
John McCall550e0c22009-10-21 00:40:46 +00004833 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4834 NewTL.setNameLoc(TL.getNameLoc());
4835
4836 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004837}
Mike Stump11289f42009-09-09 15:08:12 +00004838
Douglas Gregord6ff3322009-08-04 16:50:30 +00004839template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004840QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004841 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004842 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004843 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4844 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004845
John McCalldadc5752010-08-24 06:29:42 +00004846 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004847 if (E.isInvalid())
4848 return QualType();
4849
Eli Friedmane4f22df2012-02-29 04:03:55 +00004850 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4851 if (E.isInvalid())
4852 return QualType();
4853
John McCall550e0c22009-10-21 00:40:46 +00004854 QualType Result = TL.getType();
4855 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004856 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004857 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004858 if (Result.isNull())
4859 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004860 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004861 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004862
John McCall550e0c22009-10-21 00:40:46 +00004863 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004864 NewTL.setTypeofLoc(TL.getTypeofLoc());
4865 NewTL.setLParenLoc(TL.getLParenLoc());
4866 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004867
4868 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004869}
Mike Stump11289f42009-09-09 15:08:12 +00004870
4871template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004872QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004873 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004874 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4875 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4876 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004877 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004878
John McCall550e0c22009-10-21 00:40:46 +00004879 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004880 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4881 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004882 if (Result.isNull())
4883 return QualType();
4884 }
Mike Stump11289f42009-09-09 15:08:12 +00004885
John McCall550e0c22009-10-21 00:40:46 +00004886 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004887 NewTL.setTypeofLoc(TL.getTypeofLoc());
4888 NewTL.setLParenLoc(TL.getLParenLoc());
4889 NewTL.setRParenLoc(TL.getRParenLoc());
4890 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004891
4892 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004893}
Mike Stump11289f42009-09-09 15:08:12 +00004894
4895template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004896QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004897 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004898 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004899
Douglas Gregore922c772009-08-04 22:27:00 +00004900 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004901 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4902 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004903
John McCalldadc5752010-08-24 06:29:42 +00004904 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004905 if (E.isInvalid())
4906 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004907
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004908 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004909 if (E.isInvalid())
4910 return QualType();
4911
John McCall550e0c22009-10-21 00:40:46 +00004912 QualType Result = TL.getType();
4913 if (getDerived().AlwaysRebuild() ||
4914 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004915 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004916 if (Result.isNull())
4917 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004918 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004919 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004920
John McCall550e0c22009-10-21 00:40:46 +00004921 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4922 NewTL.setNameLoc(TL.getNameLoc());
4923
4924 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004925}
4926
4927template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004928QualType TreeTransform<Derived>::TransformUnaryTransformType(
4929 TypeLocBuilder &TLB,
4930 UnaryTransformTypeLoc TL) {
4931 QualType Result = TL.getType();
4932 if (Result->isDependentType()) {
4933 const UnaryTransformType *T = TL.getTypePtr();
4934 QualType NewBase =
4935 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4936 Result = getDerived().RebuildUnaryTransformType(NewBase,
4937 T->getUTTKind(),
4938 TL.getKWLoc());
4939 if (Result.isNull())
4940 return QualType();
4941 }
4942
4943 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4944 NewTL.setKWLoc(TL.getKWLoc());
4945 NewTL.setParensRange(TL.getParensRange());
4946 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4947 return Result;
4948}
4949
4950template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004951QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4952 AutoTypeLoc TL) {
4953 const AutoType *T = TL.getTypePtr();
4954 QualType OldDeduced = T->getDeducedType();
4955 QualType NewDeduced;
4956 if (!OldDeduced.isNull()) {
4957 NewDeduced = getDerived().TransformType(OldDeduced);
4958 if (NewDeduced.isNull())
4959 return QualType();
4960 }
4961
4962 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004963 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4964 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004965 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004966 if (Result.isNull())
4967 return QualType();
4968 }
4969
4970 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4971 NewTL.setNameLoc(TL.getNameLoc());
4972
4973 return Result;
4974}
4975
4976template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004977QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004978 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004979 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004980 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004981 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4982 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004983 if (!Record)
4984 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004985
John McCall550e0c22009-10-21 00:40:46 +00004986 QualType Result = TL.getType();
4987 if (getDerived().AlwaysRebuild() ||
4988 Record != T->getDecl()) {
4989 Result = getDerived().RebuildRecordType(Record);
4990 if (Result.isNull())
4991 return QualType();
4992 }
Mike Stump11289f42009-09-09 15:08:12 +00004993
John McCall550e0c22009-10-21 00:40:46 +00004994 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4995 NewTL.setNameLoc(TL.getNameLoc());
4996
4997 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004998}
Mike Stump11289f42009-09-09 15:08:12 +00004999
5000template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005001QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005002 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005003 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005004 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005005 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5006 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005007 if (!Enum)
5008 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005009
John McCall550e0c22009-10-21 00:40:46 +00005010 QualType Result = TL.getType();
5011 if (getDerived().AlwaysRebuild() ||
5012 Enum != T->getDecl()) {
5013 Result = getDerived().RebuildEnumType(Enum);
5014 if (Result.isNull())
5015 return QualType();
5016 }
Mike Stump11289f42009-09-09 15:08:12 +00005017
John McCall550e0c22009-10-21 00:40:46 +00005018 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5019 NewTL.setNameLoc(TL.getNameLoc());
5020
5021 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005022}
John McCallfcc33b02009-09-05 00:15:47 +00005023
John McCalle78aac42010-03-10 03:28:59 +00005024template<typename Derived>
5025QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5026 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005027 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005028 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5029 TL.getTypePtr()->getDecl());
5030 if (!D) return QualType();
5031
5032 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5033 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5034 return T;
5035}
5036
Douglas Gregord6ff3322009-08-04 16:50:30 +00005037template<typename Derived>
5038QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005039 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005040 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005041 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005042}
5043
Mike Stump11289f42009-09-09 15:08:12 +00005044template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005045QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005046 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005047 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005048 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005049
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005050 // Substitute into the replacement type, which itself might involve something
5051 // that needs to be transformed. This only tends to occur with default
5052 // template arguments of template template parameters.
5053 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5054 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5055 if (Replacement.isNull())
5056 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005057
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005058 // Always canonicalize the replacement type.
5059 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5060 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005061 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005062 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005063
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005064 // Propagate type-source information.
5065 SubstTemplateTypeParmTypeLoc NewTL
5066 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5067 NewTL.setNameLoc(TL.getNameLoc());
5068 return Result;
5069
John McCallcebee162009-10-18 09:09:24 +00005070}
5071
5072template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005073QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5074 TypeLocBuilder &TLB,
5075 SubstTemplateTypeParmPackTypeLoc TL) {
5076 return TransformTypeSpecType(TLB, TL);
5077}
5078
5079template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005080QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005081 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005082 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005083 const TemplateSpecializationType *T = TL.getTypePtr();
5084
Douglas Gregordf846d12011-03-02 18:46:51 +00005085 // The nested-name-specifier never matters in a TemplateSpecializationType,
5086 // because we can't have a dependent nested-name-specifier anyway.
5087 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005088 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005089 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5090 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005091 if (Template.isNull())
5092 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005093
John McCall31f82722010-11-12 08:19:04 +00005094 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5095}
5096
Eli Friedman0dfb8892011-10-06 23:00:33 +00005097template<typename Derived>
5098QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5099 AtomicTypeLoc TL) {
5100 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5101 if (ValueType.isNull())
5102 return QualType();
5103
5104 QualType Result = TL.getType();
5105 if (getDerived().AlwaysRebuild() ||
5106 ValueType != TL.getValueLoc().getType()) {
5107 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5108 if (Result.isNull())
5109 return QualType();
5110 }
5111
5112 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5113 NewTL.setKWLoc(TL.getKWLoc());
5114 NewTL.setLParenLoc(TL.getLParenLoc());
5115 NewTL.setRParenLoc(TL.getRParenLoc());
5116
5117 return Result;
5118}
5119
Chad Rosier1dcde962012-08-08 18:46:20 +00005120 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005121 /// container that provides a \c getArgLoc() member function.
5122 ///
5123 /// This iterator is intended to be used with the iterator form of
5124 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5125 template<typename ArgLocContainer>
5126 class TemplateArgumentLocContainerIterator {
5127 ArgLocContainer *Container;
5128 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005129
Douglas Gregorfe921a72010-12-20 23:36:19 +00005130 public:
5131 typedef TemplateArgumentLoc value_type;
5132 typedef TemplateArgumentLoc reference;
5133 typedef int difference_type;
5134 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005135
Douglas Gregorfe921a72010-12-20 23:36:19 +00005136 class pointer {
5137 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005138
Douglas Gregorfe921a72010-12-20 23:36:19 +00005139 public:
5140 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005141
Douglas Gregorfe921a72010-12-20 23:36:19 +00005142 const TemplateArgumentLoc *operator->() const {
5143 return &Arg;
5144 }
5145 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005146
5147
Douglas Gregorfe921a72010-12-20 23:36:19 +00005148 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005149
Douglas Gregorfe921a72010-12-20 23:36:19 +00005150 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5151 unsigned Index)
5152 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005153
Douglas Gregorfe921a72010-12-20 23:36:19 +00005154 TemplateArgumentLocContainerIterator &operator++() {
5155 ++Index;
5156 return *this;
5157 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005158
Douglas Gregorfe921a72010-12-20 23:36:19 +00005159 TemplateArgumentLocContainerIterator operator++(int) {
5160 TemplateArgumentLocContainerIterator Old(*this);
5161 ++(*this);
5162 return Old;
5163 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005164
Douglas Gregorfe921a72010-12-20 23:36:19 +00005165 TemplateArgumentLoc operator*() const {
5166 return Container->getArgLoc(Index);
5167 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005168
Douglas Gregorfe921a72010-12-20 23:36:19 +00005169 pointer operator->() const {
5170 return pointer(Container->getArgLoc(Index));
5171 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005172
Douglas Gregorfe921a72010-12-20 23:36:19 +00005173 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005174 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005175 return X.Container == Y.Container && X.Index == Y.Index;
5176 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005177
Douglas Gregorfe921a72010-12-20 23:36:19 +00005178 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005179 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005180 return !(X == Y);
5181 }
5182 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005183
5184
John McCall31f82722010-11-12 08:19:04 +00005185template <typename Derived>
5186QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5187 TypeLocBuilder &TLB,
5188 TemplateSpecializationTypeLoc TL,
5189 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005190 TemplateArgumentListInfo NewTemplateArgs;
5191 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5192 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005193 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5194 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005195 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005196 ArgIterator(TL, TL.getNumArgs()),
5197 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005198 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005199
John McCall0ad16662009-10-29 08:12:44 +00005200 // FIXME: maybe don't rebuild if all the template arguments are the same.
5201
5202 QualType Result =
5203 getDerived().RebuildTemplateSpecializationType(Template,
5204 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005205 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005206
5207 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005208 // Specializations of template template parameters are represented as
5209 // TemplateSpecializationTypes, and substitution of type alias templates
5210 // within a dependent context can transform them into
5211 // DependentTemplateSpecializationTypes.
5212 if (isa<DependentTemplateSpecializationType>(Result)) {
5213 DependentTemplateSpecializationTypeLoc NewTL
5214 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005215 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005216 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005217 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005218 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005219 NewTL.setLAngleLoc(TL.getLAngleLoc());
5220 NewTL.setRAngleLoc(TL.getRAngleLoc());
5221 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5222 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5223 return Result;
5224 }
5225
John McCall0ad16662009-10-29 08:12:44 +00005226 TemplateSpecializationTypeLoc NewTL
5227 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005228 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005229 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5230 NewTL.setLAngleLoc(TL.getLAngleLoc());
5231 NewTL.setRAngleLoc(TL.getRAngleLoc());
5232 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5233 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005234 }
Mike Stump11289f42009-09-09 15:08:12 +00005235
John McCall0ad16662009-10-29 08:12:44 +00005236 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005237}
Mike Stump11289f42009-09-09 15:08:12 +00005238
Douglas Gregor5a064722011-02-28 17:23:35 +00005239template <typename Derived>
5240QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5241 TypeLocBuilder &TLB,
5242 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005243 TemplateName Template,
5244 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005245 TemplateArgumentListInfo NewTemplateArgs;
5246 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5247 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5248 typedef TemplateArgumentLocContainerIterator<
5249 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005250 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005251 ArgIterator(TL, TL.getNumArgs()),
5252 NewTemplateArgs))
5253 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005254
Douglas Gregor5a064722011-02-28 17:23:35 +00005255 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005256
Douglas Gregor5a064722011-02-28 17:23:35 +00005257 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5258 QualType Result
5259 = getSema().Context.getDependentTemplateSpecializationType(
5260 TL.getTypePtr()->getKeyword(),
5261 DTN->getQualifier(),
5262 DTN->getIdentifier(),
5263 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005264
Douglas Gregor5a064722011-02-28 17:23:35 +00005265 DependentTemplateSpecializationTypeLoc NewTL
5266 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005267 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005268 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005269 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005270 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005271 NewTL.setLAngleLoc(TL.getLAngleLoc());
5272 NewTL.setRAngleLoc(TL.getRAngleLoc());
5273 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5274 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5275 return Result;
5276 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005277
5278 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005279 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005280 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005281 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005282
Douglas Gregor5a064722011-02-28 17:23:35 +00005283 if (!Result.isNull()) {
5284 /// FIXME: Wrap this in an elaborated-type-specifier?
5285 TemplateSpecializationTypeLoc NewTL
5286 = TLB.push<TemplateSpecializationTypeLoc>(Result);
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 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005294
Douglas Gregor5a064722011-02-28 17:23:35 +00005295 return Result;
5296}
5297
Mike Stump11289f42009-09-09 15:08:12 +00005298template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005299QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005300TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005301 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005302 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005303
Douglas Gregor844cb502011-03-01 18:12:44 +00005304 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005305 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005306 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005307 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005308 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5309 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005310 return QualType();
5311 }
Mike Stump11289f42009-09-09 15:08:12 +00005312
John McCall31f82722010-11-12 08:19:04 +00005313 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5314 if (NamedT.isNull())
5315 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005316
Richard Smith3f1b5d02011-05-05 21:57:07 +00005317 // C++0x [dcl.type.elab]p2:
5318 // If the identifier resolves to a typedef-name or the simple-template-id
5319 // resolves to an alias template specialization, the
5320 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005321 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5322 if (const TemplateSpecializationType *TST =
5323 NamedT->getAs<TemplateSpecializationType>()) {
5324 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005325 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5326 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005327 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5328 diag::err_tag_reference_non_tag) << 4;
5329 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5330 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005331 }
5332 }
5333
John McCall550e0c22009-10-21 00:40:46 +00005334 QualType Result = TL.getType();
5335 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005336 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005337 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005338 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005339 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005340 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005341 if (Result.isNull())
5342 return QualType();
5343 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005344
Abramo Bagnara6150c882010-05-11 21:36:43 +00005345 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005346 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005347 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005348 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005349}
Mike Stump11289f42009-09-09 15:08:12 +00005350
5351template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005352QualType TreeTransform<Derived>::TransformAttributedType(
5353 TypeLocBuilder &TLB,
5354 AttributedTypeLoc TL) {
5355 const AttributedType *oldType = TL.getTypePtr();
5356 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5357 if (modifiedType.isNull())
5358 return QualType();
5359
5360 QualType result = TL.getType();
5361
5362 // FIXME: dependent operand expressions?
5363 if (getDerived().AlwaysRebuild() ||
5364 modifiedType != oldType->getModifiedType()) {
5365 // TODO: this is really lame; we should really be rebuilding the
5366 // equivalent type from first principles.
5367 QualType equivalentType
5368 = getDerived().TransformType(oldType->getEquivalentType());
5369 if (equivalentType.isNull())
5370 return QualType();
5371 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5372 modifiedType,
5373 equivalentType);
5374 }
5375
5376 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5377 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5378 if (TL.hasAttrOperand())
5379 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5380 if (TL.hasAttrExprOperand())
5381 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5382 else if (TL.hasAttrEnumOperand())
5383 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5384
5385 return result;
5386}
5387
5388template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005389QualType
5390TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5391 ParenTypeLoc TL) {
5392 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5393 if (Inner.isNull())
5394 return QualType();
5395
5396 QualType Result = TL.getType();
5397 if (getDerived().AlwaysRebuild() ||
5398 Inner != TL.getInnerLoc().getType()) {
5399 Result = getDerived().RebuildParenType(Inner);
5400 if (Result.isNull())
5401 return QualType();
5402 }
5403
5404 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5405 NewTL.setLParenLoc(TL.getLParenLoc());
5406 NewTL.setRParenLoc(TL.getRParenLoc());
5407 return Result;
5408}
5409
5410template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005411QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005412 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005413 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005414
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005415 NestedNameSpecifierLoc QualifierLoc
5416 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5417 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005418 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005419
John McCallc392f372010-06-11 00:33:02 +00005420 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005421 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005422 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005423 QualifierLoc,
5424 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005425 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005426 if (Result.isNull())
5427 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005428
Abramo Bagnarad7548482010-05-19 21:37:53 +00005429 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5430 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005431 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5432
Abramo Bagnarad7548482010-05-19 21:37:53 +00005433 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005434 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005435 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005436 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005437 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005438 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005439 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005440 NewTL.setNameLoc(TL.getNameLoc());
5441 }
John McCall550e0c22009-10-21 00:40:46 +00005442 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005443}
Mike Stump11289f42009-09-09 15:08:12 +00005444
Douglas Gregord6ff3322009-08-04 16:50:30 +00005445template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005446QualType TreeTransform<Derived>::
5447 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005448 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005449 NestedNameSpecifierLoc QualifierLoc;
5450 if (TL.getQualifierLoc()) {
5451 QualifierLoc
5452 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5453 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005454 return QualType();
5455 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005456
John McCall31f82722010-11-12 08:19:04 +00005457 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005458 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005459}
5460
5461template<typename Derived>
5462QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005463TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5464 DependentTemplateSpecializationTypeLoc TL,
5465 NestedNameSpecifierLoc QualifierLoc) {
5466 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005467
Douglas Gregora7a795b2011-03-01 20:11:18 +00005468 TemplateArgumentListInfo NewTemplateArgs;
5469 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5470 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005471
Douglas Gregora7a795b2011-03-01 20:11:18 +00005472 typedef TemplateArgumentLocContainerIterator<
5473 DependentTemplateSpecializationTypeLoc> ArgIterator;
5474 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5475 ArgIterator(TL, TL.getNumArgs()),
5476 NewTemplateArgs))
5477 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005478
Douglas Gregora7a795b2011-03-01 20:11:18 +00005479 QualType Result
5480 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5481 QualifierLoc,
5482 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005483 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005484 NewTemplateArgs);
5485 if (Result.isNull())
5486 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005487
Douglas Gregora7a795b2011-03-01 20:11:18 +00005488 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5489 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005490
Douglas Gregora7a795b2011-03-01 20:11:18 +00005491 // Copy information relevant to the template specialization.
5492 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005493 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005494 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005495 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005496 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5497 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005498 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005499 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005500
Douglas Gregora7a795b2011-03-01 20:11:18 +00005501 // Copy information relevant to the elaborated type.
5502 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005503 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005504 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005505 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5506 DependentTemplateSpecializationTypeLoc SpecTL
5507 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005508 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005509 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005510 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005511 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005512 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5513 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005514 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005515 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005516 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005517 TemplateSpecializationTypeLoc SpecTL
5518 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005519 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005520 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005521 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5522 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005523 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005524 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005525 }
5526 return Result;
5527}
5528
5529template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005530QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5531 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005532 QualType Pattern
5533 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005534 if (Pattern.isNull())
5535 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005536
5537 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005538 if (getDerived().AlwaysRebuild() ||
5539 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005540 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005541 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005542 TL.getEllipsisLoc(),
5543 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005544 if (Result.isNull())
5545 return QualType();
5546 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005547
Douglas Gregor822d0302011-01-12 17:07:58 +00005548 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5549 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5550 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005551}
5552
5553template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005554QualType
5555TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005556 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005557 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005558 TLB.pushFullCopy(TL);
5559 return TL.getType();
5560}
5561
5562template<typename Derived>
5563QualType
5564TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005565 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005566 // ObjCObjectType is never dependent.
5567 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005568 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005569}
Mike Stump11289f42009-09-09 15:08:12 +00005570
5571template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005572QualType
5573TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005574 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005575 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005576 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005577 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005578}
5579
Douglas Gregord6ff3322009-08-04 16:50:30 +00005580//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005581// Statement transformation
5582//===----------------------------------------------------------------------===//
5583template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005584StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005585TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005586 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005587}
5588
5589template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005590StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005591TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5592 return getDerived().TransformCompoundStmt(S, false);
5593}
5594
5595template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005596StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005597TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005598 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005599 Sema::CompoundScopeRAII CompoundScope(getSema());
5600
John McCall1ababa62010-08-27 19:56:05 +00005601 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005602 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005603 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005604 for (auto *B : S->body()) {
5605 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005606 if (Result.isInvalid()) {
5607 // Immediately fail if this was a DeclStmt, since it's very
5608 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005609 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005610 return StmtError();
5611
5612 // Otherwise, just keep processing substatements and fail later.
5613 SubStmtInvalid = true;
5614 continue;
5615 }
Mike Stump11289f42009-09-09 15:08:12 +00005616
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005617 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005618 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005619 }
Mike Stump11289f42009-09-09 15:08:12 +00005620
John McCall1ababa62010-08-27 19:56:05 +00005621 if (SubStmtInvalid)
5622 return StmtError();
5623
Douglas Gregorebe10102009-08-20 07:17:43 +00005624 if (!getDerived().AlwaysRebuild() &&
5625 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005626 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005627
5628 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005629 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005630 S->getRBracLoc(),
5631 IsStmtExpr);
5632}
Mike Stump11289f42009-09-09 15:08:12 +00005633
Douglas Gregorebe10102009-08-20 07:17:43 +00005634template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005635StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005636TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005637 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005638 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005639 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5640 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005641
Eli Friedman06577382009-11-19 03:14:00 +00005642 // Transform the left-hand case value.
5643 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005644 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005645 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005646 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005647
Eli Friedman06577382009-11-19 03:14:00 +00005648 // Transform the right-hand case value (for the GNU case-range extension).
5649 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005650 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005651 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005652 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005653 }
Mike Stump11289f42009-09-09 15:08:12 +00005654
Douglas Gregorebe10102009-08-20 07:17:43 +00005655 // Build the case statement.
5656 // Case statements are always rebuilt so that they will attached to their
5657 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005658 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005659 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005660 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005661 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005662 S->getColonLoc());
5663 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005664 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005665
Douglas Gregorebe10102009-08-20 07:17:43 +00005666 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005667 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005668 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005669 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005670
Douglas Gregorebe10102009-08-20 07:17:43 +00005671 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005672 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005673}
5674
5675template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005676StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005677TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005678 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005679 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005680 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005681 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005682
Douglas Gregorebe10102009-08-20 07:17:43 +00005683 // Default statements are always rebuilt
5684 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005685 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005686}
Mike Stump11289f42009-09-09 15:08:12 +00005687
Douglas Gregorebe10102009-08-20 07:17:43 +00005688template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005689StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005690TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005691 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005692 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005693 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005694
Chris Lattnercab02a62011-02-17 20:34:02 +00005695 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5696 S->getDecl());
5697 if (!LD)
5698 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005699
5700
Douglas Gregorebe10102009-08-20 07:17:43 +00005701 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005702 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005703 cast<LabelDecl>(LD), SourceLocation(),
5704 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005705}
Mike Stump11289f42009-09-09 15:08:12 +00005706
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005707template <typename Derived>
5708const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
5709 if (!R)
5710 return R;
5711
5712 switch (R->getKind()) {
5713// Transform attributes with a pragma spelling by calling TransformXXXAttr.
5714#define ATTR(X)
5715#define PRAGMA_SPELLING_ATTR(X) \
5716 case attr::X: \
5717 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
5718#include "clang/Basic/AttrList.inc"
5719 default:
5720 return R;
5721 }
5722}
5723
5724template <typename Derived>
5725StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5726 bool AttrsChanged = false;
5727 SmallVector<const Attr *, 1> Attrs;
5728
5729 // Visit attributes and keep track if any are transformed.
5730 for (const auto *I : S->getAttrs()) {
5731 const Attr *R = getDerived().TransformAttr(I);
5732 AttrsChanged |= (I != R);
5733 Attrs.push_back(R);
5734 }
5735
Richard Smithc202b282012-04-14 00:33:13 +00005736 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5737 if (SubStmt.isInvalid())
5738 return StmtError();
5739
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005740 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00005741 return S;
5742
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005743 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00005744 SubStmt.get());
5745}
5746
5747template<typename Derived>
5748StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005749TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005750 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005751 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005752 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005753 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005754 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005755 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005756 getDerived().TransformDefinition(
5757 S->getConditionVariable()->getLocation(),
5758 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005759 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005760 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005761 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005762 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005763
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005764 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005765 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005766
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005767 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005768 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005769 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005770 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005771 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005772 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005773
John McCallb268a282010-08-23 23:25:46 +00005774 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005775 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005776 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005777
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005778 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005779 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005780 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005781
Douglas Gregorebe10102009-08-20 07:17:43 +00005782 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005783 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005784 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005785 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005786
Douglas Gregorebe10102009-08-20 07:17:43 +00005787 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005788 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005789 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005790 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005791
Douglas Gregorebe10102009-08-20 07:17:43 +00005792 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005793 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005794 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005795 Then.get() == S->getThen() &&
5796 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005797 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005798
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005799 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005800 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005801 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005802}
5803
5804template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005805StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005806TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005807 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005808 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005809 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005810 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005811 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005812 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005813 getDerived().TransformDefinition(
5814 S->getConditionVariable()->getLocation(),
5815 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005816 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005817 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005818 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005819 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005820
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005821 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005822 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005823 }
Mike Stump11289f42009-09-09 15:08:12 +00005824
Douglas Gregorebe10102009-08-20 07:17:43 +00005825 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005826 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005827 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005828 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005829 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005830 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005831
Douglas Gregorebe10102009-08-20 07:17:43 +00005832 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005833 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005834 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005835 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005836
Douglas Gregorebe10102009-08-20 07:17:43 +00005837 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005838 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5839 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005840}
Mike Stump11289f42009-09-09 15:08:12 +00005841
Douglas Gregorebe10102009-08-20 07:17:43 +00005842template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005843StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005844TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005845 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005846 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005847 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005848 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005849 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005850 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005851 getDerived().TransformDefinition(
5852 S->getConditionVariable()->getLocation(),
5853 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005854 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005855 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005856 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005857 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005858
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005859 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005860 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005861
5862 if (S->getCond()) {
5863 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005864 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5865 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005866 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005867 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005868 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005869 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005870 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005871 }
Mike Stump11289f42009-09-09 15:08:12 +00005872
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005873 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005874 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005875 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005876
Douglas Gregorebe10102009-08-20 07:17:43 +00005877 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005878 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005879 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005880 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005881
Douglas Gregorebe10102009-08-20 07:17:43 +00005882 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005883 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005884 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005885 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005886 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005887
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005888 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005889 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005890}
Mike Stump11289f42009-09-09 15:08:12 +00005891
Douglas Gregorebe10102009-08-20 07:17:43 +00005892template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005893StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005894TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
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 Gregorff73a9e2010-05-08 22:20:28 +00005900 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005901 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005902 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005903 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005904
Douglas Gregorebe10102009-08-20 07:17:43 +00005905 if (!getDerived().AlwaysRebuild() &&
5906 Cond.get() == S->getCond() &&
5907 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005908 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005909
John McCallb268a282010-08-23 23:25:46 +00005910 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5911 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005912 S->getRParenLoc());
5913}
Mike Stump11289f42009-09-09 15:08:12 +00005914
Douglas Gregorebe10102009-08-20 07:17:43 +00005915template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005916StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005917TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005918 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005919 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005920 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005921 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005922
Douglas Gregorebe10102009-08-20 07:17:43 +00005923 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005924 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005925 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005926 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005927 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005928 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005929 getDerived().TransformDefinition(
5930 S->getConditionVariable()->getLocation(),
5931 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005932 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005933 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005934 } else {
5935 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005936
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005937 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005938 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005939
5940 if (S->getCond()) {
5941 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005942 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5943 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005944 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005945 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005946 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005947
John McCallb268a282010-08-23 23:25:46 +00005948 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005949 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005950 }
Mike Stump11289f42009-09-09 15:08:12 +00005951
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005952 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005953 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005954 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005955
Douglas Gregorebe10102009-08-20 07:17:43 +00005956 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005957 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005958 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005959 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005960
Richard Smith945f8d32013-01-14 22:39:08 +00005961 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005962 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005963 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005964
Douglas Gregorebe10102009-08-20 07:17:43 +00005965 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005966 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005967 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005968 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005969
Douglas Gregorebe10102009-08-20 07:17:43 +00005970 if (!getDerived().AlwaysRebuild() &&
5971 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005972 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005973 Inc.get() == S->getInc() &&
5974 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005975 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005976
Douglas Gregorebe10102009-08-20 07:17:43 +00005977 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005978 Init.get(), FullCond, ConditionVar,
5979 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005980}
5981
5982template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005983StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005984TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005985 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5986 S->getLabel());
5987 if (!LD)
5988 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005989
Douglas Gregorebe10102009-08-20 07:17:43 +00005990 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005991 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005992 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005993}
5994
5995template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005996StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005997TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005998 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005999 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006000 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006001 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006002
Douglas Gregorebe10102009-08-20 07:17:43 +00006003 if (!getDerived().AlwaysRebuild() &&
6004 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006005 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006006
6007 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006008 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006009}
6010
6011template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006012StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006013TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006014 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006015}
Mike Stump11289f42009-09-09 15:08:12 +00006016
Douglas Gregorebe10102009-08-20 07:17:43 +00006017template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006018StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006019TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006020 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006021}
Mike Stump11289f42009-09-09 15:08:12 +00006022
Douglas Gregorebe10102009-08-20 07:17:43 +00006023template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006024StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006025TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006026 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6027 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006028 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006029 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006030
Mike Stump11289f42009-09-09 15:08:12 +00006031 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006032 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006033 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006034}
Mike Stump11289f42009-09-09 15:08:12 +00006035
Douglas Gregorebe10102009-08-20 07:17:43 +00006036template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006037StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006038TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006039 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006040 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006041 for (auto *D : S->decls()) {
6042 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006043 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006044 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006045
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006046 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006047 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006048
Douglas Gregorebe10102009-08-20 07:17:43 +00006049 Decls.push_back(Transformed);
6050 }
Mike Stump11289f42009-09-09 15:08:12 +00006051
Douglas Gregorebe10102009-08-20 07:17:43 +00006052 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006053 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006054
Rafael Espindolaab417692013-07-09 12:05:01 +00006055 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006056}
Mike Stump11289f42009-09-09 15:08:12 +00006057
Douglas Gregorebe10102009-08-20 07:17:43 +00006058template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006059StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006060TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006061
Benjamin Kramerf0623432012-08-23 22:51:59 +00006062 SmallVector<Expr*, 8> Constraints;
6063 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006064 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006065
John McCalldadc5752010-08-24 06:29:42 +00006066 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006067 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006068
6069 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006070
Anders Carlssonaaeef072010-01-24 05:50:09 +00006071 // Go through the outputs.
6072 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006073 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006074
Anders Carlssonaaeef072010-01-24 05:50:09 +00006075 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006076 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006077
Anders Carlssonaaeef072010-01-24 05:50:09 +00006078 // Transform the output expr.
6079 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006080 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006081 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006082 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006083
Anders Carlssonaaeef072010-01-24 05:50:09 +00006084 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006085
John McCallb268a282010-08-23 23:25:46 +00006086 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006087 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006088
Anders Carlssonaaeef072010-01-24 05:50:09 +00006089 // Go through the inputs.
6090 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006091 Names.push_back(S->getInputIdentifier(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->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006095
Anders Carlssonaaeef072010-01-24 05:50:09 +00006096 // Transform the input expr.
6097 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006098 ExprResult Result = getDerived().TransformExpr(InputExpr);
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() != InputExpr;
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 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006108 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006109
6110 // Go through the clobbers.
6111 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006112 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006113
6114 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006115 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006116 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6117 S->isVolatile(), S->getNumOutputs(),
6118 S->getNumInputs(), Names.data(),
6119 Constraints, Exprs, AsmString.get(),
6120 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006121}
6122
Chad Rosier32503022012-06-11 20:47:18 +00006123template<typename Derived>
6124StmtResult
6125TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006126 ArrayRef<Token> AsmToks =
6127 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006128
John McCallf413f5e2013-05-03 00:10:13 +00006129 bool HadError = false, HadChange = false;
6130
6131 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6132 SmallVector<Expr*, 8> TransformedExprs;
6133 TransformedExprs.reserve(SrcExprs.size());
6134 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6135 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6136 if (!Result.isUsable()) {
6137 HadError = true;
6138 } else {
6139 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006140 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006141 }
6142 }
6143
6144 if (HadError) return StmtError();
6145 if (!HadChange && !getDerived().AlwaysRebuild())
6146 return Owned(S);
6147
Chad Rosierb6f46c12012-08-15 16:53:30 +00006148 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006149 AsmToks, S->getAsmString(),
6150 S->getNumOutputs(), S->getNumInputs(),
6151 S->getAllConstraints(), S->getClobbers(),
6152 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006153}
Douglas Gregorebe10102009-08-20 07:17:43 +00006154
6155template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006156StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006157TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006158 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006159 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006160 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006161 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006162
Douglas Gregor96c79492010-04-23 22:50:49 +00006163 // Transform the @catch statements (if present).
6164 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006165 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006166 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006167 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006168 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006169 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006170 if (Catch.get() != S->getCatchStmt(I))
6171 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006172 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006173 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006174
Douglas Gregor306de2f2010-04-22 23:59:56 +00006175 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006176 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006177 if (S->getFinallyStmt()) {
6178 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6179 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006180 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006181 }
6182
6183 // If nothing changed, just retain this statement.
6184 if (!getDerived().AlwaysRebuild() &&
6185 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006186 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006187 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006188 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006189
Douglas Gregor306de2f2010-04-22 23:59:56 +00006190 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006191 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006192 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006193}
Mike Stump11289f42009-09-09 15:08:12 +00006194
Douglas Gregorebe10102009-08-20 07:17:43 +00006195template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006196StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006197TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006198 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006199 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006200 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006201 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006202 if (FromVar->getTypeSourceInfo()) {
6203 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6204 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006205 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006206 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006207
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006208 QualType T;
6209 if (TSInfo)
6210 T = TSInfo->getType();
6211 else {
6212 T = getDerived().TransformType(FromVar->getType());
6213 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006214 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006215 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006216
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006217 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6218 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006219 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006220 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006221
John McCalldadc5752010-08-24 06:29:42 +00006222 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006223 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006224 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006225
6226 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006227 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006228 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006229}
Mike Stump11289f42009-09-09 15:08:12 +00006230
Douglas Gregorebe10102009-08-20 07:17:43 +00006231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006232StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006233TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006234 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006235 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006236 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006237 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006238
Douglas Gregor306de2f2010-04-22 23:59:56 +00006239 // If nothing changed, just retain this statement.
6240 if (!getDerived().AlwaysRebuild() &&
6241 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006242 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006243
6244 // Build a new statement.
6245 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006246 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>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006252 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006253 if (S->getThrowExpr()) {
6254 Operand = getDerived().TransformExpr(S->getThrowExpr());
6255 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006256 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006257 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006258
Douglas Gregor2900c162010-04-22 21:44:01 +00006259 if (!getDerived().AlwaysRebuild() &&
6260 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006261 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006262
John McCallb268a282010-08-23 23:25:46 +00006263 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006264}
Mike Stump11289f42009-09-09 15:08:12 +00006265
Douglas Gregorebe10102009-08-20 07:17:43 +00006266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006267StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006268TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006269 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006270 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006271 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006272 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006273 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006274 Object =
6275 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6276 Object.get());
6277 if (Object.isInvalid())
6278 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006279
Douglas Gregor6148de72010-04-22 22:01:21 +00006280 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006281 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006282 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006283 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006284
Douglas Gregor6148de72010-04-22 22:01:21 +00006285 // If nothing change, just retain the current statement.
6286 if (!getDerived().AlwaysRebuild() &&
6287 Object.get() == S->getSynchExpr() &&
6288 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006289 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006290
6291 // Build a new statement.
6292 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006293 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006294}
6295
6296template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006297StmtResult
John McCall31168b02011-06-15 23:02:42 +00006298TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6299 ObjCAutoreleasePoolStmt *S) {
6300 // Transform the body.
6301 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6302 if (Body.isInvalid())
6303 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006304
John McCall31168b02011-06-15 23:02:42 +00006305 // If nothing changed, just retain this statement.
6306 if (!getDerived().AlwaysRebuild() &&
6307 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006308 return S;
John McCall31168b02011-06-15 23:02:42 +00006309
6310 // Build a new statement.
6311 return getDerived().RebuildObjCAutoreleasePoolStmt(
6312 S->getAtLoc(), Body.get());
6313}
6314
6315template<typename Derived>
6316StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006317TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006318 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006319 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006320 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006321 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006322 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006323
Douglas Gregorf68a5082010-04-22 23:10:45 +00006324 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006325 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006326 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006327 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006328
Douglas Gregorf68a5082010-04-22 23:10:45 +00006329 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006330 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006331 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006332 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006333
Douglas Gregorf68a5082010-04-22 23:10:45 +00006334 // If nothing changed, just retain this statement.
6335 if (!getDerived().AlwaysRebuild() &&
6336 Element.get() == S->getElement() &&
6337 Collection.get() == S->getCollection() &&
6338 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006339 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006340
Douglas Gregorf68a5082010-04-22 23:10:45 +00006341 // Build a new statement.
6342 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006343 Element.get(),
6344 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006345 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006346 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006347}
6348
David Majnemer5f7efef2013-10-15 09:50:08 +00006349template <typename Derived>
6350StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006351 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006352 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006353 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6354 TypeSourceInfo *T =
6355 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006356 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006357 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006358
David Majnemer5f7efef2013-10-15 09:50:08 +00006359 Var = getDerived().RebuildExceptionDecl(
6360 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6361 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006362 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006363 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006364 }
Mike Stump11289f42009-09-09 15:08:12 +00006365
Douglas Gregorebe10102009-08-20 07:17:43 +00006366 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006367 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006368 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006369 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006370
David Majnemer5f7efef2013-10-15 09:50:08 +00006371 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006372 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006373 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006374
David Majnemer5f7efef2013-10-15 09:50:08 +00006375 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006376}
Mike Stump11289f42009-09-09 15:08:12 +00006377
David Majnemer5f7efef2013-10-15 09:50:08 +00006378template <typename Derived>
6379StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006380 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006381 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006382 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006383 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006384
Douglas Gregorebe10102009-08-20 07:17:43 +00006385 // Transform the handlers.
6386 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006387 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006388 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006389 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006390 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006391 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006392
Douglas Gregorebe10102009-08-20 07:17:43 +00006393 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006394 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006395 }
Mike Stump11289f42009-09-09 15:08:12 +00006396
David Majnemer5f7efef2013-10-15 09:50:08 +00006397 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006398 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006399 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006400
John McCallb268a282010-08-23 23:25:46 +00006401 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006402 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006403}
Mike Stump11289f42009-09-09 15:08:12 +00006404
Richard Smith02e85f32011-04-14 22:09:26 +00006405template<typename Derived>
6406StmtResult
6407TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6408 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6409 if (Range.isInvalid())
6410 return StmtError();
6411
6412 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6413 if (BeginEnd.isInvalid())
6414 return StmtError();
6415
6416 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6417 if (Cond.isInvalid())
6418 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006419 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006420 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006421 if (Cond.isInvalid())
6422 return StmtError();
6423 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006424 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006425
6426 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6427 if (Inc.isInvalid())
6428 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006429 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006430 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006431
6432 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6433 if (LoopVar.isInvalid())
6434 return StmtError();
6435
6436 StmtResult NewStmt = S;
6437 if (getDerived().AlwaysRebuild() ||
6438 Range.get() != S->getRangeStmt() ||
6439 BeginEnd.get() != S->getBeginEndStmt() ||
6440 Cond.get() != S->getCond() ||
6441 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006442 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006443 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6444 S->getColonLoc(), Range.get(),
6445 BeginEnd.get(), Cond.get(),
6446 Inc.get(), LoopVar.get(),
6447 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006448 if (NewStmt.isInvalid())
6449 return StmtError();
6450 }
Richard Smith02e85f32011-04-14 22:09:26 +00006451
6452 StmtResult Body = getDerived().TransformStmt(S->getBody());
6453 if (Body.isInvalid())
6454 return StmtError();
6455
6456 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6457 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006458 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006459 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6460 S->getColonLoc(), Range.get(),
6461 BeginEnd.get(), Cond.get(),
6462 Inc.get(), LoopVar.get(),
6463 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006464 if (NewStmt.isInvalid())
6465 return StmtError();
6466 }
Richard Smith02e85f32011-04-14 22:09:26 +00006467
6468 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006469 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006470
6471 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6472}
6473
John Wiegley1c0675e2011-04-28 01:08:34 +00006474template<typename Derived>
6475StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006476TreeTransform<Derived>::TransformMSDependentExistsStmt(
6477 MSDependentExistsStmt *S) {
6478 // Transform the nested-name-specifier, if any.
6479 NestedNameSpecifierLoc QualifierLoc;
6480 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006481 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006482 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6483 if (!QualifierLoc)
6484 return StmtError();
6485 }
6486
6487 // Transform the declaration name.
6488 DeclarationNameInfo NameInfo = S->getNameInfo();
6489 if (NameInfo.getName()) {
6490 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6491 if (!NameInfo.getName())
6492 return StmtError();
6493 }
6494
6495 // Check whether anything changed.
6496 if (!getDerived().AlwaysRebuild() &&
6497 QualifierLoc == S->getQualifierLoc() &&
6498 NameInfo.getName() == S->getNameInfo().getName())
6499 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006500
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006501 // Determine whether this name exists, if we can.
6502 CXXScopeSpec SS;
6503 SS.Adopt(QualifierLoc);
6504 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006505 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006506 case Sema::IER_Exists:
6507 if (S->isIfExists())
6508 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006509
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006510 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6511
6512 case Sema::IER_DoesNotExist:
6513 if (S->isIfNotExists())
6514 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006515
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006516 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006517
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006518 case Sema::IER_Dependent:
6519 Dependent = true;
6520 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006521
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006522 case Sema::IER_Error:
6523 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006524 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006525
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006526 // We need to continue with the instantiation, so do so now.
6527 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6528 if (SubStmt.isInvalid())
6529 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006530
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006531 // If we have resolved the name, just transform to the substatement.
6532 if (!Dependent)
6533 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006534
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006535 // The name is still dependent, so build a dependent expression again.
6536 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6537 S->isIfExists(),
6538 QualifierLoc,
6539 NameInfo,
6540 SubStmt.get());
6541}
6542
6543template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006544ExprResult
6545TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6546 NestedNameSpecifierLoc QualifierLoc;
6547 if (E->getQualifierLoc()) {
6548 QualifierLoc
6549 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6550 if (!QualifierLoc)
6551 return ExprError();
6552 }
6553
6554 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6555 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6556 if (!PD)
6557 return ExprError();
6558
6559 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6560 if (Base.isInvalid())
6561 return ExprError();
6562
6563 return new (SemaRef.getASTContext())
6564 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6565 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6566 QualifierLoc, E->getMemberLoc());
6567}
6568
David Majnemerfad8f482013-10-15 09:33:02 +00006569template <typename Derived>
6570StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006571 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006572 if (TryBlock.isInvalid())
6573 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006574
6575 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006576 if (Handler.isInvalid())
6577 return StmtError();
6578
David Majnemerfad8f482013-10-15 09:33:02 +00006579 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6580 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006581 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006582
Warren Huntf6be4cb2014-07-25 20:52:51 +00006583 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6584 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006585}
6586
David Majnemerfad8f482013-10-15 09:33:02 +00006587template <typename Derived>
6588StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006589 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006590 if (Block.isInvalid())
6591 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006592
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006593 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006594}
6595
David Majnemerfad8f482013-10-15 09:33:02 +00006596template <typename Derived>
6597StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006598 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006599 if (FilterExpr.isInvalid())
6600 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006601
David Majnemer7e755502013-10-15 09:30:14 +00006602 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006603 if (Block.isInvalid())
6604 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006605
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006606 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6607 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006608}
6609
David Majnemerfad8f482013-10-15 09:33:02 +00006610template <typename Derived>
6611StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6612 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006613 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6614 else
6615 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6616}
6617
Nico Weber9b982072014-07-07 00:12:30 +00006618template<typename Derived>
6619StmtResult
6620TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6621 return S;
6622}
6623
Alexander Musman64d33f12014-06-04 07:53:32 +00006624//===----------------------------------------------------------------------===//
6625// OpenMP directive transformation
6626//===----------------------------------------------------------------------===//
6627template <typename Derived>
6628StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6629 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006630
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006631 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006632 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006633 ArrayRef<OMPClause *> Clauses = D->clauses();
6634 TClauses.reserve(Clauses.size());
6635 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6636 I != E; ++I) {
6637 if (*I) {
6638 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevc5e02582014-06-16 07:08:35 +00006639 if (Clause)
6640 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006641 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006642 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006643 }
6644 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006645 StmtResult AssociatedStmt;
6646 if (D->hasAssociatedStmt()) {
6647 if (!D->getAssociatedStmt()) {
6648 return StmtError();
6649 }
6650 AssociatedStmt = getDerived().TransformStmt(D->getAssociatedStmt());
6651 if (AssociatedStmt.isInvalid()) {
6652 return StmtError();
6653 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006654 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006655 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006656 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006657 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006658
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006659 // Transform directive name for 'omp critical' directive.
6660 DeclarationNameInfo DirName;
6661 if (D->getDirectiveKind() == OMPD_critical) {
6662 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6663 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6664 }
6665
Alexander Musman64d33f12014-06-04 07:53:32 +00006666 return getDerived().RebuildOMPExecutableDirective(
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006667 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
6668 D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006669}
6670
Alexander Musman64d33f12014-06-04 07:53:32 +00006671template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006672StmtResult
6673TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6674 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006675 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6676 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006677 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6678 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6679 return Res;
6680}
6681
Alexander Musman64d33f12014-06-04 07:53:32 +00006682template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006683StmtResult
6684TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6685 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006686 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6687 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006688 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6689 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006690 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006691}
6692
Alexey Bataevf29276e2014-06-18 04:14:57 +00006693template <typename Derived>
6694StmtResult
6695TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6696 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006697 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6698 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006699 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6700 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6701 return Res;
6702}
6703
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006704template <typename Derived>
6705StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00006706TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
6707 DeclarationNameInfo DirName;
6708 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
6709 D->getLocStart());
6710 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6711 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6712 return Res;
6713}
6714
6715template <typename Derived>
6716StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006717TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6718 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006719 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6720 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006721 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6722 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6723 return Res;
6724}
6725
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006726template <typename Derived>
6727StmtResult
6728TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6729 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006730 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6731 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006732 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6733 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6734 return Res;
6735}
6736
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006737template <typename Derived>
6738StmtResult
6739TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6740 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006741 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6742 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006743 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6744 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6745 return Res;
6746}
6747
Alexey Bataev4acb8592014-07-07 13:01:15 +00006748template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006749StmtResult
6750TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6751 DeclarationNameInfo DirName;
6752 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6753 D->getLocStart());
6754 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6755 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6756 return Res;
6757}
6758
6759template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006760StmtResult
6761TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6762 getDerived().getSema().StartOpenMPDSABlock(
6763 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
6764 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6765 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6766 return Res;
6767}
6768
6769template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00006770StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6771 OMPParallelForDirective *D) {
6772 DeclarationNameInfo DirName;
6773 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6774 nullptr, D->getLocStart());
6775 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6776 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6777 return Res;
6778}
6779
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006780template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00006781StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
6782 OMPParallelForSimdDirective *D) {
6783 DeclarationNameInfo DirName;
6784 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
6785 nullptr, D->getLocStart());
6786 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6787 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6788 return Res;
6789}
6790
6791template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006792StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6793 OMPParallelSectionsDirective *D) {
6794 DeclarationNameInfo DirName;
6795 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6796 nullptr, D->getLocStart());
6797 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6798 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6799 return Res;
6800}
6801
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00006802template <typename Derived>
6803StmtResult
6804TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6805 DeclarationNameInfo DirName;
6806 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6807 D->getLocStart());
6808 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6809 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6810 return Res;
6811}
6812
Alexey Bataev68446b72014-07-18 07:47:19 +00006813template <typename Derived>
6814StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
6815 OMPTaskyieldDirective *D) {
6816 DeclarationNameInfo DirName;
6817 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
6818 D->getLocStart());
6819 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6820 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6821 return Res;
6822}
6823
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00006824template <typename Derived>
6825StmtResult
6826TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
6827 DeclarationNameInfo DirName;
6828 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
6829 D->getLocStart());
6830 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6831 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6832 return Res;
6833}
6834
Alexey Bataev2df347a2014-07-18 10:17:07 +00006835template <typename Derived>
6836StmtResult
6837TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
6838 DeclarationNameInfo DirName;
6839 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
6840 D->getLocStart());
6841 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6842 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6843 return Res;
6844}
6845
Alexey Bataev6125da92014-07-21 11:26:11 +00006846template <typename Derived>
6847StmtResult
6848TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
6849 DeclarationNameInfo DirName;
6850 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
6851 D->getLocStart());
6852 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6853 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6854 return Res;
6855}
6856
Alexey Bataev9fb6e642014-07-22 06:45:04 +00006857template <typename Derived>
6858StmtResult
6859TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
6860 DeclarationNameInfo DirName;
6861 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
6862 D->getLocStart());
6863 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6864 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6865 return Res;
6866}
6867
Alexey Bataev0162e452014-07-22 10:10:35 +00006868template <typename Derived>
6869StmtResult
6870TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
6871 DeclarationNameInfo DirName;
6872 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
6873 D->getLocStart());
6874 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6875 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6876 return Res;
6877}
6878
Alexey Bataev0bd520b2014-09-19 08:19:49 +00006879template <typename Derived>
6880StmtResult
6881TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
6882 DeclarationNameInfo DirName;
6883 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
6884 D->getLocStart());
6885 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6886 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6887 return Res;
6888}
6889
Alexey Bataev13314bf2014-10-09 04:18:56 +00006890template <typename Derived>
6891StmtResult
6892TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
6893 DeclarationNameInfo DirName;
6894 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
6895 D->getLocStart());
6896 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6897 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6898 return Res;
6899}
6900
Alexander Musman64d33f12014-06-04 07:53:32 +00006901//===----------------------------------------------------------------------===//
6902// OpenMP clause transformation
6903//===----------------------------------------------------------------------===//
6904template <typename Derived>
6905OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006906 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6907 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006908 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006909 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006910 C->getLParenLoc(), C->getLocEnd());
6911}
6912
Alexander Musman64d33f12014-06-04 07:53:32 +00006913template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00006914OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
6915 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6916 if (Cond.isInvalid())
6917 return nullptr;
6918 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
6919 C->getLParenLoc(), C->getLocEnd());
6920}
6921
6922template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006923OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006924TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6925 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6926 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006927 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006928 return getDerived().RebuildOMPNumThreadsClause(
6929 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006930}
6931
Alexey Bataev62c87d22014-03-21 04:51:18 +00006932template <typename Derived>
6933OMPClause *
6934TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6935 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6936 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006937 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006938 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006939 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006940}
6941
Alexander Musman8bd31e62014-05-27 15:12:19 +00006942template <typename Derived>
6943OMPClause *
6944TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6945 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6946 if (E.isInvalid())
6947 return 0;
6948 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006949 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006950}
6951
Alexander Musman64d33f12014-06-04 07:53:32 +00006952template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006953OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006954TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006955 return getDerived().RebuildOMPDefaultClause(
6956 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6957 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006958}
6959
Alexander Musman64d33f12014-06-04 07:53:32 +00006960template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006961OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006962TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006963 return getDerived().RebuildOMPProcBindClause(
6964 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6965 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006966}
6967
Alexander Musman64d33f12014-06-04 07:53:32 +00006968template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006969OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00006970TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
6971 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
6972 if (E.isInvalid())
6973 return nullptr;
6974 return getDerived().RebuildOMPScheduleClause(
6975 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
6976 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
6977}
6978
6979template <typename Derived>
6980OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00006981TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
6982 // No need to rebuild this clause, no template-dependent parameters.
6983 return C;
6984}
6985
6986template <typename Derived>
6987OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00006988TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
6989 // No need to rebuild this clause, no template-dependent parameters.
6990 return C;
6991}
6992
6993template <typename Derived>
6994OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00006995TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
6996 // No need to rebuild this clause, no template-dependent parameters.
6997 return C;
6998}
6999
7000template <typename Derived>
7001OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007002TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7003 // No need to rebuild this clause, no template-dependent parameters.
7004 return C;
7005}
7006
7007template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007008OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7009 // No need to rebuild this clause, no template-dependent parameters.
7010 return C;
7011}
7012
7013template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007014OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7015 // No need to rebuild this clause, no template-dependent parameters.
7016 return C;
7017}
7018
7019template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007020OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007021TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7022 // No need to rebuild this clause, no template-dependent parameters.
7023 return C;
7024}
7025
7026template <typename Derived>
7027OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007028TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7029 // No need to rebuild this clause, no template-dependent parameters.
7030 return C;
7031}
7032
7033template <typename Derived>
7034OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007035TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7036 // No need to rebuild this clause, no template-dependent parameters.
7037 return C;
7038}
7039
7040template <typename Derived>
7041OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007042TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007043 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007044 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007045 for (auto *VE : C->varlists()) {
7046 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007047 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007048 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007049 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007050 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007051 return getDerived().RebuildOMPPrivateClause(
7052 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007053}
7054
Alexander Musman64d33f12014-06-04 07:53:32 +00007055template <typename Derived>
7056OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7057 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007058 llvm::SmallVector<Expr *, 16> Vars;
7059 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007060 for (auto *VE : C->varlists()) {
7061 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007062 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007063 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007064 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007065 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007066 return getDerived().RebuildOMPFirstprivateClause(
7067 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007068}
7069
Alexander Musman64d33f12014-06-04 07:53:32 +00007070template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007071OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007072TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7073 llvm::SmallVector<Expr *, 16> Vars;
7074 Vars.reserve(C->varlist_size());
7075 for (auto *VE : C->varlists()) {
7076 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7077 if (EVar.isInvalid())
7078 return nullptr;
7079 Vars.push_back(EVar.get());
7080 }
7081 return getDerived().RebuildOMPLastprivateClause(
7082 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7083}
7084
7085template <typename Derived>
7086OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007087TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7088 llvm::SmallVector<Expr *, 16> Vars;
7089 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007090 for (auto *VE : C->varlists()) {
7091 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007092 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007093 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007094 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007095 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007096 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7097 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007098}
7099
Alexander Musman64d33f12014-06-04 07:53:32 +00007100template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007101OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007102TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7103 llvm::SmallVector<Expr *, 16> Vars;
7104 Vars.reserve(C->varlist_size());
7105 for (auto *VE : C->varlists()) {
7106 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7107 if (EVar.isInvalid())
7108 return nullptr;
7109 Vars.push_back(EVar.get());
7110 }
7111 CXXScopeSpec ReductionIdScopeSpec;
7112 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7113
7114 DeclarationNameInfo NameInfo = C->getNameInfo();
7115 if (NameInfo.getName()) {
7116 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7117 if (!NameInfo.getName())
7118 return nullptr;
7119 }
7120 return getDerived().RebuildOMPReductionClause(
7121 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7122 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7123}
7124
7125template <typename Derived>
7126OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007127TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7128 llvm::SmallVector<Expr *, 16> Vars;
7129 Vars.reserve(C->varlist_size());
7130 for (auto *VE : C->varlists()) {
7131 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7132 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007133 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007134 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007135 }
7136 ExprResult Step = getDerived().TransformExpr(C->getStep());
7137 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007138 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007139 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
7140 C->getLParenLoc(),
7141 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007142}
7143
Alexander Musman64d33f12014-06-04 07:53:32 +00007144template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007145OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007146TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7147 llvm::SmallVector<Expr *, 16> Vars;
7148 Vars.reserve(C->varlist_size());
7149 for (auto *VE : C->varlists()) {
7150 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7151 if (EVar.isInvalid())
7152 return nullptr;
7153 Vars.push_back(EVar.get());
7154 }
7155 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7156 if (Alignment.isInvalid())
7157 return nullptr;
7158 return getDerived().RebuildOMPAlignedClause(
7159 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7160 C->getColonLoc(), C->getLocEnd());
7161}
7162
Alexander Musman64d33f12014-06-04 07:53:32 +00007163template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007164OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007165TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7166 llvm::SmallVector<Expr *, 16> Vars;
7167 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007168 for (auto *VE : C->varlists()) {
7169 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007170 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());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007173 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007174 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7175 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007176}
7177
Alexey Bataevbae9a792014-06-27 10:37:06 +00007178template <typename Derived>
7179OMPClause *
7180TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7181 llvm::SmallVector<Expr *, 16> Vars;
7182 Vars.reserve(C->varlist_size());
7183 for (auto *VE : C->varlists()) {
7184 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7185 if (EVar.isInvalid())
7186 return nullptr;
7187 Vars.push_back(EVar.get());
7188 }
7189 return getDerived().RebuildOMPCopyprivateClause(
7190 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7191}
7192
Alexey Bataev6125da92014-07-21 11:26:11 +00007193template <typename Derived>
7194OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7195 llvm::SmallVector<Expr *, 16> Vars;
7196 Vars.reserve(C->varlist_size());
7197 for (auto *VE : C->varlists()) {
7198 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7199 if (EVar.isInvalid())
7200 return nullptr;
7201 Vars.push_back(EVar.get());
7202 }
7203 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7204 C->getLParenLoc(), C->getLocEnd());
7205}
7206
Douglas Gregorebe10102009-08-20 07:17:43 +00007207//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007208// Expression transformation
7209//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007210template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007211ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007212TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007213 if (!E->isTypeDependent())
7214 return E;
7215
7216 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7217 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007218}
Mike Stump11289f42009-09-09 15:08:12 +00007219
7220template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007221ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007222TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007223 NestedNameSpecifierLoc QualifierLoc;
7224 if (E->getQualifierLoc()) {
7225 QualifierLoc
7226 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7227 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007228 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007229 }
John McCallce546572009-12-08 09:08:17 +00007230
7231 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007232 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7233 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007234 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007235 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007236
John McCall815039a2010-08-17 21:27:17 +00007237 DeclarationNameInfo NameInfo = E->getNameInfo();
7238 if (NameInfo.getName()) {
7239 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7240 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007241 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007242 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007243
7244 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007245 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007246 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007247 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007248 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007249
7250 // Mark it referenced in the new context regardless.
7251 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007252 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007253
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007254 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007255 }
John McCallce546572009-12-08 09:08:17 +00007256
Craig Topperc3ec1492014-05-26 06:22:03 +00007257 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007258 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007259 TemplateArgs = &TransArgs;
7260 TransArgs.setLAngleLoc(E->getLAngleLoc());
7261 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007262 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7263 E->getNumTemplateArgs(),
7264 TransArgs))
7265 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007266 }
7267
Chad Rosier1dcde962012-08-08 18:46:20 +00007268 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007269 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007270}
Mike Stump11289f42009-09-09 15:08:12 +00007271
Douglas Gregora16548e2009-08-11 05:31:07 +00007272template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007273ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007274TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007275 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007276}
Mike Stump11289f42009-09-09 15:08:12 +00007277
Douglas Gregora16548e2009-08-11 05:31:07 +00007278template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007279ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007280TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007281 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007282}
Mike Stump11289f42009-09-09 15:08:12 +00007283
Douglas Gregora16548e2009-08-11 05:31:07 +00007284template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007285ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007286TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007287 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007288}
Mike Stump11289f42009-09-09 15:08:12 +00007289
Douglas Gregora16548e2009-08-11 05:31:07 +00007290template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007291ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007292TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007293 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007294}
Mike Stump11289f42009-09-09 15:08:12 +00007295
Douglas Gregora16548e2009-08-11 05:31:07 +00007296template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007297ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007298TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007299 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007300}
7301
7302template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007303ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007304TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007305 if (FunctionDecl *FD = E->getDirectCallee())
7306 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007307 return SemaRef.MaybeBindToTemporary(E);
7308}
7309
7310template<typename Derived>
7311ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007312TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7313 ExprResult ControllingExpr =
7314 getDerived().TransformExpr(E->getControllingExpr());
7315 if (ControllingExpr.isInvalid())
7316 return ExprError();
7317
Chris Lattner01cf8db2011-07-20 06:58:45 +00007318 SmallVector<Expr *, 4> AssocExprs;
7319 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007320 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7321 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7322 if (TS) {
7323 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7324 if (!AssocType)
7325 return ExprError();
7326 AssocTypes.push_back(AssocType);
7327 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007328 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007329 }
7330
7331 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7332 if (AssocExpr.isInvalid())
7333 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007334 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007335 }
7336
7337 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7338 E->getDefaultLoc(),
7339 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007340 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007341 AssocTypes,
7342 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007343}
7344
7345template<typename Derived>
7346ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007347TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007348 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007349 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007350 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007351
Douglas Gregora16548e2009-08-11 05:31:07 +00007352 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007353 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007354
John McCallb268a282010-08-23 23:25:46 +00007355 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007356 E->getRParen());
7357}
7358
Richard Smithdb2630f2012-10-21 03:28:35 +00007359/// \brief The operand of a unary address-of operator has special rules: it's
7360/// allowed to refer to a non-static member of a class even if there's no 'this'
7361/// object available.
7362template<typename Derived>
7363ExprResult
7364TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7365 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007366 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007367 else
7368 return getDerived().TransformExpr(E);
7369}
7370
Mike Stump11289f42009-09-09 15:08:12 +00007371template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007372ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007373TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007374 ExprResult SubExpr;
7375 if (E->getOpcode() == UO_AddrOf)
7376 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7377 else
7378 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007379 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007380 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007381
Douglas Gregora16548e2009-08-11 05:31:07 +00007382 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007383 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007384
Douglas Gregora16548e2009-08-11 05:31:07 +00007385 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7386 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007387 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007388}
Mike Stump11289f42009-09-09 15:08:12 +00007389
Douglas Gregora16548e2009-08-11 05:31:07 +00007390template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007391ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007392TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7393 // Transform the type.
7394 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7395 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007396 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007397
Douglas Gregor882211c2010-04-28 22:16:22 +00007398 // Transform all of the components into components similar to what the
7399 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007400 // FIXME: It would be slightly more efficient in the non-dependent case to
7401 // just map FieldDecls, rather than requiring the rebuilder to look for
7402 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007403 // template code that we don't care.
7404 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007405 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007406 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007407 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007408 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7409 const Node &ON = E->getComponent(I);
7410 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007411 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007412 Comp.LocStart = ON.getSourceRange().getBegin();
7413 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007414 switch (ON.getKind()) {
7415 case Node::Array: {
7416 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007417 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007418 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007419 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007420
Douglas Gregor882211c2010-04-28 22:16:22 +00007421 ExprChanged = ExprChanged || Index.get() != FromIndex;
7422 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007423 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007424 break;
7425 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007426
Douglas Gregor882211c2010-04-28 22:16:22 +00007427 case Node::Field:
7428 case Node::Identifier:
7429 Comp.isBrackets = false;
7430 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007431 if (!Comp.U.IdentInfo)
7432 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007433
Douglas Gregor882211c2010-04-28 22:16:22 +00007434 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007435
Douglas Gregord1702062010-04-29 00:18:15 +00007436 case Node::Base:
7437 // Will be recomputed during the rebuild.
7438 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007439 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007440
Douglas Gregor882211c2010-04-28 22:16:22 +00007441 Components.push_back(Comp);
7442 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007443
Douglas Gregor882211c2010-04-28 22:16:22 +00007444 // If nothing changed, retain the existing expression.
7445 if (!getDerived().AlwaysRebuild() &&
7446 Type == E->getTypeSourceInfo() &&
7447 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007448 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007449
Douglas Gregor882211c2010-04-28 22:16:22 +00007450 // Build a new offsetof expression.
7451 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7452 Components.data(), Components.size(),
7453 E->getRParenLoc());
7454}
7455
7456template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007457ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007458TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7459 assert(getDerived().AlreadyTransformed(E->getType()) &&
7460 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007461 return E;
John McCall8d69a212010-11-15 23:31:06 +00007462}
7463
7464template<typename Derived>
7465ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00007466TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
7467 return E;
7468}
7469
7470template<typename Derived>
7471ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007472TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007473 // Rebuild the syntactic form. The original syntactic form has
7474 // opaque-value expressions in it, so strip those away and rebuild
7475 // the result. This is a really awful way of doing this, but the
7476 // better solution (rebuilding the semantic expressions and
7477 // rebinding OVEs as necessary) doesn't work; we'd need
7478 // TreeTransform to not strip away implicit conversions.
7479 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7480 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007481 if (result.isInvalid()) return ExprError();
7482
7483 // If that gives us a pseudo-object result back, the pseudo-object
7484 // expression must have been an lvalue-to-rvalue conversion which we
7485 // should reapply.
7486 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007487 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007488
7489 return result;
7490}
7491
7492template<typename Derived>
7493ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007494TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7495 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007496 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007497 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007498
John McCallbcd03502009-12-07 02:54:59 +00007499 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007500 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007501 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007502
John McCall4c98fd82009-11-04 07:28:41 +00007503 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007504 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007505
Peter Collingbournee190dee2011-03-11 19:24:49 +00007506 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7507 E->getKind(),
7508 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007509 }
Mike Stump11289f42009-09-09 15:08:12 +00007510
Eli Friedmane4f22df2012-02-29 04:03:55 +00007511 // C++0x [expr.sizeof]p1:
7512 // The operand is either an expression, which is an unevaluated operand
7513 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007514 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7515 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007516
Reid Kleckner32506ed2014-06-12 23:03:48 +00007517 // Try to recover if we have something like sizeof(T::X) where X is a type.
7518 // Notably, there must be *exactly* one set of parens if X is a type.
7519 TypeSourceInfo *RecoveryTSI = nullptr;
7520 ExprResult SubExpr;
7521 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7522 if (auto *DRE =
7523 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7524 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7525 PE, DRE, false, &RecoveryTSI);
7526 else
7527 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7528
7529 if (RecoveryTSI) {
7530 return getDerived().RebuildUnaryExprOrTypeTrait(
7531 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7532 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007533 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007534
Eli Friedmane4f22df2012-02-29 04:03:55 +00007535 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007536 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007537
Peter Collingbournee190dee2011-03-11 19:24:49 +00007538 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7539 E->getOperatorLoc(),
7540 E->getKind(),
7541 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007542}
Mike Stump11289f42009-09-09 15:08:12 +00007543
Douglas Gregora16548e2009-08-11 05:31:07 +00007544template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007545ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007546TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007547 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007548 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007549 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007550
John McCalldadc5752010-08-24 06:29:42 +00007551 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007552 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007553 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007554
7555
Douglas Gregora16548e2009-08-11 05:31:07 +00007556 if (!getDerived().AlwaysRebuild() &&
7557 LHS.get() == E->getLHS() &&
7558 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007559 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007560
John McCallb268a282010-08-23 23:25:46 +00007561 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007562 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007563 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007564 E->getRBracketLoc());
7565}
Mike Stump11289f42009-09-09 15:08:12 +00007566
7567template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007568ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007569TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007570 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007571 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007572 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007573 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007574
7575 // Transform arguments.
7576 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007577 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007578 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007579 &ArgChanged))
7580 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007581
Douglas Gregora16548e2009-08-11 05:31:07 +00007582 if (!getDerived().AlwaysRebuild() &&
7583 Callee.get() == E->getCallee() &&
7584 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007585 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007586
Douglas Gregora16548e2009-08-11 05:31:07 +00007587 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007588 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007589 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007590 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007591 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007592 E->getRParenLoc());
7593}
Mike Stump11289f42009-09-09 15:08:12 +00007594
7595template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007596ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007597TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007598 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007599 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007600 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007601
Douglas Gregorea972d32011-02-28 21:54:11 +00007602 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007603 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007604 QualifierLoc
7605 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007606
Douglas Gregorea972d32011-02-28 21:54:11 +00007607 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007608 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007609 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007610 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007611
Eli Friedman2cfcef62009-12-04 06:40:45 +00007612 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007613 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7614 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007615 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007616 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007617
John McCall16df1e52010-03-30 21:47:33 +00007618 NamedDecl *FoundDecl = E->getFoundDecl();
7619 if (FoundDecl == E->getMemberDecl()) {
7620 FoundDecl = Member;
7621 } else {
7622 FoundDecl = cast_or_null<NamedDecl>(
7623 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7624 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007625 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007626 }
7627
Douglas Gregora16548e2009-08-11 05:31:07 +00007628 if (!getDerived().AlwaysRebuild() &&
7629 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007630 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007631 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007632 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007633 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007634
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007635 // Mark it referenced in the new context regardless.
7636 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007637 SemaRef.MarkMemberReferenced(E);
7638
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007639 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007640 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007641
John McCall6b51f282009-11-23 01:53:49 +00007642 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007643 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007644 TransArgs.setLAngleLoc(E->getLAngleLoc());
7645 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007646 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7647 E->getNumTemplateArgs(),
7648 TransArgs))
7649 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007650 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007651
Douglas Gregora16548e2009-08-11 05:31:07 +00007652 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007653 SourceLocation FakeOperatorLoc =
7654 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007655
John McCall38836f02010-01-15 08:34:02 +00007656 // FIXME: to do this check properly, we will need to preserve the
7657 // first-qualifier-in-scope here, just in case we had a dependent
7658 // base (and therefore couldn't do the check) and a
7659 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007660 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007661
John McCallb268a282010-08-23 23:25:46 +00007662 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007663 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007664 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007665 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007666 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007667 Member,
John McCall16df1e52010-03-30 21:47:33 +00007668 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007669 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007670 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007671 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007672}
Mike Stump11289f42009-09-09 15:08:12 +00007673
Douglas Gregora16548e2009-08-11 05:31:07 +00007674template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007675ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007676TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007677 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007678 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007679 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007680
John McCalldadc5752010-08-24 06:29:42 +00007681 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007682 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007683 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007684
Douglas Gregora16548e2009-08-11 05:31:07 +00007685 if (!getDerived().AlwaysRebuild() &&
7686 LHS.get() == E->getLHS() &&
7687 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007688 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007689
Lang Hames5de91cc2012-10-02 04:45:10 +00007690 Sema::FPContractStateRAII FPContractState(getSema());
7691 getSema().FPFeatures.fp_contract = E->isFPContractable();
7692
Douglas Gregora16548e2009-08-11 05:31:07 +00007693 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007694 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007695}
7696
Mike Stump11289f42009-09-09 15:08:12 +00007697template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007698ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007699TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007700 CompoundAssignOperator *E) {
7701 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007702}
Mike Stump11289f42009-09-09 15:08:12 +00007703
Douglas Gregora16548e2009-08-11 05:31:07 +00007704template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007705ExprResult TreeTransform<Derived>::
7706TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7707 // Just rebuild the common and RHS expressions and see whether we
7708 // get any changes.
7709
7710 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7711 if (commonExpr.isInvalid())
7712 return ExprError();
7713
7714 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7715 if (rhs.isInvalid())
7716 return ExprError();
7717
7718 if (!getDerived().AlwaysRebuild() &&
7719 commonExpr.get() == e->getCommon() &&
7720 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007721 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007722
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007723 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007724 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007725 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007726 e->getColonLoc(),
7727 rhs.get());
7728}
7729
7730template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007731ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007732TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007733 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007734 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007735 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007736
John McCalldadc5752010-08-24 06:29:42 +00007737 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007738 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007739 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007740
John McCalldadc5752010-08-24 06:29:42 +00007741 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007742 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007743 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007744
Douglas Gregora16548e2009-08-11 05:31:07 +00007745 if (!getDerived().AlwaysRebuild() &&
7746 Cond.get() == E->getCond() &&
7747 LHS.get() == E->getLHS() &&
7748 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007749 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007750
John McCallb268a282010-08-23 23:25:46 +00007751 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007752 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007753 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007754 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007755 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007756}
Mike Stump11289f42009-09-09 15:08:12 +00007757
7758template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007759ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007760TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007761 // Implicit casts are eliminated during transformation, since they
7762 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007763 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007764}
Mike Stump11289f42009-09-09 15:08:12 +00007765
Douglas Gregora16548e2009-08-11 05:31:07 +00007766template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007767ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007768TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007769 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7770 if (!Type)
7771 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007772
John McCalldadc5752010-08-24 06:29:42 +00007773 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007774 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007775 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007776 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007777
Douglas Gregora16548e2009-08-11 05:31:07 +00007778 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007779 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007780 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007781 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007782
John McCall97513962010-01-15 18:39:57 +00007783 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007784 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007785 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007786 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007787}
Mike Stump11289f42009-09-09 15:08:12 +00007788
Douglas Gregora16548e2009-08-11 05:31:07 +00007789template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007790ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007791TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007792 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7793 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7794 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007795 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007796
John McCalldadc5752010-08-24 06:29:42 +00007797 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007798 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007799 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007800
Douglas Gregora16548e2009-08-11 05:31:07 +00007801 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007802 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007803 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007804 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007805
John McCall5d7aa7f2010-01-19 22:33:45 +00007806 // Note: the expression type doesn't necessarily match the
7807 // type-as-written, but that's okay, because it should always be
7808 // derivable from the initializer.
7809
John McCalle15bbff2010-01-18 19:35:47 +00007810 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007811 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007812 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007813}
Mike Stump11289f42009-09-09 15:08:12 +00007814
Douglas Gregora16548e2009-08-11 05:31:07 +00007815template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007816ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007817TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007818 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007819 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007820 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007821
Douglas Gregora16548e2009-08-11 05:31:07 +00007822 if (!getDerived().AlwaysRebuild() &&
7823 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007824 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007825
Douglas Gregora16548e2009-08-11 05:31:07 +00007826 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007827 SourceLocation FakeOperatorLoc =
7828 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007829 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007830 E->getAccessorLoc(),
7831 E->getAccessor());
7832}
Mike Stump11289f42009-09-09 15:08:12 +00007833
Douglas Gregora16548e2009-08-11 05:31:07 +00007834template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007835ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007836TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007837 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007838
Benjamin Kramerf0623432012-08-23 22:51:59 +00007839 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007840 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007841 Inits, &InitChanged))
7842 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007843
Douglas Gregora16548e2009-08-11 05:31:07 +00007844 if (!getDerived().AlwaysRebuild() && !InitChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007845 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007846
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007847 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007848 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007849}
Mike Stump11289f42009-09-09 15:08:12 +00007850
Douglas Gregora16548e2009-08-11 05:31:07 +00007851template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007852ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007853TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007854 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007855
Douglas Gregorebe10102009-08-20 07:17:43 +00007856 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007857 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007858 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007859 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007860
Douglas Gregorebe10102009-08-20 07:17:43 +00007861 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007862 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007863 bool ExprChanged = false;
7864 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7865 DEnd = E->designators_end();
7866 D != DEnd; ++D) {
7867 if (D->isFieldDesignator()) {
7868 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7869 D->getDotLoc(),
7870 D->getFieldLoc()));
7871 continue;
7872 }
Mike Stump11289f42009-09-09 15:08:12 +00007873
Douglas Gregora16548e2009-08-11 05:31:07 +00007874 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007875 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007876 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007877 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007878
7879 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007880 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007881
Douglas Gregora16548e2009-08-11 05:31:07 +00007882 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007883 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007884 continue;
7885 }
Mike Stump11289f42009-09-09 15:08:12 +00007886
Douglas Gregora16548e2009-08-11 05:31:07 +00007887 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007888 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007889 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7890 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007891 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007892
John McCalldadc5752010-08-24 06:29:42 +00007893 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007894 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007895 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007896
7897 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007898 End.get(),
7899 D->getLBracketLoc(),
7900 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007901
Douglas Gregora16548e2009-08-11 05:31:07 +00007902 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7903 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007904
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007905 ArrayExprs.push_back(Start.get());
7906 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007907 }
Mike Stump11289f42009-09-09 15:08:12 +00007908
Douglas Gregora16548e2009-08-11 05:31:07 +00007909 if (!getDerived().AlwaysRebuild() &&
7910 Init.get() == E->getInit() &&
7911 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007912 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007913
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007914 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007915 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007916 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007917}
Mike Stump11289f42009-09-09 15:08:12 +00007918
Douglas Gregora16548e2009-08-11 05:31:07 +00007919template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007920ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007921TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007922 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007923 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007924
Douglas Gregor3da3c062009-10-28 00:29:27 +00007925 // FIXME: Will we ever have proper type location here? Will we actually
7926 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007927 QualType T = getDerived().TransformType(E->getType());
7928 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007929 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007930
Douglas Gregora16548e2009-08-11 05:31:07 +00007931 if (!getDerived().AlwaysRebuild() &&
7932 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007933 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007934
Douglas Gregora16548e2009-08-11 05:31:07 +00007935 return getDerived().RebuildImplicitValueInitExpr(T);
7936}
Mike Stump11289f42009-09-09 15:08:12 +00007937
Douglas Gregora16548e2009-08-11 05:31:07 +00007938template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007939ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007940TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007941 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7942 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007943 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007944
John McCalldadc5752010-08-24 06:29:42 +00007945 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007946 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007947 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007948
Douglas Gregora16548e2009-08-11 05:31:07 +00007949 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007950 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007951 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007952 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007953
John McCallb268a282010-08-23 23:25:46 +00007954 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007955 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007956}
7957
7958template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007959ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007960TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007961 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007962 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007963 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7964 &ArgumentChanged))
7965 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007966
Douglas Gregora16548e2009-08-11 05:31:07 +00007967 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007968 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007969 E->getRParenLoc());
7970}
Mike Stump11289f42009-09-09 15:08:12 +00007971
Douglas Gregora16548e2009-08-11 05:31:07 +00007972/// \brief Transform an address-of-label expression.
7973///
7974/// By default, the transformation of an address-of-label expression always
7975/// rebuilds the expression, so that the label identifier can be resolved to
7976/// the corresponding label statement by semantic analysis.
7977template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007978ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007979TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007980 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7981 E->getLabel());
7982 if (!LD)
7983 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007984
Douglas Gregora16548e2009-08-11 05:31:07 +00007985 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007986 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007987}
Mike Stump11289f42009-09-09 15:08:12 +00007988
7989template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007990ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007991TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007992 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007993 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007994 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007995 if (SubStmt.isInvalid()) {
7996 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007997 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007998 }
Mike Stump11289f42009-09-09 15:08:12 +00007999
Douglas Gregora16548e2009-08-11 05:31:07 +00008000 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008001 SubStmt.get() == E->getSubStmt()) {
8002 // Calling this an 'error' is unintuitive, but it does the right thing.
8003 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008004 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008005 }
Mike Stump11289f42009-09-09 15:08:12 +00008006
8007 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008008 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008009 E->getRParenLoc());
8010}
Mike Stump11289f42009-09-09 15:08:12 +00008011
Douglas Gregora16548e2009-08-11 05:31:07 +00008012template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008013ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008014TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008015 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008016 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008017 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008018
John McCalldadc5752010-08-24 06:29:42 +00008019 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008020 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008021 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008022
John McCalldadc5752010-08-24 06:29:42 +00008023 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008024 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008025 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008026
Douglas Gregora16548e2009-08-11 05:31:07 +00008027 if (!getDerived().AlwaysRebuild() &&
8028 Cond.get() == E->getCond() &&
8029 LHS.get() == E->getLHS() &&
8030 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008031 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008032
Douglas Gregora16548e2009-08-11 05:31:07 +00008033 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008034 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008035 E->getRParenLoc());
8036}
Mike Stump11289f42009-09-09 15:08:12 +00008037
Douglas Gregora16548e2009-08-11 05:31:07 +00008038template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008039ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008040TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008041 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008042}
8043
8044template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008045ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008046TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008047 switch (E->getOperator()) {
8048 case OO_New:
8049 case OO_Delete:
8050 case OO_Array_New:
8051 case OO_Array_Delete:
8052 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008053
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008054 case OO_Call: {
8055 // This is a call to an object's operator().
8056 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8057
8058 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008059 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008060 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008061 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008062
8063 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008064 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8065 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008066
8067 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008068 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008069 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008070 Args))
8071 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008072
John McCallb268a282010-08-23 23:25:46 +00008073 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008074 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008075 E->getLocEnd());
8076 }
8077
8078#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8079 case OO_##Name:
8080#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8081#include "clang/Basic/OperatorKinds.def"
8082 case OO_Subscript:
8083 // Handled below.
8084 break;
8085
8086 case OO_Conditional:
8087 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008088
8089 case OO_None:
8090 case NUM_OVERLOADED_OPERATORS:
8091 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008092 }
8093
John McCalldadc5752010-08-24 06:29:42 +00008094 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008095 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008096 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008097
Richard Smithdb2630f2012-10-21 03:28:35 +00008098 ExprResult First;
8099 if (E->getOperator() == OO_Amp)
8100 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8101 else
8102 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008103 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008104 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008105
John McCalldadc5752010-08-24 06:29:42 +00008106 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008107 if (E->getNumArgs() == 2) {
8108 Second = getDerived().TransformExpr(E->getArg(1));
8109 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008110 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008111 }
Mike Stump11289f42009-09-09 15:08:12 +00008112
Douglas Gregora16548e2009-08-11 05:31:07 +00008113 if (!getDerived().AlwaysRebuild() &&
8114 Callee.get() == E->getCallee() &&
8115 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008116 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008117 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008118
Lang Hames5de91cc2012-10-02 04:45:10 +00008119 Sema::FPContractStateRAII FPContractState(getSema());
8120 getSema().FPFeatures.fp_contract = E->isFPContractable();
8121
Douglas Gregora16548e2009-08-11 05:31:07 +00008122 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8123 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008124 Callee.get(),
8125 First.get(),
8126 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008127}
Mike Stump11289f42009-09-09 15:08:12 +00008128
Douglas Gregora16548e2009-08-11 05:31:07 +00008129template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008130ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008131TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8132 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008133}
Mike Stump11289f42009-09-09 15:08:12 +00008134
Douglas Gregora16548e2009-08-11 05:31:07 +00008135template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008136ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008137TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8138 // Transform the callee.
8139 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8140 if (Callee.isInvalid())
8141 return ExprError();
8142
8143 // Transform exec config.
8144 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8145 if (EC.isInvalid())
8146 return ExprError();
8147
8148 // Transform arguments.
8149 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008150 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008151 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008152 &ArgChanged))
8153 return ExprError();
8154
8155 if (!getDerived().AlwaysRebuild() &&
8156 Callee.get() == E->getCallee() &&
8157 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008158 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008159
8160 // FIXME: Wrong source location information for the '('.
8161 SourceLocation FakeLParenLoc
8162 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8163 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008164 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008165 E->getRParenLoc(), EC.get());
8166}
8167
8168template<typename Derived>
8169ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008170TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008171 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8172 if (!Type)
8173 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008174
John McCalldadc5752010-08-24 06:29:42 +00008175 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008176 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008177 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008178 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008179
Douglas Gregora16548e2009-08-11 05:31:07 +00008180 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008181 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008182 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008183 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008184 return getDerived().RebuildCXXNamedCastExpr(
8185 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8186 Type, E->getAngleBrackets().getEnd(),
8187 // FIXME. this should be '(' location
8188 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008189}
Mike Stump11289f42009-09-09 15:08:12 +00008190
Douglas Gregora16548e2009-08-11 05:31:07 +00008191template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008192ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008193TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8194 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008195}
Mike Stump11289f42009-09-09 15:08:12 +00008196
8197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008198ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008199TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8200 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008201}
8202
Douglas Gregora16548e2009-08-11 05:31:07 +00008203template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008204ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008205TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008206 CXXReinterpretCastExpr *E) {
8207 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008208}
Mike Stump11289f42009-09-09 15:08:12 +00008209
Douglas Gregora16548e2009-08-11 05:31:07 +00008210template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008211ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008212TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8213 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008214}
Mike Stump11289f42009-09-09 15:08:12 +00008215
Douglas Gregora16548e2009-08-11 05:31:07 +00008216template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008217ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008218TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008219 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008220 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8221 if (!Type)
8222 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008223
John McCalldadc5752010-08-24 06:29:42 +00008224 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008225 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008226 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008227 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008228
Douglas Gregora16548e2009-08-11 05:31:07 +00008229 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008230 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008231 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008232 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008233
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008234 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008235 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008236 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008237 E->getRParenLoc());
8238}
Mike Stump11289f42009-09-09 15:08:12 +00008239
Douglas Gregora16548e2009-08-11 05:31:07 +00008240template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008241ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008242TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008243 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008244 TypeSourceInfo *TInfo
8245 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8246 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008247 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008248
Douglas Gregora16548e2009-08-11 05:31:07 +00008249 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008250 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008251 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008252
Douglas Gregor9da64192010-04-26 22:37:10 +00008253 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8254 E->getLocStart(),
8255 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008256 E->getLocEnd());
8257 }
Mike Stump11289f42009-09-09 15:08:12 +00008258
Eli Friedman456f0182012-01-20 01:26:23 +00008259 // We don't know whether the subexpression is potentially evaluated until
8260 // after we perform semantic analysis. We speculatively assume it is
8261 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008262 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008263 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8264 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008265
John McCalldadc5752010-08-24 06:29:42 +00008266 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008267 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008268 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008269
Douglas Gregora16548e2009-08-11 05:31:07 +00008270 if (!getDerived().AlwaysRebuild() &&
8271 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008272 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008273
Douglas Gregor9da64192010-04-26 22:37:10 +00008274 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8275 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008276 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008277 E->getLocEnd());
8278}
8279
8280template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008281ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008282TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8283 if (E->isTypeOperand()) {
8284 TypeSourceInfo *TInfo
8285 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8286 if (!TInfo)
8287 return ExprError();
8288
8289 if (!getDerived().AlwaysRebuild() &&
8290 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008291 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008292
Douglas Gregor69735112011-03-06 17:40:41 +00008293 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008294 E->getLocStart(),
8295 TInfo,
8296 E->getLocEnd());
8297 }
8298
Francois Pichet9f4f2072010-09-08 12:20:18 +00008299 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8300
8301 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8302 if (SubExpr.isInvalid())
8303 return ExprError();
8304
8305 if (!getDerived().AlwaysRebuild() &&
8306 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008307 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008308
8309 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8310 E->getLocStart(),
8311 SubExpr.get(),
8312 E->getLocEnd());
8313}
8314
8315template<typename Derived>
8316ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008317TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008318 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008319}
Mike Stump11289f42009-09-09 15:08:12 +00008320
Douglas Gregora16548e2009-08-11 05:31:07 +00008321template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008322ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008323TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008324 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008325 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008326}
Mike Stump11289f42009-09-09 15:08:12 +00008327
Douglas Gregora16548e2009-08-11 05:31:07 +00008328template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008329ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008330TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008331 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008332
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008333 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8334 // Make sure that we capture 'this'.
8335 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008336 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008337 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008338
Douglas Gregorb15af892010-01-07 23:12:05 +00008339 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008340}
Mike Stump11289f42009-09-09 15:08:12 +00008341
Douglas Gregora16548e2009-08-11 05:31:07 +00008342template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008343ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008344TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008345 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008346 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008347 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008348
Douglas Gregora16548e2009-08-11 05:31:07 +00008349 if (!getDerived().AlwaysRebuild() &&
8350 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008351 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008352
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008353 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8354 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008355}
Mike Stump11289f42009-09-09 15:08:12 +00008356
Douglas Gregora16548e2009-08-11 05:31:07 +00008357template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008358ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008359TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008360 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008361 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8362 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008363 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008364 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008365
Chandler Carruth794da4c2010-02-08 06:42:49 +00008366 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008367 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008368 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008369
Douglas Gregor033f6752009-12-23 23:03:06 +00008370 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008371}
Mike Stump11289f42009-09-09 15:08:12 +00008372
Douglas Gregora16548e2009-08-11 05:31:07 +00008373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008374ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008375TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8376 FieldDecl *Field
8377 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8378 E->getField()));
8379 if (!Field)
8380 return ExprError();
8381
8382 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008383 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008384
8385 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8386}
8387
8388template<typename Derived>
8389ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008390TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8391 CXXScalarValueInitExpr *E) {
8392 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8393 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008394 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008395
Douglas Gregora16548e2009-08-11 05:31:07 +00008396 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008397 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008398 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008399
Chad Rosier1dcde962012-08-08 18:46:20 +00008400 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008401 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008402 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008403}
Mike Stump11289f42009-09-09 15:08:12 +00008404
Douglas Gregora16548e2009-08-11 05:31:07 +00008405template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008406ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008407TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008408 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008409 TypeSourceInfo *AllocTypeInfo
8410 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8411 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008412 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008413
Douglas Gregora16548e2009-08-11 05:31:07 +00008414 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008415 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008416 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008417 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008418
Douglas Gregora16548e2009-08-11 05:31:07 +00008419 // Transform the placement arguments (if any).
8420 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008421 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008422 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008423 E->getNumPlacementArgs(), true,
8424 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008425 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008426
Sebastian Redl6047f072012-02-16 12:22:20 +00008427 // Transform the initializer (if any).
8428 Expr *OldInit = E->getInitializer();
8429 ExprResult NewInit;
8430 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008431 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008432 if (NewInit.isInvalid())
8433 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008434
Sebastian Redl6047f072012-02-16 12:22:20 +00008435 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008436 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008437 if (E->getOperatorNew()) {
8438 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008439 getDerived().TransformDecl(E->getLocStart(),
8440 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008441 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008442 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008443 }
8444
Craig Topperc3ec1492014-05-26 06:22:03 +00008445 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008446 if (E->getOperatorDelete()) {
8447 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008448 getDerived().TransformDecl(E->getLocStart(),
8449 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008450 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008451 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008452 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008453
Douglas Gregora16548e2009-08-11 05:31:07 +00008454 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008455 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008456 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008457 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008458 OperatorNew == E->getOperatorNew() &&
8459 OperatorDelete == E->getOperatorDelete() &&
8460 !ArgumentChanged) {
8461 // Mark any declarations we need as referenced.
8462 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008463 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008464 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008465 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008466 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008467
Sebastian Redl6047f072012-02-16 12:22:20 +00008468 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008469 QualType ElementType
8470 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8471 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8472 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8473 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008474 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008475 }
8476 }
8477 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008478
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008479 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008480 }
Mike Stump11289f42009-09-09 15:08:12 +00008481
Douglas Gregor0744ef62010-09-07 21:49:58 +00008482 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008483 if (!ArraySize.get()) {
8484 // If no array size was specified, but the new expression was
8485 // instantiated with an array type (e.g., "new T" where T is
8486 // instantiated with "int[4]"), extract the outer bound from the
8487 // array type as our array size. We do this with constant and
8488 // dependently-sized array types.
8489 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8490 if (!ArrayT) {
8491 // Do nothing
8492 } else if (const ConstantArrayType *ConsArrayT
8493 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008494 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8495 SemaRef.Context.getSizeType(),
8496 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008497 AllocType = ConsArrayT->getElementType();
8498 } else if (const DependentSizedArrayType *DepArrayT
8499 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8500 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008501 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008502 AllocType = DepArrayT->getElementType();
8503 }
8504 }
8505 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008506
Douglas Gregora16548e2009-08-11 05:31:07 +00008507 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8508 E->isGlobalNew(),
8509 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008510 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008511 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008512 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008513 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008514 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008515 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008516 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008517 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008518}
Mike Stump11289f42009-09-09 15:08:12 +00008519
Douglas Gregora16548e2009-08-11 05:31:07 +00008520template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008521ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008522TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008523 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008524 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008525 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008526
Douglas Gregord2d9da02010-02-26 00:38:10 +00008527 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008528 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008529 if (E->getOperatorDelete()) {
8530 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008531 getDerived().TransformDecl(E->getLocStart(),
8532 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008533 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008534 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008535 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008536
Douglas Gregora16548e2009-08-11 05:31:07 +00008537 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008538 Operand.get() == E->getArgument() &&
8539 OperatorDelete == E->getOperatorDelete()) {
8540 // Mark any declarations we need as referenced.
8541 // FIXME: instantiation-specific.
8542 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008543 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008544
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008545 if (!E->getArgument()->isTypeDependent()) {
8546 QualType Destroyed = SemaRef.Context.getBaseElementType(
8547 E->getDestroyedType());
8548 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8549 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008550 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008551 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008552 }
8553 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008554
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008555 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008556 }
Mike Stump11289f42009-09-09 15:08:12 +00008557
Douglas Gregora16548e2009-08-11 05:31:07 +00008558 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8559 E->isGlobalDelete(),
8560 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008561 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008562}
Mike Stump11289f42009-09-09 15:08:12 +00008563
Douglas Gregora16548e2009-08-11 05:31:07 +00008564template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008565ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008566TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008567 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008568 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008569 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008570 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008571
John McCallba7bf592010-08-24 05:47:05 +00008572 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008573 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008574 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008575 E->getOperatorLoc(),
8576 E->isArrow()? tok::arrow : tok::period,
8577 ObjectTypePtr,
8578 MayBePseudoDestructor);
8579 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008580 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008581
John McCallba7bf592010-08-24 05:47:05 +00008582 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008583 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8584 if (QualifierLoc) {
8585 QualifierLoc
8586 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8587 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008588 return ExprError();
8589 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008590 CXXScopeSpec SS;
8591 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008592
Douglas Gregor678f90d2010-02-25 01:56:36 +00008593 PseudoDestructorTypeStorage Destroyed;
8594 if (E->getDestroyedTypeInfo()) {
8595 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008596 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008597 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008598 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008599 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008600 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008601 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008602 // We aren't likely to be able to resolve the identifier down to a type
8603 // now anyway, so just retain the identifier.
8604 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8605 E->getDestroyedTypeLoc());
8606 } else {
8607 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008608 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008609 *E->getDestroyedTypeIdentifier(),
8610 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008611 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008612 SS, ObjectTypePtr,
8613 false);
8614 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008615 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008616
Douglas Gregor678f90d2010-02-25 01:56:36 +00008617 Destroyed
8618 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8619 E->getDestroyedTypeLoc());
8620 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008621
Craig Topperc3ec1492014-05-26 06:22:03 +00008622 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008623 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008624 CXXScopeSpec EmptySS;
8625 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008626 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008627 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008628 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008629 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008630
John McCallb268a282010-08-23 23:25:46 +00008631 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008632 E->getOperatorLoc(),
8633 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008634 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008635 ScopeTypeInfo,
8636 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008637 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008638 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008639}
Mike Stump11289f42009-09-09 15:08:12 +00008640
Douglas Gregorad8a3362009-09-04 17:36:40 +00008641template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008642ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008643TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008644 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008645 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8646 Sema::LookupOrdinaryName);
8647
8648 // Transform all the decls.
8649 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8650 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008651 NamedDecl *InstD = static_cast<NamedDecl*>(
8652 getDerived().TransformDecl(Old->getNameLoc(),
8653 *I));
John McCall84d87672009-12-10 09:41:52 +00008654 if (!InstD) {
8655 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8656 // This can happen because of dependent hiding.
8657 if (isa<UsingShadowDecl>(*I))
8658 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008659 else {
8660 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008661 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008662 }
John McCall84d87672009-12-10 09:41:52 +00008663 }
John McCalle66edc12009-11-24 19:00:30 +00008664
8665 // Expand using declarations.
8666 if (isa<UsingDecl>(InstD)) {
8667 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008668 for (auto *I : UD->shadows())
8669 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008670 continue;
8671 }
8672
8673 R.addDecl(InstD);
8674 }
8675
8676 // Resolve a kind, but don't do any further analysis. If it's
8677 // ambiguous, the callee needs to deal with it.
8678 R.resolveKind();
8679
8680 // Rebuild the nested-name qualifier, if present.
8681 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008682 if (Old->getQualifierLoc()) {
8683 NestedNameSpecifierLoc QualifierLoc
8684 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8685 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008686 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008687
Douglas Gregor0da1d432011-02-28 20:01:57 +00008688 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008689 }
8690
Douglas Gregor9262f472010-04-27 18:19:34 +00008691 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008692 CXXRecordDecl *NamingClass
8693 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8694 Old->getNameLoc(),
8695 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008696 if (!NamingClass) {
8697 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008698 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008699 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008700
Douglas Gregorda7be082010-04-27 16:10:10 +00008701 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008702 }
8703
Abramo Bagnara7945c982012-01-27 09:46:47 +00008704 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8705
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008706 // If we have neither explicit template arguments, nor the template keyword,
8707 // it's a normal declaration name.
8708 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008709 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8710
8711 // If we have template arguments, rebuild them, then rebuild the
8712 // templateid expression.
8713 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008714 if (Old->hasExplicitTemplateArgs() &&
8715 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008716 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008717 TransArgs)) {
8718 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008719 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008720 }
John McCalle66edc12009-11-24 19:00:30 +00008721
Abramo Bagnara7945c982012-01-27 09:46:47 +00008722 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008723 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008724}
Mike Stump11289f42009-09-09 15:08:12 +00008725
Douglas Gregora16548e2009-08-11 05:31:07 +00008726template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008727ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008728TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8729 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008730 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008731 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8732 TypeSourceInfo *From = E->getArg(I);
8733 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008734 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008735 TypeLocBuilder TLB;
8736 TLB.reserve(FromTL.getFullDataSize());
8737 QualType To = getDerived().TransformType(TLB, FromTL);
8738 if (To.isNull())
8739 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008740
Douglas Gregor29c42f22012-02-24 07:38:34 +00008741 if (To == From->getType())
8742 Args.push_back(From);
8743 else {
8744 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8745 ArgChanged = true;
8746 }
8747 continue;
8748 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008749
Douglas Gregor29c42f22012-02-24 07:38:34 +00008750 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008751
Douglas Gregor29c42f22012-02-24 07:38:34 +00008752 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008753 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008754 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8755 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8756 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008757
Douglas Gregor29c42f22012-02-24 07:38:34 +00008758 // Determine whether the set of unexpanded parameter packs can and should
8759 // be expanded.
8760 bool Expand = true;
8761 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008762 Optional<unsigned> OrigNumExpansions =
8763 ExpansionTL.getTypePtr()->getNumExpansions();
8764 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008765 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8766 PatternTL.getSourceRange(),
8767 Unexpanded,
8768 Expand, RetainExpansion,
8769 NumExpansions))
8770 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008771
Douglas Gregor29c42f22012-02-24 07:38:34 +00008772 if (!Expand) {
8773 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008774 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008775 // expansion.
8776 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008777
Douglas Gregor29c42f22012-02-24 07:38:34 +00008778 TypeLocBuilder TLB;
8779 TLB.reserve(From->getTypeLoc().getFullDataSize());
8780
8781 QualType To = getDerived().TransformType(TLB, PatternTL);
8782 if (To.isNull())
8783 return ExprError();
8784
Chad Rosier1dcde962012-08-08 18:46:20 +00008785 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008786 PatternTL.getSourceRange(),
8787 ExpansionTL.getEllipsisLoc(),
8788 NumExpansions);
8789 if (To.isNull())
8790 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008791
Douglas Gregor29c42f22012-02-24 07:38:34 +00008792 PackExpansionTypeLoc ToExpansionTL
8793 = TLB.push<PackExpansionTypeLoc>(To);
8794 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8795 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8796 continue;
8797 }
8798
8799 // Expand the pack expansion by substituting for each argument in the
8800 // pack(s).
8801 for (unsigned I = 0; I != *NumExpansions; ++I) {
8802 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8803 TypeLocBuilder TLB;
8804 TLB.reserve(PatternTL.getFullDataSize());
8805 QualType To = getDerived().TransformType(TLB, PatternTL);
8806 if (To.isNull())
8807 return ExprError();
8808
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008809 if (To->containsUnexpandedParameterPack()) {
8810 To = getDerived().RebuildPackExpansionType(To,
8811 PatternTL.getSourceRange(),
8812 ExpansionTL.getEllipsisLoc(),
8813 NumExpansions);
8814 if (To.isNull())
8815 return ExprError();
8816
8817 PackExpansionTypeLoc ToExpansionTL
8818 = TLB.push<PackExpansionTypeLoc>(To);
8819 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8820 }
8821
Douglas Gregor29c42f22012-02-24 07:38:34 +00008822 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8823 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008824
Douglas Gregor29c42f22012-02-24 07:38:34 +00008825 if (!RetainExpansion)
8826 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008827
Douglas Gregor29c42f22012-02-24 07:38:34 +00008828 // If we're supposed to retain a pack expansion, do so by temporarily
8829 // forgetting the partially-substituted parameter pack.
8830 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8831
8832 TypeLocBuilder TLB;
8833 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008834
Douglas Gregor29c42f22012-02-24 07:38:34 +00008835 QualType To = getDerived().TransformType(TLB, PatternTL);
8836 if (To.isNull())
8837 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008838
8839 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008840 PatternTL.getSourceRange(),
8841 ExpansionTL.getEllipsisLoc(),
8842 NumExpansions);
8843 if (To.isNull())
8844 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008845
Douglas Gregor29c42f22012-02-24 07:38:34 +00008846 PackExpansionTypeLoc ToExpansionTL
8847 = TLB.push<PackExpansionTypeLoc>(To);
8848 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8849 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8850 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008851
Douglas Gregor29c42f22012-02-24 07:38:34 +00008852 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008853 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008854
8855 return getDerived().RebuildTypeTrait(E->getTrait(),
8856 E->getLocStart(),
8857 Args,
8858 E->getLocEnd());
8859}
8860
8861template<typename Derived>
8862ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008863TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8864 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8865 if (!T)
8866 return ExprError();
8867
8868 if (!getDerived().AlwaysRebuild() &&
8869 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008870 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008871
8872 ExprResult SubExpr;
8873 {
8874 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8875 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8876 if (SubExpr.isInvalid())
8877 return ExprError();
8878
8879 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008880 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008881 }
8882
8883 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8884 E->getLocStart(),
8885 T,
8886 SubExpr.get(),
8887 E->getLocEnd());
8888}
8889
8890template<typename Derived>
8891ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008892TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8893 ExprResult SubExpr;
8894 {
8895 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8896 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8897 if (SubExpr.isInvalid())
8898 return ExprError();
8899
8900 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008901 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008902 }
8903
8904 return getDerived().RebuildExpressionTrait(
8905 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8906}
8907
Reid Kleckner32506ed2014-06-12 23:03:48 +00008908template <typename Derived>
8909ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8910 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8911 TypeSourceInfo **RecoveryTSI) {
8912 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8913 DRE, AddrTaken, RecoveryTSI);
8914
8915 // Propagate both errors and recovered types, which return ExprEmpty.
8916 if (!NewDRE.isUsable())
8917 return NewDRE;
8918
8919 // We got an expr, wrap it up in parens.
8920 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8921 return PE;
8922 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8923 PE->getRParen());
8924}
8925
8926template <typename Derived>
8927ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8928 DependentScopeDeclRefExpr *E) {
8929 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8930 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008931}
8932
8933template<typename Derived>
8934ExprResult
8935TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8936 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00008937 bool IsAddressOfOperand,
8938 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008939 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008940 NestedNameSpecifierLoc QualifierLoc
8941 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8942 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008943 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008944 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008945
John McCall31f82722010-11-12 08:19:04 +00008946 // TODO: If this is a conversion-function-id, verify that the
8947 // destination type name (if present) resolves the same way after
8948 // instantiation as it did in the local scope.
8949
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008950 DeclarationNameInfo NameInfo
8951 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8952 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008953 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008954
John McCalle66edc12009-11-24 19:00:30 +00008955 if (!E->hasExplicitTemplateArgs()) {
8956 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008957 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008958 // Note: it is sufficient to compare the Name component of NameInfo:
8959 // if name has not changed, DNLoc has not changed either.
8960 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008961 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008962
Reid Kleckner32506ed2014-06-12 23:03:48 +00008963 return getDerived().RebuildDependentScopeDeclRefExpr(
8964 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
8965 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00008966 }
John McCall6b51f282009-11-23 01:53:49 +00008967
8968 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008969 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8970 E->getNumTemplateArgs(),
8971 TransArgs))
8972 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008973
Reid Kleckner32506ed2014-06-12 23:03:48 +00008974 return getDerived().RebuildDependentScopeDeclRefExpr(
8975 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
8976 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00008977}
8978
8979template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008980ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008981TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008982 // CXXConstructExprs other than for list-initialization and
8983 // CXXTemporaryObjectExpr are always implicit, so when we have
8984 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008985 if ((E->getNumArgs() == 1 ||
8986 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008987 (!getDerived().DropCallArgument(E->getArg(0))) &&
8988 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008989 return getDerived().TransformExpr(E->getArg(0));
8990
Douglas Gregora16548e2009-08-11 05:31:07 +00008991 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8992
8993 QualType T = getDerived().TransformType(E->getType());
8994 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008995 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008996
8997 CXXConstructorDecl *Constructor
8998 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008999 getDerived().TransformDecl(E->getLocStart(),
9000 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009001 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009002 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009003
Douglas Gregora16548e2009-08-11 05:31:07 +00009004 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009005 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009006 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009007 &ArgumentChanged))
9008 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009009
Douglas Gregora16548e2009-08-11 05:31:07 +00009010 if (!getDerived().AlwaysRebuild() &&
9011 T == E->getType() &&
9012 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009013 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009014 // Mark the constructor as referenced.
9015 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009016 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009017 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009018 }
Mike Stump11289f42009-09-09 15:08:12 +00009019
Douglas Gregordb121ba2009-12-14 16:27:04 +00009020 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9021 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009022 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009023 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009024 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009025 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009026 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009027 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009028 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009029}
Mike Stump11289f42009-09-09 15:08:12 +00009030
Douglas Gregora16548e2009-08-11 05:31:07 +00009031/// \brief Transform a C++ temporary-binding expression.
9032///
Douglas Gregor363b1512009-12-24 18:51:59 +00009033/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9034/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009035template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009036ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009037TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009038 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009039}
Mike Stump11289f42009-09-09 15:08:12 +00009040
John McCall5d413782010-12-06 08:20:24 +00009041/// \brief Transform a C++ expression that contains cleanups that should
9042/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009043///
John McCall5d413782010-12-06 08:20:24 +00009044/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009045/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009046template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009047ExprResult
John McCall5d413782010-12-06 08:20:24 +00009048TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009049 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009050}
Mike Stump11289f42009-09-09 15:08:12 +00009051
Douglas Gregora16548e2009-08-11 05:31:07 +00009052template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009053ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009054TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009055 CXXTemporaryObjectExpr *E) {
9056 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9057 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009058 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009059
Douglas Gregora16548e2009-08-11 05:31:07 +00009060 CXXConstructorDecl *Constructor
9061 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009062 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009063 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009064 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009065 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009066
Douglas Gregora16548e2009-08-11 05:31:07 +00009067 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009068 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009069 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009070 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009071 &ArgumentChanged))
9072 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009073
Douglas Gregora16548e2009-08-11 05:31:07 +00009074 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009075 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009076 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009077 !ArgumentChanged) {
9078 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009079 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009080 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009081 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009082
Richard Smithd59b8322012-12-19 01:39:02 +00009083 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009084 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9085 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009086 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009087 E->getLocEnd());
9088}
Mike Stump11289f42009-09-09 15:08:12 +00009089
Douglas Gregora16548e2009-08-11 05:31:07 +00009090template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009091ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009092TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009093 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009094 // lambda body, because they are not semantically within that scope.
9095 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9096 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
9097 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009098 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009099 CEnd = E->capture_end();
9100 C != CEnd; ++C) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009101 if (!C->isInitCapture())
9102 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009103 EnterExpressionEvaluationContext EEEC(getSema(),
9104 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009105 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9106 C->getCapturedVar()->getInit(),
9107 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009108
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009109 if (NewExprInitResult.isInvalid())
9110 return ExprError();
9111 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009112
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009113 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009114 QualType NewInitCaptureType =
9115 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
9116 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009117 NewExprInit);
9118 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009119 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9120 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009121 }
9122
Faisal Vali524ca282013-11-12 01:40:44 +00009123 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Reid Kleckneraac43c62014-12-15 21:07:16 +00009124 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9125
Faisal Vali2cba1332013-10-23 06:44:28 +00009126 // Transform the template parameters, and add them to the current
9127 // instantiation scope. The null case is handled correctly.
9128 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
9129 E->getTemplateParameterList());
9130
Richard Smith01014ce2014-11-20 23:53:14 +00009131 // Transform the type of the original lambda's call operator.
9132 // The transformation MUST be done in the CurrentInstantiationScope since
9133 // it introduces a mapping of the original to the newly created
9134 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009135 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009136 {
9137 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9138 FunctionProtoTypeLoc OldCallOpFPTL =
9139 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009140
9141 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009142 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009143 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009144 QualType NewCallOpType = TransformFunctionProtoType(
9145 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009146 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9147 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9148 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009149 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009150 if (NewCallOpType.isNull())
9151 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009152 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9153 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009154 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009155
Eli Friedmand564afb2012-09-19 01:18:11 +00009156 // Create the local class that will describe the lambda.
9157 CXXRecordDecl *Class
9158 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009159 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009160 /*KnownDependent=*/false,
9161 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009162 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9163
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009164 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009165 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9166 Class, E->getIntroducerRange(), NewCallOpTSI,
9167 E->getCallOperator()->getLocEnd(),
9168 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009169 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009170
Faisal Vali2cba1332013-10-23 06:44:28 +00009171 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
9172
Reid Kleckneraac43c62014-12-15 21:07:16 +00009173 // TransformLambdaScope will manage the function scope, so we can disable the
9174 // cleanup.
9175 FuncScopeCleanup.disable();
9176
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009177 return getDerived().TransformLambdaScope(E, NewCallOperator,
9178 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00009179}
9180
9181template<typename Derived>
9182ExprResult
9183TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009184 CXXMethodDecl *CallOperator,
9185 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00009186 bool Invalid = false;
9187
Douglas Gregorb4328232012-02-14 00:00:48 +00009188 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009189 Sema::ContextRAII SavedContext(getSema(), CallOperator,
9190 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009191
Faisal Vali2b391ab2013-09-26 19:54:12 +00009192 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009193 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00009194 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009195 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00009196 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009197 E->hasExplicitParameters(),
9198 E->hasExplicitResultType(),
9199 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00009200
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009201 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009202 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009203 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009204 CEnd = E->capture_end();
9205 C != CEnd; ++C) {
9206 // When we hit the first implicit capture, tell Sema that we've finished
9207 // the list of explicit captures.
9208 if (!FinishedExplicitCaptures && C->isImplicit()) {
9209 getSema().finishLambdaExplicitCaptures(LSI);
9210 FinishedExplicitCaptures = true;
9211 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009212
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009213 // Capturing 'this' is trivial.
9214 if (C->capturesThis()) {
9215 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9216 continue;
9217 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009218 // Captured expression will be recaptured during captured variables
9219 // rebuilding.
9220 if (C->capturesVLAType())
9221 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009222
Richard Smithba71c082013-05-16 06:20:58 +00009223 // Rebuild init-captures, including the implied field declaration.
9224 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009225
9226 InitCaptureInfoTy InitExprTypePair =
9227 InitCaptureExprsAndTypes[C - E->capture_begin()];
9228 ExprResult Init = InitExprTypePair.first;
9229 QualType InitQualType = InitExprTypePair.second;
9230 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009231 Invalid = true;
9232 continue;
9233 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009234 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009235 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9236 OldVD->getLocation(), InitExprTypePair.second,
9237 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009238 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009239 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009240 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009241 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009242 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009243 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009244 continue;
9245 }
9246
9247 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9248
Douglas Gregor3e308b12012-02-14 19:27:52 +00009249 // Determine the capture kind for Sema.
9250 Sema::TryCaptureKind Kind
9251 = C->isImplicit()? Sema::TryCapture_Implicit
9252 : C->getCaptureKind() == LCK_ByCopy
9253 ? Sema::TryCapture_ExplicitByVal
9254 : Sema::TryCapture_ExplicitByRef;
9255 SourceLocation EllipsisLoc;
9256 if (C->isPackExpansion()) {
9257 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9258 bool ShouldExpand = false;
9259 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009260 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009261 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9262 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009263 Unexpanded,
9264 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009265 NumExpansions)) {
9266 Invalid = true;
9267 continue;
9268 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009269
Douglas Gregor3e308b12012-02-14 19:27:52 +00009270 if (ShouldExpand) {
9271 // The transform has determined that we should perform an expansion;
9272 // transform and capture each of the arguments.
9273 // expansion of the pattern. Do so.
9274 VarDecl *Pack = C->getCapturedVar();
9275 for (unsigned I = 0; I != *NumExpansions; ++I) {
9276 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9277 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009278 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009279 Pack));
9280 if (!CapturedVar) {
9281 Invalid = true;
9282 continue;
9283 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009284
Douglas Gregor3e308b12012-02-14 19:27:52 +00009285 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009286 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9287 }
Richard Smith9467be42014-06-06 17:33:35 +00009288
9289 // FIXME: Retain a pack expansion if RetainExpansion is true.
9290
Douglas Gregor3e308b12012-02-14 19:27:52 +00009291 continue;
9292 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009293
Douglas Gregor3e308b12012-02-14 19:27:52 +00009294 EllipsisLoc = C->getEllipsisLoc();
9295 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009296
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009297 // Transform the captured variable.
9298 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009299 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009300 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009301 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009302 Invalid = true;
9303 continue;
9304 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009305
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009306 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00009307 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009308 }
9309 if (!FinishedExplicitCaptures)
9310 getSema().finishLambdaExplicitCaptures(LSI);
9311
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009312
9313 // Enter a new evaluation context to insulate the lambda from any
9314 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009315 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009316
9317 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009318 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009319 /*IsInstantiation=*/true);
9320 return ExprError();
9321 }
9322
9323 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00009324 StmtResult Body = getDerived().TransformStmt(E->getBody());
9325 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009326 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009327 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009328 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009329 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009330
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009331 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009332 /*CurScope=*/nullptr,
9333 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00009334}
9335
9336template<typename Derived>
9337ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009338TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009339 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009340 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9341 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009342 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009343
Douglas Gregora16548e2009-08-11 05:31:07 +00009344 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009345 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009346 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009347 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009348 &ArgumentChanged))
9349 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009350
Douglas Gregora16548e2009-08-11 05:31:07 +00009351 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009352 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009353 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009354 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009355
Douglas Gregora16548e2009-08-11 05:31:07 +00009356 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009357 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009358 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009359 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009360 E->getRParenLoc());
9361}
Mike Stump11289f42009-09-09 15:08:12 +00009362
Douglas Gregora16548e2009-08-11 05:31:07 +00009363template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009364ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009365TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009366 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009367 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009368 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009369 Expr *OldBase;
9370 QualType BaseType;
9371 QualType ObjectType;
9372 if (!E->isImplicitAccess()) {
9373 OldBase = E->getBase();
9374 Base = getDerived().TransformExpr(OldBase);
9375 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009376 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009377
John McCall2d74de92009-12-01 22:10:20 +00009378 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009379 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009380 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009381 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009382 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009383 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009384 ObjectTy,
9385 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009386 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009387 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009388
John McCallba7bf592010-08-24 05:47:05 +00009389 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009390 BaseType = ((Expr*) Base.get())->getType();
9391 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009392 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009393 BaseType = getDerived().TransformType(E->getBaseType());
9394 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9395 }
Mike Stump11289f42009-09-09 15:08:12 +00009396
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009397 // Transform the first part of the nested-name-specifier that qualifies
9398 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009399 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009400 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009401 E->getFirstQualifierFoundInScope(),
9402 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009403
Douglas Gregore16af532011-02-28 18:50:33 +00009404 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009405 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009406 QualifierLoc
9407 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9408 ObjectType,
9409 FirstQualifierInScope);
9410 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009411 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009412 }
Mike Stump11289f42009-09-09 15:08:12 +00009413
Abramo Bagnara7945c982012-01-27 09:46:47 +00009414 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9415
John McCall31f82722010-11-12 08:19:04 +00009416 // TODO: If this is a conversion-function-id, verify that the
9417 // destination type name (if present) resolves the same way after
9418 // instantiation as it did in the local scope.
9419
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009420 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009421 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009422 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009423 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009424
John McCall2d74de92009-12-01 22:10:20 +00009425 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009426 // This is a reference to a member without an explicitly-specified
9427 // template argument list. Optimize for this common case.
9428 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009429 Base.get() == OldBase &&
9430 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009431 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009432 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009433 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009434 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009435
John McCallb268a282010-08-23 23:25:46 +00009436 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009437 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009438 E->isArrow(),
9439 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009440 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009441 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009442 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009443 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009444 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009445 }
9446
John McCall6b51f282009-11-23 01:53:49 +00009447 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009448 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9449 E->getNumTemplateArgs(),
9450 TransArgs))
9451 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009452
John McCallb268a282010-08-23 23:25:46 +00009453 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009454 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009455 E->isArrow(),
9456 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009457 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009458 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009459 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009460 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009461 &TransArgs);
9462}
9463
9464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009465ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009466TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009467 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009468 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009469 QualType BaseType;
9470 if (!Old->isImplicitAccess()) {
9471 Base = getDerived().TransformExpr(Old->getBase());
9472 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009473 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009474 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009475 Old->isArrow());
9476 if (Base.isInvalid())
9477 return ExprError();
9478 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009479 } else {
9480 BaseType = getDerived().TransformType(Old->getBaseType());
9481 }
John McCall10eae182009-11-30 22:42:35 +00009482
Douglas Gregor0da1d432011-02-28 20:01:57 +00009483 NestedNameSpecifierLoc QualifierLoc;
9484 if (Old->getQualifierLoc()) {
9485 QualifierLoc
9486 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9487 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009488 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009489 }
9490
Abramo Bagnara7945c982012-01-27 09:46:47 +00009491 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9492
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009493 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009494 Sema::LookupOrdinaryName);
9495
9496 // Transform all the decls.
9497 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9498 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009499 NamedDecl *InstD = static_cast<NamedDecl*>(
9500 getDerived().TransformDecl(Old->getMemberLoc(),
9501 *I));
John McCall84d87672009-12-10 09:41:52 +00009502 if (!InstD) {
9503 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9504 // This can happen because of dependent hiding.
9505 if (isa<UsingShadowDecl>(*I))
9506 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009507 else {
9508 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009509 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009510 }
John McCall84d87672009-12-10 09:41:52 +00009511 }
John McCall10eae182009-11-30 22:42:35 +00009512
9513 // Expand using declarations.
9514 if (isa<UsingDecl>(InstD)) {
9515 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009516 for (auto *I : UD->shadows())
9517 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009518 continue;
9519 }
9520
9521 R.addDecl(InstD);
9522 }
9523
9524 R.resolveKind();
9525
Douglas Gregor9262f472010-04-27 18:19:34 +00009526 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009527 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009528 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009529 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009530 Old->getMemberLoc(),
9531 Old->getNamingClass()));
9532 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009533 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009534
Douglas Gregorda7be082010-04-27 16:10:10 +00009535 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009536 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009537
John McCall10eae182009-11-30 22:42:35 +00009538 TemplateArgumentListInfo TransArgs;
9539 if (Old->hasExplicitTemplateArgs()) {
9540 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9541 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009542 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9543 Old->getNumTemplateArgs(),
9544 TransArgs))
9545 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009546 }
John McCall38836f02010-01-15 08:34:02 +00009547
9548 // FIXME: to do this check properly, we will need to preserve the
9549 // first-qualifier-in-scope here, just in case we had a dependent
9550 // base (and therefore couldn't do the check) and a
9551 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009552 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009553
John McCallb268a282010-08-23 23:25:46 +00009554 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009555 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009556 Old->getOperatorLoc(),
9557 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009558 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009559 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009560 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009561 R,
9562 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009563 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009564}
9565
9566template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009567ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009568TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009569 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009570 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9571 if (SubExpr.isInvalid())
9572 return ExprError();
9573
9574 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009575 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009576
9577 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9578}
9579
9580template<typename Derived>
9581ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009582TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009583 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9584 if (Pattern.isInvalid())
9585 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009586
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009587 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009588 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009589
Douglas Gregorb8840002011-01-14 21:20:45 +00009590 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9591 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009592}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009593
9594template<typename Derived>
9595ExprResult
9596TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9597 // If E is not value-dependent, then nothing will change when we transform it.
9598 // Note: This is an instantiation-centric view.
9599 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009600 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009601
9602 // Note: None of the implementations of TryExpandParameterPacks can ever
9603 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009604 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009605 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9606 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009607 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009608 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009609 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009610 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009611 ShouldExpand, RetainExpansion,
9612 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009613 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009614
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009615 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009616 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009617
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009618 NamedDecl *Pack = E->getPack();
9619 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009620 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009621 Pack));
9622 if (!Pack)
9623 return ExprError();
9624 }
9625
Chad Rosier1dcde962012-08-08 18:46:20 +00009626
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009627 // We now know the length of the parameter pack, so build a new expression
9628 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009629 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9630 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009631 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009632}
9633
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009634template<typename Derived>
9635ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009636TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9637 SubstNonTypeTemplateParmPackExpr *E) {
9638 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009639 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009640}
9641
9642template<typename Derived>
9643ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009644TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9645 SubstNonTypeTemplateParmExpr *E) {
9646 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009647 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009648}
9649
9650template<typename Derived>
9651ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009652TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9653 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009654 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009655}
9656
9657template<typename Derived>
9658ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009659TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9660 MaterializeTemporaryExpr *E) {
9661 return getDerived().TransformExpr(E->GetTemporaryExpr());
9662}
Chad Rosier1dcde962012-08-08 18:46:20 +00009663
Douglas Gregorfe314812011-06-21 17:03:29 +00009664template<typename Derived>
9665ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +00009666TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
9667 Expr *Pattern = E->getPattern();
9668
9669 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9670 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
9671 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9672
9673 // Determine whether the set of unexpanded parameter packs can and should
9674 // be expanded.
9675 bool Expand = true;
9676 bool RetainExpansion = false;
9677 Optional<unsigned> NumExpansions;
9678 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
9679 Pattern->getSourceRange(),
9680 Unexpanded,
9681 Expand, RetainExpansion,
9682 NumExpansions))
9683 return true;
9684
9685 if (!Expand) {
9686 // Do not expand any packs here, just transform and rebuild a fold
9687 // expression.
9688 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9689
9690 ExprResult LHS =
9691 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
9692 if (LHS.isInvalid())
9693 return true;
9694
9695 ExprResult RHS =
9696 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
9697 if (RHS.isInvalid())
9698 return true;
9699
9700 if (!getDerived().AlwaysRebuild() &&
9701 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
9702 return E;
9703
9704 return getDerived().RebuildCXXFoldExpr(
9705 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
9706 RHS.get(), E->getLocEnd());
9707 }
9708
9709 // The transform has determined that we should perform an elementwise
9710 // expansion of the pattern. Do so.
9711 ExprResult Result = getDerived().TransformExpr(E->getInit());
9712 if (Result.isInvalid())
9713 return true;
9714 bool LeftFold = E->isLeftFold();
9715
9716 // If we're retaining an expansion for a right fold, it is the innermost
9717 // component and takes the init (if any).
9718 if (!LeftFold && RetainExpansion) {
9719 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9720
9721 ExprResult Out = getDerived().TransformExpr(Pattern);
9722 if (Out.isInvalid())
9723 return true;
9724
9725 Result = getDerived().RebuildCXXFoldExpr(
9726 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
9727 Result.get(), E->getLocEnd());
9728 if (Result.isInvalid())
9729 return true;
9730 }
9731
9732 for (unsigned I = 0; I != *NumExpansions; ++I) {
9733 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
9734 getSema(), LeftFold ? I : *NumExpansions - I - 1);
9735 ExprResult Out = getDerived().TransformExpr(Pattern);
9736 if (Out.isInvalid())
9737 return true;
9738
9739 if (Out.get()->containsUnexpandedParameterPack()) {
9740 // We still have a pack; retain a pack expansion for this slice.
9741 Result = getDerived().RebuildCXXFoldExpr(
9742 E->getLocStart(),
9743 LeftFold ? Result.get() : Out.get(),
9744 E->getOperator(), E->getEllipsisLoc(),
9745 LeftFold ? Out.get() : Result.get(),
9746 E->getLocEnd());
9747 } else if (Result.isUsable()) {
9748 // We've got down to a single element; build a binary operator.
9749 Result = getDerived().RebuildBinaryOperator(
9750 E->getEllipsisLoc(), E->getOperator(),
9751 LeftFold ? Result.get() : Out.get(),
9752 LeftFold ? Out.get() : Result.get());
9753 } else
9754 Result = Out;
9755
9756 if (Result.isInvalid())
9757 return true;
9758 }
9759
9760 // If we're retaining an expansion for a left fold, it is the outermost
9761 // component and takes the complete expansion so far as its init (if any).
9762 if (LeftFold && RetainExpansion) {
9763 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9764
9765 ExprResult Out = getDerived().TransformExpr(Pattern);
9766 if (Out.isInvalid())
9767 return true;
9768
9769 Result = getDerived().RebuildCXXFoldExpr(
9770 E->getLocStart(), Result.get(),
9771 E->getOperator(), E->getEllipsisLoc(),
9772 Out.get(), E->getLocEnd());
9773 if (Result.isInvalid())
9774 return true;
9775 }
9776
9777 // If we had no init and an empty pack, and we're not retaining an expansion,
9778 // then produce a fallback value or error.
9779 if (Result.isUnset())
9780 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
9781 E->getOperator());
9782
9783 return Result;
9784}
9785
9786template<typename Derived>
9787ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009788TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9789 CXXStdInitializerListExpr *E) {
9790 return getDerived().TransformExpr(E->getSubExpr());
9791}
9792
9793template<typename Derived>
9794ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009795TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009796 return SemaRef.MaybeBindToTemporary(E);
9797}
9798
9799template<typename Derived>
9800ExprResult
9801TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009802 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009803}
9804
9805template<typename Derived>
9806ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009807TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9808 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9809 if (SubExpr.isInvalid())
9810 return ExprError();
9811
9812 if (!getDerived().AlwaysRebuild() &&
9813 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009814 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009815
9816 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009817}
9818
9819template<typename Derived>
9820ExprResult
9821TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9822 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009823 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009824 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009825 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009826 /*IsCall=*/false, Elements, &ArgChanged))
9827 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009828
Ted Kremeneke65b0862012-03-06 20:05:56 +00009829 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9830 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009831
Ted Kremeneke65b0862012-03-06 20:05:56 +00009832 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9833 Elements.data(),
9834 Elements.size());
9835}
9836
9837template<typename Derived>
9838ExprResult
9839TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009840 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009841 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009842 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009843 bool ArgChanged = false;
9844 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9845 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009846
Ted Kremeneke65b0862012-03-06 20:05:56 +00009847 if (OrigElement.isPackExpansion()) {
9848 // This key/value element is a pack expansion.
9849 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9850 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9851 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9852 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9853
9854 // Determine whether the set of unexpanded parameter packs can
9855 // and should be expanded.
9856 bool Expand = true;
9857 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009858 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9859 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009860 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9861 OrigElement.Value->getLocEnd());
9862 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9863 PatternRange,
9864 Unexpanded,
9865 Expand, RetainExpansion,
9866 NumExpansions))
9867 return ExprError();
9868
9869 if (!Expand) {
9870 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009871 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009872 // expansion.
9873 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9874 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9875 if (Key.isInvalid())
9876 return ExprError();
9877
9878 if (Key.get() != OrigElement.Key)
9879 ArgChanged = true;
9880
9881 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9882 if (Value.isInvalid())
9883 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009884
Ted Kremeneke65b0862012-03-06 20:05:56 +00009885 if (Value.get() != OrigElement.Value)
9886 ArgChanged = true;
9887
Chad Rosier1dcde962012-08-08 18:46:20 +00009888 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009889 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9890 };
9891 Elements.push_back(Expansion);
9892 continue;
9893 }
9894
9895 // Record right away that the argument was changed. This needs
9896 // to happen even if the array expands to nothing.
9897 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009898
Ted Kremeneke65b0862012-03-06 20:05:56 +00009899 // The transform has determined that we should perform an elementwise
9900 // expansion of the pattern. Do so.
9901 for (unsigned I = 0; I != *NumExpansions; ++I) {
9902 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9903 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9904 if (Key.isInvalid())
9905 return ExprError();
9906
9907 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9908 if (Value.isInvalid())
9909 return ExprError();
9910
Chad Rosier1dcde962012-08-08 18:46:20 +00009911 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009912 Key.get(), Value.get(), SourceLocation(), NumExpansions
9913 };
9914
9915 // If any unexpanded parameter packs remain, we still have a
9916 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +00009917 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +00009918 if (Key.get()->containsUnexpandedParameterPack() ||
9919 Value.get()->containsUnexpandedParameterPack())
9920 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009921
Ted Kremeneke65b0862012-03-06 20:05:56 +00009922 Elements.push_back(Element);
9923 }
9924
Richard Smith9467be42014-06-06 17:33:35 +00009925 // FIXME: Retain a pack expansion if RetainExpansion is true.
9926
Ted Kremeneke65b0862012-03-06 20:05:56 +00009927 // We've finished with this pack expansion.
9928 continue;
9929 }
9930
9931 // Transform and check key.
9932 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9933 if (Key.isInvalid())
9934 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009935
Ted Kremeneke65b0862012-03-06 20:05:56 +00009936 if (Key.get() != OrigElement.Key)
9937 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009938
Ted Kremeneke65b0862012-03-06 20:05:56 +00009939 // Transform and check value.
9940 ExprResult Value
9941 = getDerived().TransformExpr(OrigElement.Value);
9942 if (Value.isInvalid())
9943 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009944
Ted Kremeneke65b0862012-03-06 20:05:56 +00009945 if (Value.get() != OrigElement.Value)
9946 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009947
9948 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009949 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009950 };
9951 Elements.push_back(Element);
9952 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009953
Ted Kremeneke65b0862012-03-06 20:05:56 +00009954 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9955 return SemaRef.MaybeBindToTemporary(E);
9956
9957 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9958 Elements.data(),
9959 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009960}
9961
Mike Stump11289f42009-09-09 15:08:12 +00009962template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009963ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009964TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009965 TypeSourceInfo *EncodedTypeInfo
9966 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9967 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009968 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009969
Douglas Gregora16548e2009-08-11 05:31:07 +00009970 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009971 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009972 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009973
9974 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009975 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009976 E->getRParenLoc());
9977}
Mike Stump11289f42009-09-09 15:08:12 +00009978
Douglas Gregora16548e2009-08-11 05:31:07 +00009979template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009980ExprResult TreeTransform<Derived>::
9981TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009982 // This is a kind of implicit conversion, and it needs to get dropped
9983 // and recomputed for the same general reasons that ImplicitCastExprs
9984 // do, as well a more specific one: this expression is only valid when
9985 // it appears *immediately* as an argument expression.
9986 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009987}
9988
9989template<typename Derived>
9990ExprResult TreeTransform<Derived>::
9991TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009992 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009993 = getDerived().TransformType(E->getTypeInfoAsWritten());
9994 if (!TSInfo)
9995 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009996
John McCall31168b02011-06-15 23:02:42 +00009997 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009998 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009999 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010000
John McCall31168b02011-06-15 23:02:42 +000010001 if (!getDerived().AlwaysRebuild() &&
10002 TSInfo == E->getTypeInfoAsWritten() &&
10003 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010004 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010005
John McCall31168b02011-06-15 23:02:42 +000010006 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010007 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010008 Result.get());
10009}
10010
10011template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010012ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010013TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010014 // Transform arguments.
10015 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010016 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010017 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010018 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010019 &ArgChanged))
10020 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010021
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010022 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10023 // Class message: transform the receiver type.
10024 TypeSourceInfo *ReceiverTypeInfo
10025 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10026 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010027 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010028
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010029 // If nothing changed, just retain the existing message send.
10030 if (!getDerived().AlwaysRebuild() &&
10031 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010032 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010033
10034 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010035 SmallVector<SourceLocation, 16> SelLocs;
10036 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010037 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10038 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010039 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010040 E->getMethodDecl(),
10041 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010042 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010043 E->getRightLoc());
10044 }
10045
10046 // Instance message: transform the receiver
10047 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10048 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010049 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010050 = getDerived().TransformExpr(E->getInstanceReceiver());
10051 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010052 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010053
10054 // If nothing changed, just retain the existing message send.
10055 if (!getDerived().AlwaysRebuild() &&
10056 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010057 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010058
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010059 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010060 SmallVector<SourceLocation, 16> SelLocs;
10061 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010062 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010063 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010064 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010065 E->getMethodDecl(),
10066 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010067 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010068 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010069}
10070
Mike Stump11289f42009-09-09 15:08:12 +000010071template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010072ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010073TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010074 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010075}
10076
Mike Stump11289f42009-09-09 15:08:12 +000010077template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010078ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010079TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010080 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010081}
10082
Mike Stump11289f42009-09-09 15:08:12 +000010083template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010084ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010085TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010086 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010087 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010088 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010089 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010090
10091 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010092
Douglas Gregord51d90d2010-04-26 20:11:03 +000010093 // If nothing changed, just retain the existing expression.
10094 if (!getDerived().AlwaysRebuild() &&
10095 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010096 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010097
John McCallb268a282010-08-23 23:25:46 +000010098 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010099 E->getLocation(),
10100 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010101}
10102
Mike Stump11289f42009-09-09 15:08:12 +000010103template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010104ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010105TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010106 // 'super' and types never change. Property never changes. Just
10107 // retain the existing expression.
10108 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010109 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010110
Douglas Gregor9faee212010-04-26 20:47:02 +000010111 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010112 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010113 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010114 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010115
Douglas Gregor9faee212010-04-26 20:47:02 +000010116 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010117
Douglas Gregor9faee212010-04-26 20:47:02 +000010118 // If nothing changed, just retain the existing expression.
10119 if (!getDerived().AlwaysRebuild() &&
10120 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010121 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010122
John McCallb7bd14f2010-12-02 01:19:52 +000010123 if (E->isExplicitProperty())
10124 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10125 E->getExplicitProperty(),
10126 E->getLocation());
10127
10128 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010129 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010130 E->getImplicitPropertyGetter(),
10131 E->getImplicitPropertySetter(),
10132 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010133}
10134
Mike Stump11289f42009-09-09 15:08:12 +000010135template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010136ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010137TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10138 // Transform the base expression.
10139 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10140 if (Base.isInvalid())
10141 return ExprError();
10142
10143 // Transform the key expression.
10144 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10145 if (Key.isInvalid())
10146 return ExprError();
10147
10148 // If nothing changed, just retain the existing expression.
10149 if (!getDerived().AlwaysRebuild() &&
10150 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010151 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010152
Chad Rosier1dcde962012-08-08 18:46:20 +000010153 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010154 Base.get(), Key.get(),
10155 E->getAtIndexMethodDecl(),
10156 E->setAtIndexMethodDecl());
10157}
10158
10159template<typename Derived>
10160ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010161TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010162 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010163 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010164 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010165 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010166
Douglas Gregord51d90d2010-04-26 20:11:03 +000010167 // If nothing changed, just retain the existing expression.
10168 if (!getDerived().AlwaysRebuild() &&
10169 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010170 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010171
John McCallb268a282010-08-23 23:25:46 +000010172 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010173 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010174 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010175}
10176
Mike Stump11289f42009-09-09 15:08:12 +000010177template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010178ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010179TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010180 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010181 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010182 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010183 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010184 SubExprs, &ArgumentChanged))
10185 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010186
Douglas Gregora16548e2009-08-11 05:31:07 +000010187 if (!getDerived().AlwaysRebuild() &&
10188 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010189 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010190
Douglas Gregora16548e2009-08-11 05:31:07 +000010191 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010192 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010193 E->getRParenLoc());
10194}
10195
Mike Stump11289f42009-09-09 15:08:12 +000010196template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010197ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010198TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10199 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10200 if (SrcExpr.isInvalid())
10201 return ExprError();
10202
10203 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10204 if (!Type)
10205 return ExprError();
10206
10207 if (!getDerived().AlwaysRebuild() &&
10208 Type == E->getTypeSourceInfo() &&
10209 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010210 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010211
10212 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10213 SrcExpr.get(), Type,
10214 E->getRParenLoc());
10215}
10216
10217template<typename Derived>
10218ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010219TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010220 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010221
Craig Topperc3ec1492014-05-26 06:22:03 +000010222 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010223 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10224
10225 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010226 blockScope->TheDecl->setBlockMissingReturnType(
10227 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010228
Chris Lattner01cf8db2011-07-20 06:58:45 +000010229 SmallVector<ParmVarDecl*, 4> params;
10230 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010231
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010232 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010233 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
10234 oldBlock->param_begin(),
10235 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010236 nullptr, paramTypes, &params)) {
10237 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010238 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010239 }
John McCall490112f2011-02-04 18:33:18 +000010240
Jordan Rosea0a86be2013-03-08 22:25:36 +000010241 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000010242 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000010243 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000010244
Jordan Rose5c382722013-03-08 21:51:21 +000010245 QualType functionType =
10246 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010247 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000010248 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000010249
10250 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000010251 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000010252 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000010253
10254 if (!oldBlock->blockMissingReturnType()) {
10255 blockScope->HasImplicitReturnType = false;
10256 blockScope->ReturnType = exprResultType;
10257 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010258
John McCall3882ace2011-01-05 12:14:39 +000010259 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000010260 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010261 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010262 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000010263 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010264 }
John McCall3882ace2011-01-05 12:14:39 +000010265
John McCall490112f2011-02-04 18:33:18 +000010266#ifndef NDEBUG
10267 // In builds with assertions, make sure that we captured everything we
10268 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010269 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010270 for (const auto &I : oldBlock->captures()) {
10271 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010272
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010273 // Ignore parameter packs.
10274 if (isa<ParmVarDecl>(oldCapture) &&
10275 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10276 continue;
John McCall490112f2011-02-04 18:33:18 +000010277
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010278 VarDecl *newCapture =
10279 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10280 oldCapture));
10281 assert(blockScope->CaptureMap.count(newCapture));
10282 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010283 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010284 }
10285#endif
10286
10287 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010288 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010289}
10290
Mike Stump11289f42009-09-09 15:08:12 +000010291template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010292ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010293TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010294 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010295}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010296
10297template<typename Derived>
10298ExprResult
10299TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010300 QualType RetTy = getDerived().TransformType(E->getType());
10301 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010302 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010303 SubExprs.reserve(E->getNumSubExprs());
10304 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10305 SubExprs, &ArgumentChanged))
10306 return ExprError();
10307
10308 if (!getDerived().AlwaysRebuild() &&
10309 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010310 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010311
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010312 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010313 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010314}
Chad Rosier1dcde962012-08-08 18:46:20 +000010315
Douglas Gregora16548e2009-08-11 05:31:07 +000010316//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010317// Type reconstruction
10318//===----------------------------------------------------------------------===//
10319
Mike Stump11289f42009-09-09 15:08:12 +000010320template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010321QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10322 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010323 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010324 getDerived().getBaseEntity());
10325}
10326
Mike Stump11289f42009-09-09 15:08:12 +000010327template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010328QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10329 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010330 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010331 getDerived().getBaseEntity());
10332}
10333
Mike Stump11289f42009-09-09 15:08:12 +000010334template<typename Derived>
10335QualType
John McCall70dd5f62009-10-30 00:06:24 +000010336TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10337 bool WrittenAsLValue,
10338 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010339 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010340 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010341}
10342
10343template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010344QualType
John McCall70dd5f62009-10-30 00:06:24 +000010345TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10346 QualType ClassType,
10347 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010348 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10349 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010350}
10351
10352template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010353QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010354TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10355 ArrayType::ArraySizeModifier SizeMod,
10356 const llvm::APInt *Size,
10357 Expr *SizeExpr,
10358 unsigned IndexTypeQuals,
10359 SourceRange BracketsRange) {
10360 if (SizeExpr || !Size)
10361 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10362 IndexTypeQuals, BracketsRange,
10363 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010364
10365 QualType Types[] = {
10366 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10367 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10368 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010369 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010370 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010371 QualType SizeType;
10372 for (unsigned I = 0; I != NumTypes; ++I)
10373 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10374 SizeType = Types[I];
10375 break;
10376 }
Mike Stump11289f42009-09-09 15:08:12 +000010377
Eli Friedman9562f392012-01-25 23:20:27 +000010378 // Note that we can return a VariableArrayType here in the case where
10379 // the element type was a dependent VariableArrayType.
10380 IntegerLiteral *ArraySize
10381 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10382 /*FIXME*/BracketsRange.getBegin());
10383 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010384 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010385 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010386}
Mike Stump11289f42009-09-09 15:08:12 +000010387
Douglas Gregord6ff3322009-08-04 16:50:30 +000010388template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010389QualType
10390TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010391 ArrayType::ArraySizeModifier SizeMod,
10392 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010393 unsigned IndexTypeQuals,
10394 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010395 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010396 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010397}
10398
10399template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010400QualType
Mike Stump11289f42009-09-09 15:08:12 +000010401TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010402 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010403 unsigned IndexTypeQuals,
10404 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010405 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010406 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010407}
Mike Stump11289f42009-09-09 15:08:12 +000010408
Douglas Gregord6ff3322009-08-04 16:50:30 +000010409template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010410QualType
10411TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010412 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010413 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010414 unsigned IndexTypeQuals,
10415 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010416 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010417 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010418 IndexTypeQuals, BracketsRange);
10419}
10420
10421template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010422QualType
10423TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010424 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010425 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010426 unsigned IndexTypeQuals,
10427 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010428 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010429 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010430 IndexTypeQuals, BracketsRange);
10431}
10432
10433template<typename Derived>
10434QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010435 unsigned NumElements,
10436 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010437 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010438 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010439}
Mike Stump11289f42009-09-09 15:08:12 +000010440
Douglas Gregord6ff3322009-08-04 16:50:30 +000010441template<typename Derived>
10442QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10443 unsigned NumElements,
10444 SourceLocation AttributeLoc) {
10445 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10446 NumElements, true);
10447 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010448 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10449 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010450 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010451}
Mike Stump11289f42009-09-09 15:08:12 +000010452
Douglas Gregord6ff3322009-08-04 16:50:30 +000010453template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010454QualType
10455TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010456 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010457 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010458 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010459}
Mike Stump11289f42009-09-09 15:08:12 +000010460
Douglas Gregord6ff3322009-08-04 16:50:30 +000010461template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010462QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10463 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010464 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010465 const FunctionProtoType::ExtProtoInfo &EPI) {
10466 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010467 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010468 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010469 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010470}
Mike Stump11289f42009-09-09 15:08:12 +000010471
Douglas Gregord6ff3322009-08-04 16:50:30 +000010472template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010473QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10474 return SemaRef.Context.getFunctionNoProtoType(T);
10475}
10476
10477template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010478QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10479 assert(D && "no decl found");
10480 if (D->isInvalidDecl()) return QualType();
10481
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010482 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010483 TypeDecl *Ty;
10484 if (isa<UsingDecl>(D)) {
10485 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010486 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010487 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10488
10489 // A valid resolved using typename decl points to exactly one type decl.
10490 assert(++Using->shadow_begin() == Using->shadow_end());
10491 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010492
John McCallb96ec562009-12-04 22:46:56 +000010493 } else {
10494 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10495 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10496 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10497 }
10498
10499 return SemaRef.Context.getTypeDeclType(Ty);
10500}
10501
10502template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010503QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10504 SourceLocation Loc) {
10505 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010506}
10507
10508template<typename Derived>
10509QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10510 return SemaRef.Context.getTypeOfType(Underlying);
10511}
10512
10513template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010514QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10515 SourceLocation Loc) {
10516 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010517}
10518
10519template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010520QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10521 UnaryTransformType::UTTKind UKind,
10522 SourceLocation Loc) {
10523 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10524}
10525
10526template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010527QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010528 TemplateName Template,
10529 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010530 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010531 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010532}
Mike Stump11289f42009-09-09 15:08:12 +000010533
Douglas Gregor1135c352009-08-06 05:28:30 +000010534template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010535QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10536 SourceLocation KWLoc) {
10537 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10538}
10539
10540template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010541TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010542TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010543 bool TemplateKW,
10544 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010545 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010546 Template);
10547}
10548
10549template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010550TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010551TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10552 const IdentifierInfo &Name,
10553 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010554 QualType ObjectType,
10555 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010556 UnqualifiedId TemplateName;
10557 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010558 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010559 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010560 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010561 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010562 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010563 /*EnteringContext=*/false,
10564 Template);
John McCall31f82722010-11-12 08:19:04 +000010565 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010566}
Mike Stump11289f42009-09-09 15:08:12 +000010567
Douglas Gregora16548e2009-08-11 05:31:07 +000010568template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010569TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010570TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010571 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010572 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010573 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010574 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010575 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010576 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010577 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010578 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010579 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010580 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010581 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010582 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010583 /*EnteringContext=*/false,
10584 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010585 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010586}
Chad Rosier1dcde962012-08-08 18:46:20 +000010587
Douglas Gregor71395fa2009-11-04 00:56:37 +000010588template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010589ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010590TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10591 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010592 Expr *OrigCallee,
10593 Expr *First,
10594 Expr *Second) {
10595 Expr *Callee = OrigCallee->IgnoreParenCasts();
10596 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010597
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010598 if (First->getObjectKind() == OK_ObjCProperty) {
10599 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10600 if (BinaryOperator::isAssignmentOp(Opc))
10601 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10602 First, Second);
10603 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10604 if (Result.isInvalid())
10605 return ExprError();
10606 First = Result.get();
10607 }
10608
10609 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10610 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10611 if (Result.isInvalid())
10612 return ExprError();
10613 Second = Result.get();
10614 }
10615
Douglas Gregora16548e2009-08-11 05:31:07 +000010616 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010617 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010618 if (!First->getType()->isOverloadableType() &&
10619 !Second->getType()->isOverloadableType())
10620 return getSema().CreateBuiltinArraySubscriptExpr(First,
10621 Callee->getLocStart(),
10622 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010623 } else if (Op == OO_Arrow) {
10624 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010625 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10626 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010627 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010628 // The argument is not of overloadable type, so try to create a
10629 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010630 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010631 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010632
John McCallb268a282010-08-23 23:25:46 +000010633 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010634 }
10635 } else {
John McCallb268a282010-08-23 23:25:46 +000010636 if (!First->getType()->isOverloadableType() &&
10637 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010638 // Neither of the arguments is an overloadable type, so try to
10639 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010640 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010641 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010642 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010643 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010644 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010645
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010646 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010647 }
10648 }
Mike Stump11289f42009-09-09 15:08:12 +000010649
10650 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010651 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010652 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010653
John McCallb268a282010-08-23 23:25:46 +000010654 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010655 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010656 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010657 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010658 // If we've resolved this to a particular non-member function, just call
10659 // that function. If we resolved it to a member function,
10660 // CreateOverloaded* will find that function for us.
10661 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10662 if (!isa<CXXMethodDecl>(ND))
10663 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000010664 }
Mike Stump11289f42009-09-09 15:08:12 +000010665
Douglas Gregora16548e2009-08-11 05:31:07 +000010666 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000010667 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000010668 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000010669
Douglas Gregora16548e2009-08-11 05:31:07 +000010670 // Create the overloaded operator invocation for unary operators.
10671 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000010672 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010673 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000010674 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010675 }
Mike Stump11289f42009-09-09 15:08:12 +000010676
Douglas Gregore9d62932011-07-15 16:25:15 +000010677 if (Op == OO_Subscript) {
10678 SourceLocation LBrace;
10679 SourceLocation RBrace;
10680
10681 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000010682 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000010683 LBrace = SourceLocation::getFromRawEncoding(
10684 NameLoc.CXXOperatorName.BeginOpNameLoc);
10685 RBrace = SourceLocation::getFromRawEncoding(
10686 NameLoc.CXXOperatorName.EndOpNameLoc);
10687 } else {
10688 LBrace = Callee->getLocStart();
10689 RBrace = OpLoc;
10690 }
10691
10692 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10693 First, Second);
10694 }
Sebastian Redladba46e2009-10-29 20:17:01 +000010695
Douglas Gregora16548e2009-08-11 05:31:07 +000010696 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000010697 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010698 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000010699 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10700 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010701 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010702
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010703 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010704}
Mike Stump11289f42009-09-09 15:08:12 +000010705
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010706template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010707ExprResult
John McCallb268a282010-08-23 23:25:46 +000010708TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010709 SourceLocation OperatorLoc,
10710 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010711 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010712 TypeSourceInfo *ScopeType,
10713 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010714 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010715 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010716 QualType BaseType = Base->getType();
10717 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010718 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010719 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010720 !BaseType->getAs<PointerType>()->getPointeeType()
10721 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010722 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +000010723 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010724 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010725 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010726 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010727 /*FIXME?*/true);
10728 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010729
Douglas Gregor678f90d2010-02-25 01:56:36 +000010730 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010731 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10732 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10733 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10734 NameInfo.setNamedTypeInfo(DestroyedType);
10735
Richard Smith8e4a3862012-05-15 06:15:11 +000010736 // The scope type is now known to be a valid nested name specifier
10737 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000010738 if (ScopeType) {
10739 if (!ScopeType->getType()->getAs<TagType>()) {
10740 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
10741 diag::err_expected_class_or_namespace)
10742 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
10743 return ExprError();
10744 }
10745 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
10746 CCLoc);
10747 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010748
Abramo Bagnara7945c982012-01-27 09:46:47 +000010749 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010750 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010751 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010752 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010753 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010754 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010755 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010756}
10757
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010758template<typename Derived>
10759StmtResult
10760TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010761 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010762 CapturedDecl *CD = S->getCapturedDecl();
10763 unsigned NumParams = CD->getNumParams();
10764 unsigned ContextParamPos = CD->getContextParamPosition();
10765 SmallVector<Sema::CapturedParamNameType, 4> Params;
10766 for (unsigned I = 0; I < NumParams; ++I) {
10767 if (I != ContextParamPos) {
10768 Params.push_back(
10769 std::make_pair(
10770 CD->getParam(I)->getName(),
10771 getDerived().TransformType(CD->getParam(I)->getType())));
10772 } else {
10773 Params.push_back(std::make_pair(StringRef(), QualType()));
10774 }
10775 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010776 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010777 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010778 StmtResult Body;
10779 {
10780 Sema::CompoundScopeRAII CompoundScope(getSema());
10781 Body = getDerived().TransformStmt(S->getCapturedStmt());
10782 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010783
10784 if (Body.isInvalid()) {
10785 getSema().ActOnCapturedRegionError();
10786 return StmtError();
10787 }
10788
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010789 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010790}
10791
Douglas Gregord6ff3322009-08-04 16:50:30 +000010792} // end namespace clang
10793
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000010794#endif