blob: 9ddb6d842f42820668d23b7273a3658a14d7d158 [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
Douglas Gregor3024f072012-04-16 07:05:22 +0000566 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
567 FunctionProtoTypeLoc TL,
568 CXXRecordDecl *ThisContext,
NAKAMURA Takumi23224152014-10-17 12:48:37 +0000569 unsigned ThisTypeQuals);
Douglas Gregor3024f072012-04-16 07:05:22 +0000570
David Majnemerfad8f482013-10-15 09:33:02 +0000571 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000572
Chad Rosier1dcde962012-08-08 18:46:20 +0000573 QualType
John McCall31f82722010-11-12 08:19:04 +0000574 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
575 TemplateSpecializationTypeLoc TL,
576 TemplateName Template);
577
Chad Rosier1dcde962012-08-08 18:46:20 +0000578 QualType
John McCall31f82722010-11-12 08:19:04 +0000579 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
580 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000581 TemplateName Template,
582 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000583
Nico Weberc153d242014-07-28 00:02:09 +0000584 QualType TransformDependentTemplateSpecializationType(
585 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
586 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000587
John McCall58f10c32010-03-11 09:03:00 +0000588 /// \brief Transforms the parameters of a function type into the
589 /// given vectors.
590 ///
591 /// The result vectors should be kept in sync; null entries in the
592 /// variables vector are acceptable.
593 ///
594 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000595 bool TransformFunctionTypeParams(SourceLocation Loc,
596 ParmVarDecl **Params, unsigned NumParams,
597 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000598 SmallVectorImpl<QualType> &PTypes,
599 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000600
601 /// \brief Transforms a single function-type parameter. Return null
602 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000603 ///
604 /// \param indexAdjustment - A number to add to the parameter's
605 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000606 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000607 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000608 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000609 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000610
John McCall31f82722010-11-12 08:19:04 +0000611 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000612
John McCalldadc5752010-08-24 06:29:42 +0000613 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
614 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000615
616 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000617 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000618 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
619 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000620
Faisal Vali2cba1332013-10-23 06:44:28 +0000621 TemplateParameterList *TransformTemplateParameterList(
622 TemplateParameterList *TPL) {
623 return TPL;
624 }
625
Richard Smithdb2630f2012-10-21 03:28:35 +0000626 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000627
Richard Smithdb2630f2012-10-21 03:28:35 +0000628 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000629 bool IsAddressOfOperand,
630 TypeSourceInfo **RecoveryTSI);
631
632 ExprResult TransformParenDependentScopeDeclRefExpr(
633 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
634 TypeSourceInfo **RecoveryTSI);
635
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000636 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000637
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000638// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
639// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000640#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000641 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000642 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000643#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000644 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000645 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000646#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000647#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000648
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000649#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000650 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000651 OMPClause *Transform ## Class(Class *S);
652#include "clang/Basic/OpenMPKinds.def"
653
Douglas Gregord6ff3322009-08-04 16:50:30 +0000654 /// \brief Build a new pointer type given its pointee type.
655 ///
656 /// By default, performs semantic analysis when building the pointer type.
657 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000658 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659
660 /// \brief Build a new block pointer type given its pointee type.
661 ///
Mike Stump11289f42009-09-09 15:08:12 +0000662 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000663 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000664 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000665
John McCall70dd5f62009-10-30 00:06:24 +0000666 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667 ///
John McCall70dd5f62009-10-30 00:06:24 +0000668 /// By default, performs semantic analysis when building the
669 /// reference type. Subclasses may override this routine to provide
670 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000671 ///
John McCall70dd5f62009-10-30 00:06:24 +0000672 /// \param LValue whether the type was written with an lvalue sigil
673 /// or an rvalue sigil.
674 QualType RebuildReferenceType(QualType ReferentType,
675 bool LValue,
676 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000677
Douglas Gregord6ff3322009-08-04 16:50:30 +0000678 /// \brief Build a new member pointer type given the pointee type and the
679 /// class type it refers into.
680 ///
681 /// By default, performs semantic analysis when building the member pointer
682 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000683 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
684 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000685
Douglas Gregord6ff3322009-08-04 16:50:30 +0000686 /// \brief Build a new array type given the element type, size
687 /// modifier, size of the array (if known), size expression, and index type
688 /// qualifiers.
689 ///
690 /// By default, performs semantic analysis when building the array type.
691 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000692 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000693 QualType RebuildArrayType(QualType ElementType,
694 ArrayType::ArraySizeModifier SizeMod,
695 const llvm::APInt *Size,
696 Expr *SizeExpr,
697 unsigned IndexTypeQuals,
698 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000699
Douglas Gregord6ff3322009-08-04 16:50:30 +0000700 /// \brief Build a new constant array type given the element type, size
701 /// modifier, (known) size of the array, and index type qualifiers.
702 ///
703 /// By default, performs semantic analysis when building the array type.
704 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000705 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000706 ArrayType::ArraySizeModifier SizeMod,
707 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000708 unsigned IndexTypeQuals,
709 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000710
Douglas Gregord6ff3322009-08-04 16:50:30 +0000711 /// \brief Build a new incomplete array type given the element type, size
712 /// modifier, and index type qualifiers.
713 ///
714 /// By default, performs semantic analysis when building the array type.
715 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000716 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000717 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000718 unsigned IndexTypeQuals,
719 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000720
Mike Stump11289f42009-09-09 15:08:12 +0000721 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000722 /// size modifier, size expression, and index type qualifiers.
723 ///
724 /// By default, performs semantic analysis when building the array type.
725 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000726 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000727 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000728 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000729 unsigned IndexTypeQuals,
730 SourceRange BracketsRange);
731
Mike Stump11289f42009-09-09 15:08:12 +0000732 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000733 /// size modifier, size expression, and index type qualifiers.
734 ///
735 /// By default, performs semantic analysis when building the array type.
736 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000737 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000738 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000739 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 unsigned IndexTypeQuals,
741 SourceRange BracketsRange);
742
743 /// \brief Build a new vector type given the element type and
744 /// number of elements.
745 ///
746 /// By default, performs semantic analysis when building the vector type.
747 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000748 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000749 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000750
Douglas Gregord6ff3322009-08-04 16:50:30 +0000751 /// \brief Build a new extended vector type given the element type and
752 /// number of elements.
753 ///
754 /// By default, performs semantic analysis when building the vector type.
755 /// Subclasses may override this routine to provide different behavior.
756 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
757 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000758
759 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000760 /// given the element type and number of elements.
761 ///
762 /// By default, performs semantic analysis when building the vector type.
763 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000764 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000765 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000766 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000767
Douglas Gregord6ff3322009-08-04 16:50:30 +0000768 /// \brief Build a new function type.
769 ///
770 /// By default, performs semantic analysis when building the function type.
771 /// Subclasses may override this routine to provide different behavior.
772 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000773 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000774 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000775
John McCall550e0c22009-10-21 00:40:46 +0000776 /// \brief Build a new unprototyped function type.
777 QualType RebuildFunctionNoProtoType(QualType ResultType);
778
John McCallb96ec562009-12-04 22:46:56 +0000779 /// \brief Rebuild an unresolved typename type, given the decl that
780 /// the UnresolvedUsingTypenameDecl was transformed to.
781 QualType RebuildUnresolvedUsingType(Decl *D);
782
Douglas Gregord6ff3322009-08-04 16:50:30 +0000783 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000784 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000785 return SemaRef.Context.getTypeDeclType(Typedef);
786 }
787
788 /// \brief Build a new class/struct/union type.
789 QualType RebuildRecordType(RecordDecl *Record) {
790 return SemaRef.Context.getTypeDeclType(Record);
791 }
792
793 /// \brief Build a new Enum type.
794 QualType RebuildEnumType(EnumDecl *Enum) {
795 return SemaRef.Context.getTypeDeclType(Enum);
796 }
John McCallfcc33b02009-09-05 00:15:47 +0000797
Mike Stump11289f42009-09-09 15:08:12 +0000798 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000799 ///
800 /// By default, performs semantic analysis when building the typeof type.
801 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000802 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000803
Mike Stump11289f42009-09-09 15:08:12 +0000804 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000805 ///
806 /// By default, builds a new TypeOfType with the given underlying type.
807 QualType RebuildTypeOfType(QualType Underlying);
808
Alexis Hunte852b102011-05-24 22:41:36 +0000809 /// \brief Build a new unary transform type.
810 QualType RebuildUnaryTransformType(QualType BaseType,
811 UnaryTransformType::UTTKind UKind,
812 SourceLocation Loc);
813
Richard Smith74aeef52013-04-26 16:15:35 +0000814 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000815 ///
816 /// By default, performs semantic analysis when building the decltype type.
817 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000818 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000819
Richard Smith74aeef52013-04-26 16:15:35 +0000820 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000821 ///
822 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000823 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000824 // Note, IsDependent is always false here: we implicitly convert an 'auto'
825 // which has been deduced to a dependent type into an undeduced 'auto', so
826 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000827 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
828 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000829 }
830
Douglas Gregord6ff3322009-08-04 16:50:30 +0000831 /// \brief Build a new template specialization type.
832 ///
833 /// By default, performs semantic analysis when building the template
834 /// specialization type. Subclasses may override this routine to provide
835 /// different behavior.
836 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000837 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000838 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000839
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000840 /// \brief Build a new parenthesized type.
841 ///
842 /// By default, builds a new ParenType type from the inner type.
843 /// Subclasses may override this routine to provide different behavior.
844 QualType RebuildParenType(QualType InnerType) {
845 return SemaRef.Context.getParenType(InnerType);
846 }
847
Douglas Gregord6ff3322009-08-04 16:50:30 +0000848 /// \brief Build a new qualified name type.
849 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000850 /// By default, builds a new ElaboratedType type from the keyword,
851 /// the nested-name-specifier and the named type.
852 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000853 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
854 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000855 NestedNameSpecifierLoc QualifierLoc,
856 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000857 return SemaRef.Context.getElaboratedType(Keyword,
858 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000859 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000860 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000861
862 /// \brief Build a new typename type that refers to a template-id.
863 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000864 /// By default, builds a new DependentNameType type from the
865 /// nested-name-specifier and the given type. Subclasses may override
866 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000867 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000868 ElaboratedTypeKeyword Keyword,
869 NestedNameSpecifierLoc QualifierLoc,
870 const IdentifierInfo *Name,
871 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000872 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000873 // Rebuild the template name.
874 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000875 CXXScopeSpec SS;
876 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000877 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000878 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
879 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000880
Douglas Gregora7a795b2011-03-01 20:11:18 +0000881 if (InstName.isNull())
882 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000883
Douglas Gregora7a795b2011-03-01 20:11:18 +0000884 // If it's still dependent, make a dependent specialization.
885 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000886 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
887 QualifierLoc.getNestedNameSpecifier(),
888 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000889 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000890
Douglas Gregora7a795b2011-03-01 20:11:18 +0000891 // Otherwise, make an elaborated type wrapping a non-dependent
892 // specialization.
893 QualType T =
894 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
895 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000896
Craig Topperc3ec1492014-05-26 06:22:03 +0000897 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000898 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000899
900 return SemaRef.Context.getElaboratedType(Keyword,
901 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000902 T);
903 }
904
Douglas Gregord6ff3322009-08-04 16:50:30 +0000905 /// \brief Build a new typename type that refers to an identifier.
906 ///
907 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000908 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000909 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000910 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000911 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000912 NestedNameSpecifierLoc QualifierLoc,
913 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000914 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000915 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000916 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000917
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000918 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000919 // If the name is still dependent, just build a new dependent name type.
920 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000921 return SemaRef.Context.getDependentNameType(Keyword,
922 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000923 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000924 }
925
Abramo Bagnara6150c882010-05-11 21:36:43 +0000926 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000927 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000928 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000929
930 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
931
Abramo Bagnarad7548482010-05-19 21:37:53 +0000932 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000933 // into a non-dependent elaborated-type-specifier. Find the tag we're
934 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000935 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000936 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
937 if (!DC)
938 return QualType();
939
John McCallbf8c5192010-05-27 06:40:31 +0000940 if (SemaRef.RequireCompleteDeclContext(SS, DC))
941 return QualType();
942
Craig Topperc3ec1492014-05-26 06:22:03 +0000943 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000944 SemaRef.LookupQualifiedName(Result, DC);
945 switch (Result.getResultKind()) {
946 case LookupResult::NotFound:
947 case LookupResult::NotFoundInCurrentInstantiation:
948 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000949
Douglas Gregore677daf2010-03-31 22:19:08 +0000950 case LookupResult::Found:
951 Tag = Result.getAsSingle<TagDecl>();
952 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000953
Douglas Gregore677daf2010-03-31 22:19:08 +0000954 case LookupResult::FoundOverloaded:
955 case LookupResult::FoundUnresolvedValue:
956 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000957
Douglas Gregore677daf2010-03-31 22:19:08 +0000958 case LookupResult::Ambiguous:
959 // Let the LookupResult structure handle ambiguities.
960 return QualType();
961 }
962
963 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000964 // Check where the name exists but isn't a tag type and use that to emit
965 // better diagnostics.
966 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
967 SemaRef.LookupQualifiedName(Result, DC);
968 switch (Result.getResultKind()) {
969 case LookupResult::Found:
970 case LookupResult::FoundOverloaded:
971 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000972 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000973 unsigned Kind = 0;
974 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000975 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
976 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000977 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
978 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
979 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000980 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000981 default:
Nick Lewycky0c438082011-01-24 19:01:04 +0000982 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000983 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000984 break;
985 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000986 return QualType();
987 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000988
Richard Trieucaa33d32011-06-10 03:11:26 +0000989 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
990 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000991 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000992 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
993 return QualType();
994 }
995
996 // Build the elaborated-type-specifier type.
997 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000998 return SemaRef.Context.getElaboratedType(Keyword,
999 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001000 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001001 }
Mike Stump11289f42009-09-09 15:08:12 +00001002
Douglas Gregor822d0302011-01-12 17:07:58 +00001003 /// \brief Build a new pack expansion type.
1004 ///
1005 /// By default, builds a new PackExpansionType type from the given pattern.
1006 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001007 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001008 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001009 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001010 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001011 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1012 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001013 }
1014
Eli Friedman0dfb8892011-10-06 23:00:33 +00001015 /// \brief Build a new atomic type given its value type.
1016 ///
1017 /// By default, performs semantic analysis when building the atomic type.
1018 /// Subclasses may override this routine to provide different behavior.
1019 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1020
Douglas Gregor71dc5092009-08-06 06:41:21 +00001021 /// \brief Build a new template name given a nested name specifier, a flag
1022 /// indicating whether the "template" keyword was provided, and the template
1023 /// that the template name refers to.
1024 ///
1025 /// By default, builds the new template name directly. Subclasses may override
1026 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001027 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001028 bool TemplateKW,
1029 TemplateDecl *Template);
1030
Douglas Gregor71dc5092009-08-06 06:41:21 +00001031 /// \brief Build a new template name given a nested name specifier and the
1032 /// name that is referred to as a template.
1033 ///
1034 /// By default, performs semantic analysis to determine whether the name can
1035 /// be resolved to a specific template, then builds the appropriate kind of
1036 /// template name. Subclasses may override this routine to provide different
1037 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001038 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1039 const IdentifierInfo &Name,
1040 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001041 QualType ObjectType,
1042 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001043
Douglas Gregor71395fa2009-11-04 00:56:37 +00001044 /// \brief Build a new template name given a nested name specifier and the
1045 /// overloaded operator name that is referred to as a template.
1046 ///
1047 /// By default, performs semantic analysis to determine whether the name can
1048 /// be resolved to a specific template, then builds the appropriate kind of
1049 /// template name. Subclasses may override this routine to provide different
1050 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001051 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001052 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001053 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001054 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001055
1056 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001057 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001058 ///
1059 /// By default, performs semantic analysis to determine whether the name can
1060 /// be resolved to a specific template, then builds the appropriate kind of
1061 /// template name. Subclasses may override this routine to provide different
1062 /// behavior.
1063 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1064 const TemplateArgument &ArgPack) {
1065 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1066 }
1067
Douglas Gregorebe10102009-08-20 07:17:43 +00001068 /// \brief Build a new compound statement.
1069 ///
1070 /// By default, performs semantic analysis to build the new statement.
1071 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001072 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001073 MultiStmtArg Statements,
1074 SourceLocation RBraceLoc,
1075 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001076 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001077 IsStmtExpr);
1078 }
1079
1080 /// \brief Build a new case statement.
1081 ///
1082 /// By default, performs semantic analysis to build the new statement.
1083 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001084 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001085 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001086 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001087 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001088 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001089 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001090 ColonLoc);
1091 }
Mike Stump11289f42009-09-09 15:08:12 +00001092
Douglas Gregorebe10102009-08-20 07:17:43 +00001093 /// \brief Attach the body to a new case statement.
1094 ///
1095 /// By default, performs semantic analysis to build the new statement.
1096 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001097 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001098 getSema().ActOnCaseStmtBody(S, Body);
1099 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001100 }
Mike Stump11289f42009-09-09 15:08:12 +00001101
Douglas Gregorebe10102009-08-20 07:17:43 +00001102 /// \brief Build a new default statement.
1103 ///
1104 /// By default, performs semantic analysis to build the new statement.
1105 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001106 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001107 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001108 Stmt *SubStmt) {
1109 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001110 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001111 }
Mike Stump11289f42009-09-09 15:08:12 +00001112
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 /// \brief Build a new label statement.
1114 ///
1115 /// By default, performs semantic analysis to build the new statement.
1116 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001117 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1118 SourceLocation ColonLoc, Stmt *SubStmt) {
1119 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001120 }
Mike Stump11289f42009-09-09 15:08:12 +00001121
Richard Smithc202b282012-04-14 00:33:13 +00001122 /// \brief Build a new label statement.
1123 ///
1124 /// By default, performs semantic analysis to build the new statement.
1125 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001126 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1127 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001128 Stmt *SubStmt) {
1129 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1130 }
1131
Douglas Gregorebe10102009-08-20 07:17:43 +00001132 /// \brief Build a new "if" statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001136 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001137 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001138 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001139 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001140 }
Mike Stump11289f42009-09-09 15:08:12 +00001141
Douglas Gregorebe10102009-08-20 07:17:43 +00001142 /// \brief Start building a new switch statement.
1143 ///
1144 /// By default, performs semantic analysis to build the new statement.
1145 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001146 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001147 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001148 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001149 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001150 }
Mike Stump11289f42009-09-09 15:08:12 +00001151
Douglas Gregorebe10102009-08-20 07:17:43 +00001152 /// \brief Attach the body to the switch statement.
1153 ///
1154 /// By default, performs semantic analysis to build the new statement.
1155 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001156 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001157 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001158 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001159 }
1160
1161 /// \brief Build a new while statement.
1162 ///
1163 /// By default, performs semantic analysis to build the new statement.
1164 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001165 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1166 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001167 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001168 }
Mike Stump11289f42009-09-09 15:08:12 +00001169
Douglas Gregorebe10102009-08-20 07:17:43 +00001170 /// \brief Build a new do-while statement.
1171 ///
1172 /// By default, performs semantic analysis to build the new statement.
1173 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001174 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001175 SourceLocation WhileLoc, SourceLocation LParenLoc,
1176 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001177 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1178 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001179 }
1180
1181 /// \brief Build a new for statement.
1182 ///
1183 /// By default, performs semantic analysis to build the new statement.
1184 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001185 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001186 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001187 VarDecl *CondVar, Sema::FullExprArg Inc,
1188 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001189 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001190 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001191 }
Mike Stump11289f42009-09-09 15:08:12 +00001192
Douglas Gregorebe10102009-08-20 07:17:43 +00001193 /// \brief Build a new goto statement.
1194 ///
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001197 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1198 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001199 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001200 }
1201
1202 /// \brief Build a new indirect goto statement.
1203 ///
1204 /// By default, performs semantic analysis to build the new statement.
1205 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001206 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001207 SourceLocation StarLoc,
1208 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001209 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001210 }
Mike Stump11289f42009-09-09 15:08:12 +00001211
Douglas Gregorebe10102009-08-20 07:17:43 +00001212 /// \brief Build a new return statement.
1213 ///
1214 /// By default, performs semantic analysis to build the new statement.
1215 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001216 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001217 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001218 }
Mike Stump11289f42009-09-09 15:08:12 +00001219
Douglas Gregorebe10102009-08-20 07:17:43 +00001220 /// \brief Build a new declaration statement.
1221 ///
1222 /// By default, performs semantic analysis to build the new statement.
1223 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001224 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001225 SourceLocation StartLoc, SourceLocation EndLoc) {
1226 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001227 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001228 }
Mike Stump11289f42009-09-09 15:08:12 +00001229
Anders Carlssonaaeef072010-01-24 05:50:09 +00001230 /// \brief Build a new inline asm statement.
1231 ///
1232 /// By default, performs semantic analysis to build the new statement.
1233 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001234 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1235 bool IsVolatile, unsigned NumOutputs,
1236 unsigned NumInputs, IdentifierInfo **Names,
1237 MultiExprArg Constraints, MultiExprArg Exprs,
1238 Expr *AsmString, MultiExprArg Clobbers,
1239 SourceLocation RParenLoc) {
1240 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1241 NumInputs, Names, Constraints, Exprs,
1242 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001243 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001244
Chad Rosier32503022012-06-11 20:47:18 +00001245 /// \brief Build a new MS style inline asm statement.
1246 ///
1247 /// By default, performs semantic analysis to build the new statement.
1248 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001249 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001250 ArrayRef<Token> AsmToks,
1251 StringRef AsmString,
1252 unsigned NumOutputs, unsigned NumInputs,
1253 ArrayRef<StringRef> Constraints,
1254 ArrayRef<StringRef> Clobbers,
1255 ArrayRef<Expr*> Exprs,
1256 SourceLocation EndLoc) {
1257 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1258 NumOutputs, NumInputs,
1259 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001260 }
1261
James Dennett2a4d13c2012-06-15 07:13:21 +00001262 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001263 ///
1264 /// By default, performs semantic analysis to build the new statement.
1265 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001266 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001267 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001268 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001269 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001270 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001271 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001272 }
1273
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001274 /// \brief Rebuild an Objective-C exception declaration.
1275 ///
1276 /// By default, performs semantic analysis to build the new declaration.
1277 /// Subclasses may override this routine to provide different behavior.
1278 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1279 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001280 return getSema().BuildObjCExceptionDecl(TInfo, T,
1281 ExceptionDecl->getInnerLocStart(),
1282 ExceptionDecl->getLocation(),
1283 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001284 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001285
James Dennett2a4d13c2012-06-15 07:13:21 +00001286 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001287 ///
1288 /// By default, performs semantic analysis to build the new statement.
1289 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001290 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001291 SourceLocation RParenLoc,
1292 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001293 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001294 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001295 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001296 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001297
James Dennett2a4d13c2012-06-15 07:13:21 +00001298 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001299 ///
1300 /// By default, performs semantic analysis to build the new statement.
1301 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001302 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001303 Stmt *Body) {
1304 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001305 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001306
James Dennett2a4d13c2012-06-15 07:13:21 +00001307 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001308 ///
1309 /// By default, performs semantic analysis to build the new statement.
1310 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001311 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001312 Expr *Operand) {
1313 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001314 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001315
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001316 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001317 ///
1318 /// By default, performs semantic analysis to build the new statement.
1319 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001320 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001321 DeclarationNameInfo DirName,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001322 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001323 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001324 SourceLocation EndLoc) {
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001325 return getSema().ActOnOpenMPExecutableDirective(Kind, DirName, Clauses,
1326 AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001327 }
1328
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001329 /// \brief Build a new OpenMP 'if' clause.
1330 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001331 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001332 /// Subclasses may override this routine to provide different behavior.
1333 OMPClause *RebuildOMPIfClause(Expr *Condition,
1334 SourceLocation StartLoc,
1335 SourceLocation LParenLoc,
1336 SourceLocation EndLoc) {
1337 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1338 LParenLoc, EndLoc);
1339 }
1340
Alexey Bataev3778b602014-07-17 07:32:53 +00001341 /// \brief Build a new OpenMP 'final' clause.
1342 ///
1343 /// By default, performs semantic analysis to build the new OpenMP clause.
1344 /// Subclasses may override this routine to provide different behavior.
1345 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1346 SourceLocation LParenLoc,
1347 SourceLocation EndLoc) {
1348 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1349 EndLoc);
1350 }
1351
Alexey Bataev568a8332014-03-06 06:15:19 +00001352 /// \brief Build a new OpenMP 'num_threads' clause.
1353 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001354 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001355 /// Subclasses may override this routine to provide different behavior.
1356 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1357 SourceLocation StartLoc,
1358 SourceLocation LParenLoc,
1359 SourceLocation EndLoc) {
1360 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1361 LParenLoc, EndLoc);
1362 }
1363
Alexey Bataev62c87d22014-03-21 04:51:18 +00001364 /// \brief Build a new OpenMP 'safelen' clause.
1365 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001366 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001367 /// Subclasses may override this routine to provide different behavior.
1368 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1369 SourceLocation LParenLoc,
1370 SourceLocation EndLoc) {
1371 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1372 }
1373
Alexander Musman8bd31e62014-05-27 15:12:19 +00001374 /// \brief Build a new OpenMP 'collapse' clause.
1375 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001376 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001377 /// Subclasses may override this routine to provide different behavior.
1378 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1379 SourceLocation LParenLoc,
1380 SourceLocation EndLoc) {
1381 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1382 EndLoc);
1383 }
1384
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001385 /// \brief Build a new OpenMP 'default' clause.
1386 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001387 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001388 /// Subclasses may override this routine to provide different behavior.
1389 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1390 SourceLocation KindKwLoc,
1391 SourceLocation StartLoc,
1392 SourceLocation LParenLoc,
1393 SourceLocation EndLoc) {
1394 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1395 StartLoc, LParenLoc, EndLoc);
1396 }
1397
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001398 /// \brief Build a new OpenMP 'proc_bind' clause.
1399 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001400 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001401 /// Subclasses may override this routine to provide different behavior.
1402 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1403 SourceLocation KindKwLoc,
1404 SourceLocation StartLoc,
1405 SourceLocation LParenLoc,
1406 SourceLocation EndLoc) {
1407 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1408 StartLoc, LParenLoc, EndLoc);
1409 }
1410
Alexey Bataev56dafe82014-06-20 07:16:17 +00001411 /// \brief Build a new OpenMP 'schedule' clause.
1412 ///
1413 /// By default, performs semantic analysis to build the new OpenMP clause.
1414 /// Subclasses may override this routine to provide different behavior.
1415 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1416 Expr *ChunkSize,
1417 SourceLocation StartLoc,
1418 SourceLocation LParenLoc,
1419 SourceLocation KindLoc,
1420 SourceLocation CommaLoc,
1421 SourceLocation EndLoc) {
1422 return getSema().ActOnOpenMPScheduleClause(
1423 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1424 }
1425
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001426 /// \brief Build a new OpenMP 'private' clause.
1427 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001428 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001429 /// Subclasses may override this routine to provide different behavior.
1430 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1431 SourceLocation StartLoc,
1432 SourceLocation LParenLoc,
1433 SourceLocation EndLoc) {
1434 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1435 EndLoc);
1436 }
1437
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001438 /// \brief Build a new OpenMP 'firstprivate' clause.
1439 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001440 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001441 /// Subclasses may override this routine to provide different behavior.
1442 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1443 SourceLocation StartLoc,
1444 SourceLocation LParenLoc,
1445 SourceLocation EndLoc) {
1446 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1447 EndLoc);
1448 }
1449
Alexander Musman1bb328c2014-06-04 13:06:39 +00001450 /// \brief Build a new OpenMP 'lastprivate' clause.
1451 ///
1452 /// By default, performs semantic analysis to build the new OpenMP clause.
1453 /// Subclasses may override this routine to provide different behavior.
1454 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1455 SourceLocation StartLoc,
1456 SourceLocation LParenLoc,
1457 SourceLocation EndLoc) {
1458 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1459 EndLoc);
1460 }
1461
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001462 /// \brief Build a new OpenMP 'shared' clause.
1463 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001464 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001465 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001466 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1467 SourceLocation StartLoc,
1468 SourceLocation LParenLoc,
1469 SourceLocation EndLoc) {
1470 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1471 EndLoc);
1472 }
1473
Alexey Bataevc5e02582014-06-16 07:08:35 +00001474 /// \brief Build a new OpenMP 'reduction' clause.
1475 ///
1476 /// By default, performs semantic analysis to build the new statement.
1477 /// Subclasses may override this routine to provide different behavior.
1478 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1479 SourceLocation StartLoc,
1480 SourceLocation LParenLoc,
1481 SourceLocation ColonLoc,
1482 SourceLocation EndLoc,
1483 CXXScopeSpec &ReductionIdScopeSpec,
1484 const DeclarationNameInfo &ReductionId) {
1485 return getSema().ActOnOpenMPReductionClause(
1486 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1487 ReductionId);
1488 }
1489
Alexander Musman8dba6642014-04-22 13:09:42 +00001490 /// \brief Build a new OpenMP 'linear' clause.
1491 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001492 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001493 /// Subclasses may override this routine to provide different behavior.
1494 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1495 SourceLocation StartLoc,
1496 SourceLocation LParenLoc,
1497 SourceLocation ColonLoc,
1498 SourceLocation EndLoc) {
1499 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1500 ColonLoc, EndLoc);
1501 }
1502
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001503 /// \brief Build a new OpenMP 'aligned' clause.
1504 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001505 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001506 /// Subclasses may override this routine to provide different behavior.
1507 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1508 SourceLocation StartLoc,
1509 SourceLocation LParenLoc,
1510 SourceLocation ColonLoc,
1511 SourceLocation EndLoc) {
1512 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1513 LParenLoc, ColonLoc, EndLoc);
1514 }
1515
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001516 /// \brief Build a new OpenMP 'copyin' clause.
1517 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001518 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001519 /// Subclasses may override this routine to provide different behavior.
1520 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1521 SourceLocation StartLoc,
1522 SourceLocation LParenLoc,
1523 SourceLocation EndLoc) {
1524 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1525 EndLoc);
1526 }
1527
Alexey Bataevbae9a792014-06-27 10:37:06 +00001528 /// \brief Build a new OpenMP 'copyprivate' clause.
1529 ///
1530 /// By default, performs semantic analysis to build the new OpenMP clause.
1531 /// Subclasses may override this routine to provide different behavior.
1532 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1533 SourceLocation StartLoc,
1534 SourceLocation LParenLoc,
1535 SourceLocation EndLoc) {
1536 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1537 EndLoc);
1538 }
1539
Alexey Bataev6125da92014-07-21 11:26:11 +00001540 /// \brief Build a new OpenMP 'flush' pseudo clause.
1541 ///
1542 /// By default, performs semantic analysis to build the new OpenMP clause.
1543 /// Subclasses may override this routine to provide different behavior.
1544 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1545 SourceLocation StartLoc,
1546 SourceLocation LParenLoc,
1547 SourceLocation EndLoc) {
1548 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1549 EndLoc);
1550 }
1551
James Dennett2a4d13c2012-06-15 07:13:21 +00001552 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001553 ///
1554 /// By default, performs semantic analysis to build the new statement.
1555 /// Subclasses may override this routine to provide different behavior.
1556 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1557 Expr *object) {
1558 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1559 }
1560
James Dennett2a4d13c2012-06-15 07:13:21 +00001561 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001562 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001563 /// By default, performs semantic analysis to build the new statement.
1564 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001565 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001566 Expr *Object, Stmt *Body) {
1567 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001568 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001569
James Dennett2a4d13c2012-06-15 07:13:21 +00001570 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001571 ///
1572 /// By default, performs semantic analysis to build the new statement.
1573 /// Subclasses may override this routine to provide different behavior.
1574 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1575 Stmt *Body) {
1576 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1577 }
John McCall53848232011-07-27 01:07:15 +00001578
Douglas Gregorf68a5082010-04-22 23:10:45 +00001579 /// \brief Build a new Objective-C fast enumeration statement.
1580 ///
1581 /// By default, performs semantic analysis to build the new statement.
1582 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001583 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001584 Stmt *Element,
1585 Expr *Collection,
1586 SourceLocation RParenLoc,
1587 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001588 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001589 Element,
John McCallb268a282010-08-23 23:25:46 +00001590 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001591 RParenLoc);
1592 if (ForEachStmt.isInvalid())
1593 return StmtError();
1594
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001595 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001596 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001597
Douglas Gregorebe10102009-08-20 07:17:43 +00001598 /// \brief Build a new C++ exception declaration.
1599 ///
1600 /// By default, performs semantic analysis to build the new decaration.
1601 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001602 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001603 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001604 SourceLocation StartLoc,
1605 SourceLocation IdLoc,
1606 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001607 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001608 StartLoc, IdLoc, Id);
1609 if (Var)
1610 getSema().CurContext->addDecl(Var);
1611 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001612 }
1613
1614 /// \brief Build a new C++ catch statement.
1615 ///
1616 /// By default, performs semantic analysis to build the new statement.
1617 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001618 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001619 VarDecl *ExceptionDecl,
1620 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001621 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1622 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001623 }
Mike Stump11289f42009-09-09 15:08:12 +00001624
Douglas Gregorebe10102009-08-20 07:17:43 +00001625 /// \brief Build a new C++ try statement.
1626 ///
1627 /// By default, performs semantic analysis to build the new statement.
1628 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001629 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1630 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001631 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001632 }
Mike Stump11289f42009-09-09 15:08:12 +00001633
Richard Smith02e85f32011-04-14 22:09:26 +00001634 /// \brief Build a new C++0x range-based for statement.
1635 ///
1636 /// By default, performs semantic analysis to build the new statement.
1637 /// Subclasses may override this routine to provide different behavior.
1638 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1639 SourceLocation ColonLoc,
1640 Stmt *Range, Stmt *BeginEnd,
1641 Expr *Cond, Expr *Inc,
1642 Stmt *LoopVar,
1643 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001644 // If we've just learned that the range is actually an Objective-C
1645 // collection, treat this as an Objective-C fast enumeration loop.
1646 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1647 if (RangeStmt->isSingleDecl()) {
1648 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001649 if (RangeVar->isInvalidDecl())
1650 return StmtError();
1651
Douglas Gregorf7106af2013-04-08 18:40:13 +00001652 Expr *RangeExpr = RangeVar->getInit();
1653 if (!RangeExpr->isTypeDependent() &&
1654 RangeExpr->getType()->isObjCObjectPointerType())
1655 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1656 RParenLoc);
1657 }
1658 }
1659 }
1660
Richard Smith02e85f32011-04-14 22:09:26 +00001661 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001662 Cond, Inc, LoopVar, RParenLoc,
1663 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001664 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001665
1666 /// \brief Build a new C++0x range-based for statement.
1667 ///
1668 /// By default, performs semantic analysis to build the new statement.
1669 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001670 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001671 bool IsIfExists,
1672 NestedNameSpecifierLoc QualifierLoc,
1673 DeclarationNameInfo NameInfo,
1674 Stmt *Nested) {
1675 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1676 QualifierLoc, NameInfo, Nested);
1677 }
1678
Richard Smith02e85f32011-04-14 22:09:26 +00001679 /// \brief Attach body to a C++0x range-based for statement.
1680 ///
1681 /// By default, performs semantic analysis to finish the new statement.
1682 /// Subclasses may override this routine to provide different behavior.
1683 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1684 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1685 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001686
David Majnemerfad8f482013-10-15 09:33:02 +00001687 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001688 Stmt *TryBlock, Stmt *Handler) {
1689 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001690 }
1691
David Majnemerfad8f482013-10-15 09:33:02 +00001692 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001693 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001694 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001695 }
1696
David Majnemerfad8f482013-10-15 09:33:02 +00001697 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1698 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001699 }
1700
Alexey Bataevec474782014-10-09 08:45:04 +00001701 /// \brief Build a new predefined expression.
1702 ///
1703 /// By default, performs semantic analysis to build the new expression.
1704 /// Subclasses may override this routine to provide different behavior.
1705 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1706 PredefinedExpr::IdentType IT) {
1707 return getSema().BuildPredefinedExpr(Loc, IT);
1708 }
1709
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 /// \brief Build a new expression that references a declaration.
1711 ///
1712 /// By default, performs semantic analysis to build the new expression.
1713 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001714 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001715 LookupResult &R,
1716 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001717 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1718 }
1719
1720
1721 /// \brief Build a new expression that references a declaration.
1722 ///
1723 /// By default, performs semantic analysis to build the new expression.
1724 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001725 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001726 ValueDecl *VD,
1727 const DeclarationNameInfo &NameInfo,
1728 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001729 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001730 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001731
1732 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001733
1734 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001735 }
Mike Stump11289f42009-09-09 15:08:12 +00001736
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001738 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 /// By default, performs semantic analysis to build the new expression.
1740 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001741 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001742 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001743 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001744 }
1745
Douglas Gregorad8a3362009-09-04 17:36:40 +00001746 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001747 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001748 /// By default, performs semantic analysis to build the new expression.
1749 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001750 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001751 SourceLocation OperatorLoc,
1752 bool isArrow,
1753 CXXScopeSpec &SS,
1754 TypeSourceInfo *ScopeType,
1755 SourceLocation CCLoc,
1756 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001757 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001758
Douglas Gregora16548e2009-08-11 05:31:07 +00001759 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001760 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 /// By default, performs semantic analysis to build the new expression.
1762 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001763 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001764 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001765 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001766 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 }
Mike Stump11289f42009-09-09 15:08:12 +00001768
Douglas Gregor882211c2010-04-28 22:16:22 +00001769 /// \brief Build a new builtin offsetof expression.
1770 ///
1771 /// By default, performs semantic analysis to build the new expression.
1772 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001773 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001774 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001775 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001776 unsigned NumComponents,
1777 SourceLocation RParenLoc) {
1778 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1779 NumComponents, RParenLoc);
1780 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001781
1782 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001783 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001784 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001785 /// By default, performs semantic analysis to build the new expression.
1786 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001787 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1788 SourceLocation OpLoc,
1789 UnaryExprOrTypeTrait ExprKind,
1790 SourceRange R) {
1791 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 }
1793
Peter Collingbournee190dee2011-03-11 19:24:49 +00001794 /// \brief Build a new sizeof, alignof or vec step expression with an
1795 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001796 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001797 /// By default, performs semantic analysis to build the new expression.
1798 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001799 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1800 UnaryExprOrTypeTrait ExprKind,
1801 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001802 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001803 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001805 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001806
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001807 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001808 }
Mike Stump11289f42009-09-09 15:08:12 +00001809
Douglas Gregora16548e2009-08-11 05:31:07 +00001810 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001811 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001812 /// By default, performs semantic analysis to build the new expression.
1813 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001814 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001815 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001816 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001817 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001818 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001819 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001820 RBracketLoc);
1821 }
1822
1823 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001824 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001825 /// By default, performs semantic analysis to build the new expression.
1826 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001827 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001828 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001829 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001830 Expr *ExecConfig = nullptr) {
1831 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001832 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001833 }
1834
1835 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001836 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001837 /// By default, performs semantic analysis to build the new expression.
1838 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001839 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001840 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001841 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001842 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001843 const DeclarationNameInfo &MemberNameInfo,
1844 ValueDecl *Member,
1845 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001846 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001847 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001848 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1849 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001850 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001851 // We have a reference to an unnamed field. This is always the
1852 // base of an anonymous struct/union member access, i.e. the
1853 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001854 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001855 assert(Member->getType()->isRecordType() &&
1856 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001857
Richard Smithcab9a7d2011-10-26 19:06:56 +00001858 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001859 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001860 QualifierLoc.getNestedNameSpecifier(),
1861 FoundDecl, Member);
1862 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001863 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001864 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001865 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001866 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001867 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001868 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001869 cast<FieldDecl>(Member)->getType(),
1870 VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001871 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001872 }
Mike Stump11289f42009-09-09 15:08:12 +00001873
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001874 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001875 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001876
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001877 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001878 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001879
John McCall16df1e52010-03-30 21:47:33 +00001880 // FIXME: this involves duplicating earlier analysis in a lot of
1881 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001882 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001883 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001884 R.resolveKind();
1885
John McCallb268a282010-08-23 23:25:46 +00001886 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001887 SS, TemplateKWLoc,
1888 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001889 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001890 }
Mike Stump11289f42009-09-09 15:08:12 +00001891
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001893 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001894 /// By default, performs semantic analysis to build the new expression.
1895 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001896 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001897 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001898 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001899 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001900 }
1901
1902 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001903 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 /// By default, performs semantic analysis to build the new expression.
1905 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001906 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001907 SourceLocation QuestionLoc,
1908 Expr *LHS,
1909 SourceLocation ColonLoc,
1910 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001911 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1912 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 }
1914
Douglas Gregora16548e2009-08-11 05:31:07 +00001915 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001916 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 /// By default, performs semantic analysis to build the new expression.
1918 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001919 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001920 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001922 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001923 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001924 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001925 }
Mike Stump11289f42009-09-09 15:08:12 +00001926
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001928 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 /// By default, performs semantic analysis to build the new expression.
1930 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001931 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001932 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001933 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001934 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001935 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001936 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 }
Mike Stump11289f42009-09-09 15:08:12 +00001938
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001940 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 /// By default, performs semantic analysis to build the new expression.
1942 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001943 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 SourceLocation OpLoc,
1945 SourceLocation AccessorLoc,
1946 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001947
John McCall10eae182009-11-30 22:42:35 +00001948 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001949 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001950 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001951 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001952 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001953 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001954 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001955 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001956 }
Mike Stump11289f42009-09-09 15:08:12 +00001957
Douglas Gregora16548e2009-08-11 05:31:07 +00001958 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001959 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 /// By default, performs semantic analysis to build the new expression.
1961 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001962 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001963 MultiExprArg Inits,
1964 SourceLocation RBraceLoc,
1965 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001966 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001967 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001968 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001969 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001970
Douglas Gregord3d93062009-11-09 17:16:50 +00001971 // Patch in the result type we were given, which may have been computed
1972 // when the initial InitListExpr was built.
1973 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1974 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001975 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 }
Mike Stump11289f42009-09-09 15:08:12 +00001977
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001979 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001980 /// By default, performs semantic analysis to build the new expression.
1981 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001982 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 MultiExprArg ArrayExprs,
1984 SourceLocation EqualOrColonLoc,
1985 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001986 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001987 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001988 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001989 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001990 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001991 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001992
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001993 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 }
Mike Stump11289f42009-09-09 15:08:12 +00001995
Douglas Gregora16548e2009-08-11 05:31:07 +00001996 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001997 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 /// By default, builds the implicit value initialization without performing
1999 /// any semantic analysis. Subclasses may override this routine to provide
2000 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002001 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002002 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 }
Mike Stump11289f42009-09-09 15:08:12 +00002004
Douglas Gregora16548e2009-08-11 05:31:07 +00002005 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002006 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002007 /// By default, performs semantic analysis to build the new expression.
2008 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002009 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002010 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002011 SourceLocation RParenLoc) {
2012 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002013 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002014 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002015 }
2016
2017 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002018 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 /// By default, performs semantic analysis to build the new expression.
2020 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002021 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002022 MultiExprArg SubExprs,
2023 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002024 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002025 }
Mike Stump11289f42009-09-09 15:08:12 +00002026
Douglas Gregora16548e2009-08-11 05:31:07 +00002027 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002028 ///
2029 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 /// rather than attempting to map the label statement itself.
2031 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002032 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002033 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002034 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002035 }
Mike Stump11289f42009-09-09 15:08:12 +00002036
Douglas Gregora16548e2009-08-11 05:31:07 +00002037 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002038 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002039 /// By default, performs semantic analysis to build the new expression.
2040 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002041 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002042 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002044 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002045 }
Mike Stump11289f42009-09-09 15:08:12 +00002046
Douglas Gregora16548e2009-08-11 05:31:07 +00002047 /// \brief Build a new __builtin_choose_expr expression.
2048 ///
2049 /// By default, performs semantic analysis to build the new expression.
2050 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002051 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002052 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 SourceLocation RParenLoc) {
2054 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002055 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002056 RParenLoc);
2057 }
Mike Stump11289f42009-09-09 15:08:12 +00002058
Peter Collingbourne91147592011-04-15 00:35:48 +00002059 /// \brief Build a new generic selection expression.
2060 ///
2061 /// By default, performs semantic analysis to build the new expression.
2062 /// Subclasses may override this routine to provide different behavior.
2063 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2064 SourceLocation DefaultLoc,
2065 SourceLocation RParenLoc,
2066 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002067 ArrayRef<TypeSourceInfo *> Types,
2068 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002069 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002070 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002071 }
2072
Douglas Gregora16548e2009-08-11 05:31:07 +00002073 /// \brief Build a new overloaded operator call expression.
2074 ///
2075 /// By default, performs semantic analysis to build the new expression.
2076 /// The semantic analysis provides the behavior of template instantiation,
2077 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002078 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002079 /// argument-dependent lookup, etc. Subclasses may override this routine to
2080 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002081 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002083 Expr *Callee,
2084 Expr *First,
2085 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002086
2087 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002088 /// reinterpret_cast.
2089 ///
2090 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002091 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002092 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002093 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002094 Stmt::StmtClass Class,
2095 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002096 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002097 SourceLocation RAngleLoc,
2098 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002099 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002100 SourceLocation RParenLoc) {
2101 switch (Class) {
2102 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002103 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002104 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002105 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002106
2107 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002108 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002109 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002110 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002111
Douglas Gregora16548e2009-08-11 05:31:07 +00002112 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002113 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002114 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002115 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002116 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002117
Douglas Gregora16548e2009-08-11 05:31:07 +00002118 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002119 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002120 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002121 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002122
Douglas Gregora16548e2009-08-11 05:31:07 +00002123 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002124 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002125 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002126 }
Mike Stump11289f42009-09-09 15:08:12 +00002127
Douglas Gregora16548e2009-08-11 05:31:07 +00002128 /// \brief Build a new C++ static_cast expression.
2129 ///
2130 /// By default, performs semantic analysis to build the new expression.
2131 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002132 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002133 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002134 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 SourceLocation RAngleLoc,
2136 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002137 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002139 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002140 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002141 SourceRange(LAngleLoc, RAngleLoc),
2142 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002143 }
2144
2145 /// \brief Build a new C++ dynamic_cast expression.
2146 ///
2147 /// By default, performs semantic analysis to build the new expression.
2148 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002149 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002150 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002151 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002152 SourceLocation RAngleLoc,
2153 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002154 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002155 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002156 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002157 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002158 SourceRange(LAngleLoc, RAngleLoc),
2159 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 }
2161
2162 /// \brief Build a new C++ reinterpret_cast expression.
2163 ///
2164 /// By default, performs semantic analysis to build the new expression.
2165 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002166 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002167 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002168 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002169 SourceLocation RAngleLoc,
2170 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002171 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002173 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002174 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002175 SourceRange(LAngleLoc, RAngleLoc),
2176 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 }
2178
2179 /// \brief Build a new C++ const_cast expression.
2180 ///
2181 /// By default, performs semantic analysis to build the new expression.
2182 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002183 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002185 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 SourceLocation RAngleLoc,
2187 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002188 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002190 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002191 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002192 SourceRange(LAngleLoc, RAngleLoc),
2193 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 }
Mike Stump11289f42009-09-09 15:08:12 +00002195
Douglas Gregora16548e2009-08-11 05:31:07 +00002196 /// \brief Build a new C++ functional-style cast expression.
2197 ///
2198 /// By default, performs semantic analysis to build the new expression.
2199 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002200 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2201 SourceLocation LParenLoc,
2202 Expr *Sub,
2203 SourceLocation RParenLoc) {
2204 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002205 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002206 RParenLoc);
2207 }
Mike Stump11289f42009-09-09 15:08:12 +00002208
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 /// \brief Build a new C++ typeid(type) expression.
2210 ///
2211 /// By default, performs semantic analysis to build the new expression.
2212 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002213 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002214 SourceLocation TypeidLoc,
2215 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002216 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002217 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002218 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002219 }
Mike Stump11289f42009-09-09 15:08:12 +00002220
Francois Pichet9f4f2072010-09-08 12:20:18 +00002221
Douglas Gregora16548e2009-08-11 05:31:07 +00002222 /// \brief Build a new C++ typeid(expr) expression.
2223 ///
2224 /// By default, performs semantic analysis to build the new expression.
2225 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002226 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002227 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002228 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002229 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002230 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002231 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002232 }
2233
Francois Pichet9f4f2072010-09-08 12:20:18 +00002234 /// \brief Build a new C++ __uuidof(type) expression.
2235 ///
2236 /// By default, performs semantic analysis to build the new expression.
2237 /// Subclasses may override this routine to provide different behavior.
2238 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2239 SourceLocation TypeidLoc,
2240 TypeSourceInfo *Operand,
2241 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002242 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002243 RParenLoc);
2244 }
2245
2246 /// \brief Build a new C++ __uuidof(expr) expression.
2247 ///
2248 /// By default, performs semantic analysis to build the new expression.
2249 /// Subclasses may override this routine to provide different behavior.
2250 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2251 SourceLocation TypeidLoc,
2252 Expr *Operand,
2253 SourceLocation RParenLoc) {
2254 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2255 RParenLoc);
2256 }
2257
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 /// \brief Build a new C++ "this" expression.
2259 ///
2260 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002261 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002262 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002263 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002264 QualType ThisType,
2265 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002266 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002267 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002268 }
2269
2270 /// \brief Build a new C++ throw expression.
2271 ///
2272 /// By default, performs semantic analysis to build the new expression.
2273 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002274 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2275 bool IsThrownVariableInScope) {
2276 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002277 }
2278
2279 /// \brief Build a new C++ default-argument expression.
2280 ///
2281 /// By default, builds a new default-argument expression, which does not
2282 /// require any semantic analysis. Subclasses may override this routine to
2283 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002284 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002285 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002286 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002287 }
2288
Richard Smith852c9db2013-04-20 22:23:05 +00002289 /// \brief Build a new C++11 default-initialization expression.
2290 ///
2291 /// By default, builds a new default field initialization expression, which
2292 /// does not require any semantic analysis. Subclasses may override this
2293 /// routine to provide different behavior.
2294 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2295 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002296 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002297 }
2298
Douglas Gregora16548e2009-08-11 05:31:07 +00002299 /// \brief Build a new C++ zero-initialization expression.
2300 ///
2301 /// By default, performs semantic analysis to build the new expression.
2302 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002303 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2304 SourceLocation LParenLoc,
2305 SourceLocation RParenLoc) {
2306 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002307 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002308 }
Mike Stump11289f42009-09-09 15:08:12 +00002309
Douglas Gregora16548e2009-08-11 05:31:07 +00002310 /// \brief Build a new C++ "new" expression.
2311 ///
2312 /// By default, performs semantic analysis to build the new expression.
2313 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002314 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002315 bool UseGlobal,
2316 SourceLocation PlacementLParen,
2317 MultiExprArg PlacementArgs,
2318 SourceLocation PlacementRParen,
2319 SourceRange TypeIdParens,
2320 QualType AllocatedType,
2321 TypeSourceInfo *AllocatedTypeInfo,
2322 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002323 SourceRange DirectInitRange,
2324 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002325 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002326 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002327 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002328 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002329 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002330 AllocatedType,
2331 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002332 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002333 DirectInitRange,
2334 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002335 }
Mike Stump11289f42009-09-09 15:08:12 +00002336
Douglas Gregora16548e2009-08-11 05:31:07 +00002337 /// \brief Build a new C++ "delete" expression.
2338 ///
2339 /// By default, performs semantic analysis to build the new expression.
2340 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002341 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002342 bool IsGlobalDelete,
2343 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002344 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002345 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002346 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002347 }
Mike Stump11289f42009-09-09 15:08:12 +00002348
Douglas Gregor29c42f22012-02-24 07:38:34 +00002349 /// \brief Build a new type trait expression.
2350 ///
2351 /// By default, performs semantic analysis to build the new expression.
2352 /// Subclasses may override this routine to provide different behavior.
2353 ExprResult RebuildTypeTrait(TypeTrait Trait,
2354 SourceLocation StartLoc,
2355 ArrayRef<TypeSourceInfo *> Args,
2356 SourceLocation RParenLoc) {
2357 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2358 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002359
John Wiegley6242b6a2011-04-28 00:16:57 +00002360 /// \brief Build a new array type trait expression.
2361 ///
2362 /// By default, performs semantic analysis to build the new expression.
2363 /// Subclasses may override this routine to provide different behavior.
2364 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2365 SourceLocation StartLoc,
2366 TypeSourceInfo *TSInfo,
2367 Expr *DimExpr,
2368 SourceLocation RParenLoc) {
2369 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2370 }
2371
John Wiegleyf9f65842011-04-25 06:54:41 +00002372 /// \brief Build a new expression trait expression.
2373 ///
2374 /// By default, performs semantic analysis to build the new expression.
2375 /// Subclasses may override this routine to provide different behavior.
2376 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2377 SourceLocation StartLoc,
2378 Expr *Queried,
2379 SourceLocation RParenLoc) {
2380 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2381 }
2382
Mike Stump11289f42009-09-09 15:08:12 +00002383 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002384 /// expression.
2385 ///
2386 /// By default, performs semantic analysis to build the new expression.
2387 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002388 ExprResult RebuildDependentScopeDeclRefExpr(
2389 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002390 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002391 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002392 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002393 bool IsAddressOfOperand,
2394 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002395 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002396 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002397
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002398 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002399 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2400 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002401
Reid Kleckner32506ed2014-06-12 23:03:48 +00002402 return getSema().BuildQualifiedDeclarationNameExpr(
2403 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002404 }
2405
2406 /// \brief Build a new template-id expression.
2407 ///
2408 /// By default, performs semantic analysis to build the new expression.
2409 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002410 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002411 SourceLocation TemplateKWLoc,
2412 LookupResult &R,
2413 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002414 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002415 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2416 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002417 }
2418
2419 /// \brief Build a new object-construction expression.
2420 ///
2421 /// By default, performs semantic analysis to build the new expression.
2422 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002423 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002424 SourceLocation Loc,
2425 CXXConstructorDecl *Constructor,
2426 bool IsElidable,
2427 MultiExprArg Args,
2428 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002429 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002430 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002431 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002432 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002433 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002434 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002435 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002436 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002437 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002438
Douglas Gregordb121ba2009-12-14 16:27:04 +00002439 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002440 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002441 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002442 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002443 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002444 RequiresZeroInit, ConstructKind,
2445 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002446 }
2447
2448 /// \brief Build a new object-construction expression.
2449 ///
2450 /// By default, performs semantic analysis to build the new expression.
2451 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002452 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2453 SourceLocation LParenLoc,
2454 MultiExprArg Args,
2455 SourceLocation RParenLoc) {
2456 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002457 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002458 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002459 RParenLoc);
2460 }
2461
2462 /// \brief Build a new object-construction expression.
2463 ///
2464 /// By default, performs semantic analysis to build the new expression.
2465 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002466 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2467 SourceLocation LParenLoc,
2468 MultiExprArg Args,
2469 SourceLocation RParenLoc) {
2470 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002471 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002472 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002473 RParenLoc);
2474 }
Mike Stump11289f42009-09-09 15:08:12 +00002475
Douglas Gregora16548e2009-08-11 05:31:07 +00002476 /// \brief Build a new member reference expression.
2477 ///
2478 /// By default, performs semantic analysis to build the new expression.
2479 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002480 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002481 QualType BaseType,
2482 bool IsArrow,
2483 SourceLocation OperatorLoc,
2484 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002485 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002486 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002487 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002488 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002489 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002490 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002491
John McCallb268a282010-08-23 23:25:46 +00002492 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002493 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002494 SS, TemplateKWLoc,
2495 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002496 MemberNameInfo,
2497 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002498 }
2499
John McCall10eae182009-11-30 22:42:35 +00002500 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002501 ///
2502 /// By default, performs semantic analysis to build the new expression.
2503 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002504 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2505 SourceLocation OperatorLoc,
2506 bool IsArrow,
2507 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002508 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002509 NamedDecl *FirstQualifierInScope,
2510 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002511 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002512 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002513 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002514
John McCallb268a282010-08-23 23:25:46 +00002515 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002516 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002517 SS, TemplateKWLoc,
2518 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002519 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002520 }
Mike Stump11289f42009-09-09 15:08:12 +00002521
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002522 /// \brief Build a new noexcept expression.
2523 ///
2524 /// By default, performs semantic analysis to build the new expression.
2525 /// Subclasses may override this routine to provide different behavior.
2526 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2527 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2528 }
2529
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002530 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002531 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2532 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002533 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002534 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002535 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002536 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2537 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002538 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002539
2540 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2541 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002542 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002543 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002544
Patrick Beard0caa3942012-04-19 00:25:12 +00002545 /// \brief Build a new Objective-C boxed expression.
2546 ///
2547 /// By default, performs semantic analysis to build the new expression.
2548 /// Subclasses may override this routine to provide different behavior.
2549 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2550 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2551 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002552
Ted Kremeneke65b0862012-03-06 20:05:56 +00002553 /// \brief Build a new Objective-C array literal.
2554 ///
2555 /// By default, performs semantic analysis to build the new expression.
2556 /// Subclasses may override this routine to provide different behavior.
2557 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2558 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002559 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002560 MultiExprArg(Elements, NumElements));
2561 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002562
2563 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002564 Expr *Base, Expr *Key,
2565 ObjCMethodDecl *getterMethod,
2566 ObjCMethodDecl *setterMethod) {
2567 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2568 getterMethod, setterMethod);
2569 }
2570
2571 /// \brief Build a new Objective-C dictionary literal.
2572 ///
2573 /// By default, performs semantic analysis to build the new expression.
2574 /// Subclasses may override this routine to provide different behavior.
2575 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2576 ObjCDictionaryElement *Elements,
2577 unsigned NumElements) {
2578 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2579 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002580
James Dennett2a4d13c2012-06-15 07:13:21 +00002581 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002582 ///
2583 /// By default, performs semantic analysis to build the new expression.
2584 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002585 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002586 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002587 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002588 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002589 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002590
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002591 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002592 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002593 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002594 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002595 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002596 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002597 MultiExprArg Args,
2598 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002599 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2600 ReceiverTypeInfo->getType(),
2601 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002602 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002603 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002604 }
2605
2606 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002607 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002608 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002609 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002610 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002611 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002612 MultiExprArg Args,
2613 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002614 return SemaRef.BuildInstanceMessage(Receiver,
2615 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002616 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002617 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002618 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002619 }
2620
Douglas Gregord51d90d2010-04-26 20:11:03 +00002621 /// \brief Build a new Objective-C ivar reference expression.
2622 ///
2623 /// By default, performs semantic analysis to build the new expression.
2624 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002625 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002626 SourceLocation IvarLoc,
2627 bool IsArrow, bool IsFreeIvar) {
2628 // FIXME: We lose track of the IsFreeIvar bit.
2629 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002630 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2631 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002632 /*FIXME:*/IvarLoc, IsArrow,
2633 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002634 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002635 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002636 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002637 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002638
2639 /// \brief Build a new Objective-C property reference expression.
2640 ///
2641 /// By default, performs semantic analysis to build the new expression.
2642 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002643 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002644 ObjCPropertyDecl *Property,
2645 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002646 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002647 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2648 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2649 /*FIXME:*/PropertyLoc,
2650 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002651 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002652 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002653 NameInfo,
2654 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002655 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002656
John McCallb7bd14f2010-12-02 01:19:52 +00002657 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002658 ///
2659 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002660 /// Subclasses may override this routine to provide different behavior.
2661 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2662 ObjCMethodDecl *Getter,
2663 ObjCMethodDecl *Setter,
2664 SourceLocation PropertyLoc) {
2665 // Since these expressions can only be value-dependent, we do not
2666 // need to perform semantic analysis again.
2667 return Owned(
2668 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2669 VK_LValue, OK_ObjCProperty,
2670 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002671 }
2672
Douglas Gregord51d90d2010-04-26 20:11:03 +00002673 /// \brief Build a new Objective-C "isa" expression.
2674 ///
2675 /// By default, performs semantic analysis to build the new expression.
2676 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002677 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002678 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002679 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002680 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2681 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002682 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002683 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002684 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002685 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002686 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002687 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002688
Douglas Gregora16548e2009-08-11 05:31:07 +00002689 /// \brief Build a new shuffle vector expression.
2690 ///
2691 /// By default, performs semantic analysis to build the new expression.
2692 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002693 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002694 MultiExprArg SubExprs,
2695 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002696 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002697 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002698 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2699 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2700 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002701 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002702
Douglas Gregora16548e2009-08-11 05:31:07 +00002703 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002704 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002705 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2706 SemaRef.Context.BuiltinFnTy,
2707 VK_RValue, BuiltinLoc);
2708 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2709 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002710 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002711
2712 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002713 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002714 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002715 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002716
Douglas Gregora16548e2009-08-11 05:31:07 +00002717 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002718 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002719 }
John McCall31f82722010-11-12 08:19:04 +00002720
Hal Finkelc4d7c822013-09-18 03:29:45 +00002721 /// \brief Build a new convert vector expression.
2722 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2723 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2724 SourceLocation RParenLoc) {
2725 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2726 BuiltinLoc, RParenLoc);
2727 }
2728
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002729 /// \brief Build a new template argument pack expansion.
2730 ///
2731 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002732 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002733 /// different behavior.
2734 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002735 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002736 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002737 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002738 case TemplateArgument::Expression: {
2739 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002740 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2741 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002742 if (Result.isInvalid())
2743 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002744
Douglas Gregor98318c22011-01-03 21:37:45 +00002745 return TemplateArgumentLoc(Result.get(), Result.get());
2746 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002747
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002748 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002749 return TemplateArgumentLoc(TemplateArgument(
2750 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002751 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002752 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002753 Pattern.getTemplateNameLoc(),
2754 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002755
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002756 case TemplateArgument::Null:
2757 case TemplateArgument::Integral:
2758 case TemplateArgument::Declaration:
2759 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002760 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002761 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002762 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002763
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002764 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002765 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002766 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002767 EllipsisLoc,
2768 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002769 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2770 Expansion);
2771 break;
2772 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002773
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002774 return TemplateArgumentLoc();
2775 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002776
Douglas Gregor968f23a2011-01-03 19:31:53 +00002777 /// \brief Build a new expression pack expansion.
2778 ///
2779 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002780 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002781 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002782 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002783 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002784 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002785 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002786
Richard Smith0f0af192014-11-08 05:07:16 +00002787 /// \brief Build a new C++1z fold-expression.
2788 ///
2789 /// By default, performs semantic analysis in order to build a new fold
2790 /// expression.
2791 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
2792 BinaryOperatorKind Operator,
2793 SourceLocation EllipsisLoc, Expr *RHS,
2794 SourceLocation RParenLoc) {
2795 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
2796 RHS, RParenLoc);
2797 }
2798
2799 /// \brief Build an empty C++1z fold-expression with the given operator.
2800 ///
2801 /// By default, produces the fallback value for the fold-expression, or
2802 /// produce an error if there is no fallback value.
2803 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
2804 BinaryOperatorKind Operator) {
2805 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
2806 }
2807
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002808 /// \brief Build a new atomic operation expression.
2809 ///
2810 /// By default, performs semantic analysis to build the new expression.
2811 /// Subclasses may override this routine to provide different behavior.
2812 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2813 MultiExprArg SubExprs,
2814 QualType RetTy,
2815 AtomicExpr::AtomicOp Op,
2816 SourceLocation RParenLoc) {
2817 // Just create the expression; there is not any interesting semantic
2818 // analysis here because we can't actually build an AtomicExpr until
2819 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002820 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002821 RParenLoc);
2822 }
2823
John McCall31f82722010-11-12 08:19:04 +00002824private:
Douglas Gregor14454802011-02-25 02:25:35 +00002825 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2826 QualType ObjectType,
2827 NamedDecl *FirstQualifierInScope,
2828 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002829
2830 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2831 QualType ObjectType,
2832 NamedDecl *FirstQualifierInScope,
2833 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002834
2835 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2836 NamedDecl *FirstQualifierInScope,
2837 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002838};
Douglas Gregora16548e2009-08-11 05:31:07 +00002839
Douglas Gregorebe10102009-08-20 07:17:43 +00002840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002841StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002842 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002843 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002844
Douglas Gregorebe10102009-08-20 07:17:43 +00002845 switch (S->getStmtClass()) {
2846 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002847
Douglas Gregorebe10102009-08-20 07:17:43 +00002848 // Transform individual statement nodes
2849#define STMT(Node, Parent) \
2850 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002851#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002852#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002853#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002854
Douglas Gregorebe10102009-08-20 07:17:43 +00002855 // Transform expressions by calling TransformExpr.
2856#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002857#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002858#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002859#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002860 {
John McCalldadc5752010-08-24 06:29:42 +00002861 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002862 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002863 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002864
Richard Smith945f8d32013-01-14 22:39:08 +00002865 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002866 }
Mike Stump11289f42009-09-09 15:08:12 +00002867 }
2868
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002869 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002870}
Mike Stump11289f42009-09-09 15:08:12 +00002871
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002872template<typename Derived>
2873OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2874 if (!S)
2875 return S;
2876
2877 switch (S->getClauseKind()) {
2878 default: break;
2879 // Transform individual clause nodes
2880#define OPENMP_CLAUSE(Name, Class) \
2881 case OMPC_ ## Name : \
2882 return getDerived().Transform ## Class(cast<Class>(S));
2883#include "clang/Basic/OpenMPKinds.def"
2884 }
2885
2886 return S;
2887}
2888
Mike Stump11289f42009-09-09 15:08:12 +00002889
Douglas Gregore922c772009-08-04 22:27:00 +00002890template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002891ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002892 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002893 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002894
2895 switch (E->getStmtClass()) {
2896 case Stmt::NoStmtClass: break;
2897#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002898#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002899#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002900 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002901#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002902 }
2903
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002904 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002905}
2906
2907template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002908ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00002909 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00002910 // Initializers are instantiated like expressions, except that various outer
2911 // layers are stripped.
2912 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002913 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002914
2915 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2916 Init = ExprTemp->getSubExpr();
2917
Richard Smithe6ca4752013-05-30 22:40:16 +00002918 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2919 Init = MTE->GetTemporaryExpr();
2920
Richard Smithd59b8322012-12-19 01:39:02 +00002921 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2922 Init = Binder->getSubExpr();
2923
2924 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2925 Init = ICE->getSubExprAsWritten();
2926
Richard Smithcc1b96d2013-06-12 22:31:48 +00002927 if (CXXStdInitializerListExpr *ILE =
2928 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00002929 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00002930
Richard Smithc6abd962014-07-25 01:12:44 +00002931 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00002932 // InitListExprs. Other forms of copy-initialization will be a no-op if
2933 // the initializer is already the right type.
2934 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00002935 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00002936 return getDerived().TransformExpr(Init);
2937
2938 // Revert value-initialization back to empty parens.
2939 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2940 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002941 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002942 Parens.getEnd());
2943 }
2944
2945 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2946 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002947 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002948 SourceLocation());
2949
2950 // Revert initialization by constructor back to a parenthesized or braced list
2951 // of expressions. Any other form of initializer can just be reused directly.
2952 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002953 return getDerived().TransformExpr(Init);
2954
Richard Smithf8adcdc2014-07-17 05:12:35 +00002955 // If the initialization implicitly converted an initializer list to a
2956 // std::initializer_list object, unwrap the std::initializer_list too.
2957 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00002958 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00002959
Richard Smithd59b8322012-12-19 01:39:02 +00002960 SmallVector<Expr*, 8> NewArgs;
2961 bool ArgChanged = false;
2962 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00002963 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00002964 return ExprError();
2965
2966 // If this was list initialization, revert to list form.
2967 if (Construct->isListInitialization())
2968 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2969 Construct->getLocEnd(),
2970 Construct->getType());
2971
Richard Smithd59b8322012-12-19 01:39:02 +00002972 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002973 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00002974 if (Parens.isInvalid()) {
2975 // This was a variable declaration's initialization for which no initializer
2976 // was specified.
2977 assert(NewArgs.empty() &&
2978 "no parens or braces but have direct init with arguments?");
2979 return ExprEmpty();
2980 }
Richard Smithd59b8322012-12-19 01:39:02 +00002981 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2982 Parens.getEnd());
2983}
2984
2985template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002986bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2987 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002988 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002989 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002990 bool *ArgChanged) {
2991 for (unsigned I = 0; I != NumInputs; ++I) {
2992 // If requested, drop call arguments that need to be dropped.
2993 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2994 if (ArgChanged)
2995 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002996
Douglas Gregora3efea12011-01-03 19:04:46 +00002997 break;
2998 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002999
Douglas Gregor968f23a2011-01-03 19:31:53 +00003000 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3001 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003002
Chris Lattner01cf8db2011-07-20 06:58:45 +00003003 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003004 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3005 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003006
Douglas Gregor968f23a2011-01-03 19:31:53 +00003007 // Determine whether the set of unexpanded parameter packs can and should
3008 // be expanded.
3009 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003010 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003011 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3012 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003013 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3014 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003015 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003016 Expand, RetainExpansion,
3017 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003018 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003019
Douglas Gregor968f23a2011-01-03 19:31:53 +00003020 if (!Expand) {
3021 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003022 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003023 // expansion.
3024 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3025 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3026 if (OutPattern.isInvalid())
3027 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003028
3029 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003030 Expansion->getEllipsisLoc(),
3031 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003032 if (Out.isInvalid())
3033 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003034
Douglas Gregor968f23a2011-01-03 19:31:53 +00003035 if (ArgChanged)
3036 *ArgChanged = true;
3037 Outputs.push_back(Out.get());
3038 continue;
3039 }
John McCall542e7c62011-07-06 07:30:07 +00003040
3041 // Record right away that the argument was changed. This needs
3042 // to happen even if the array expands to nothing.
3043 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003044
Douglas Gregor968f23a2011-01-03 19:31:53 +00003045 // The transform has determined that we should perform an elementwise
3046 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003047 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003048 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3049 ExprResult Out = getDerived().TransformExpr(Pattern);
3050 if (Out.isInvalid())
3051 return true;
3052
Richard Smith9467be42014-06-06 17:33:35 +00003053 // FIXME: Can this happen? We should not try to expand the pack
3054 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003055 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003056 Out = getDerived().RebuildPackExpansion(
3057 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003058 if (Out.isInvalid())
3059 return true;
3060 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003061
Douglas Gregor968f23a2011-01-03 19:31:53 +00003062 Outputs.push_back(Out.get());
3063 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003064
Richard Smith9467be42014-06-06 17:33:35 +00003065 // If we're supposed to retain a pack expansion, do so by temporarily
3066 // forgetting the partially-substituted parameter pack.
3067 if (RetainExpansion) {
3068 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3069
3070 ExprResult Out = getDerived().TransformExpr(Pattern);
3071 if (Out.isInvalid())
3072 return true;
3073
3074 Out = getDerived().RebuildPackExpansion(
3075 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3076 if (Out.isInvalid())
3077 return true;
3078
3079 Outputs.push_back(Out.get());
3080 }
3081
Douglas Gregor968f23a2011-01-03 19:31:53 +00003082 continue;
3083 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003084
Richard Smithd59b8322012-12-19 01:39:02 +00003085 ExprResult Result =
3086 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3087 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003088 if (Result.isInvalid())
3089 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003090
Douglas Gregora3efea12011-01-03 19:04:46 +00003091 if (Result.get() != Inputs[I] && ArgChanged)
3092 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003093
3094 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003095 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003096
Douglas Gregora3efea12011-01-03 19:04:46 +00003097 return false;
3098}
3099
3100template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003101NestedNameSpecifierLoc
3102TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3103 NestedNameSpecifierLoc NNS,
3104 QualType ObjectType,
3105 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003106 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003107 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003108 Qualifier = Qualifier.getPrefix())
3109 Qualifiers.push_back(Qualifier);
3110
3111 CXXScopeSpec SS;
3112 while (!Qualifiers.empty()) {
3113 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3114 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003115
Douglas Gregor14454802011-02-25 02:25:35 +00003116 switch (QNNS->getKind()) {
3117 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003118 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003119 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003120 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003121 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003122 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003123 FirstQualifierInScope, false))
3124 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003125
Douglas Gregor14454802011-02-25 02:25:35 +00003126 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003127
Douglas Gregor14454802011-02-25 02:25:35 +00003128 case NestedNameSpecifier::Namespace: {
3129 NamespaceDecl *NS
3130 = cast_or_null<NamespaceDecl>(
3131 getDerived().TransformDecl(
3132 Q.getLocalBeginLoc(),
3133 QNNS->getAsNamespace()));
3134 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3135 break;
3136 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003137
Douglas Gregor14454802011-02-25 02:25:35 +00003138 case NestedNameSpecifier::NamespaceAlias: {
3139 NamespaceAliasDecl *Alias
3140 = cast_or_null<NamespaceAliasDecl>(
3141 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3142 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003143 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003144 Q.getLocalEndLoc());
3145 break;
3146 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003147
Douglas Gregor14454802011-02-25 02:25:35 +00003148 case NestedNameSpecifier::Global:
3149 // There is no meaningful transformation that one could perform on the
3150 // global scope.
3151 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3152 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003153
Nikola Smiljanic67860242014-09-26 00:28:20 +00003154 case NestedNameSpecifier::Super: {
3155 CXXRecordDecl *RD =
3156 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3157 SourceLocation(), QNNS->getAsRecordDecl()));
3158 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3159 break;
3160 }
3161
Douglas Gregor14454802011-02-25 02:25:35 +00003162 case NestedNameSpecifier::TypeSpecWithTemplate:
3163 case NestedNameSpecifier::TypeSpec: {
3164 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3165 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003166
Douglas Gregor14454802011-02-25 02:25:35 +00003167 if (!TL)
3168 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003169
Douglas Gregor14454802011-02-25 02:25:35 +00003170 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003171 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003172 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003173 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003174 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003175 if (TL.getType()->isEnumeralType())
3176 SemaRef.Diag(TL.getBeginLoc(),
3177 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003178 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3179 Q.getLocalEndLoc());
3180 break;
3181 }
Richard Trieude756fb2011-05-07 01:36:37 +00003182 // If the nested-name-specifier is an invalid type def, don't emit an
3183 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003184 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3185 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003186 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003187 << TL.getType() << SS.getRange();
3188 }
Douglas Gregor14454802011-02-25 02:25:35 +00003189 return NestedNameSpecifierLoc();
3190 }
Douglas Gregore16af532011-02-28 18:50:33 +00003191 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003192
Douglas Gregore16af532011-02-28 18:50:33 +00003193 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003194 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003195 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003196 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003197
Douglas Gregor14454802011-02-25 02:25:35 +00003198 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003199 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003200 !getDerived().AlwaysRebuild())
3201 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003202
3203 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003204 // nested-name-specifier, do so.
3205 if (SS.location_size() == NNS.getDataLength() &&
3206 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3207 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3208
3209 // Allocate new nested-name-specifier location information.
3210 return SS.getWithLocInContext(SemaRef.Context);
3211}
3212
3213template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003214DeclarationNameInfo
3215TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003216::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003217 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003218 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003219 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003220
3221 switch (Name.getNameKind()) {
3222 case DeclarationName::Identifier:
3223 case DeclarationName::ObjCZeroArgSelector:
3224 case DeclarationName::ObjCOneArgSelector:
3225 case DeclarationName::ObjCMultiArgSelector:
3226 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003227 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003228 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003229 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003230
Douglas Gregorf816bd72009-09-03 22:13:48 +00003231 case DeclarationName::CXXConstructorName:
3232 case DeclarationName::CXXDestructorName:
3233 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003234 TypeSourceInfo *NewTInfo;
3235 CanQualType NewCanTy;
3236 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003237 NewTInfo = getDerived().TransformType(OldTInfo);
3238 if (!NewTInfo)
3239 return DeclarationNameInfo();
3240 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003241 }
3242 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003243 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003244 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003245 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003246 if (NewT.isNull())
3247 return DeclarationNameInfo();
3248 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3249 }
Mike Stump11289f42009-09-09 15:08:12 +00003250
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003251 DeclarationName NewName
3252 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3253 NewCanTy);
3254 DeclarationNameInfo NewNameInfo(NameInfo);
3255 NewNameInfo.setName(NewName);
3256 NewNameInfo.setNamedTypeInfo(NewTInfo);
3257 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003258 }
Mike Stump11289f42009-09-09 15:08:12 +00003259 }
3260
David Blaikie83d382b2011-09-23 05:06:16 +00003261 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003262}
3263
3264template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003265TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003266TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3267 TemplateName Name,
3268 SourceLocation NameLoc,
3269 QualType ObjectType,
3270 NamedDecl *FirstQualifierInScope) {
3271 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3272 TemplateDecl *Template = QTN->getTemplateDecl();
3273 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003274
Douglas Gregor9db53502011-03-02 18:07:45 +00003275 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003276 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003277 Template));
3278 if (!TransTemplate)
3279 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003280
Douglas Gregor9db53502011-03-02 18:07:45 +00003281 if (!getDerived().AlwaysRebuild() &&
3282 SS.getScopeRep() == QTN->getQualifier() &&
3283 TransTemplate == Template)
3284 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003285
Douglas Gregor9db53502011-03-02 18:07:45 +00003286 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3287 TransTemplate);
3288 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003289
Douglas Gregor9db53502011-03-02 18:07:45 +00003290 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3291 if (SS.getScopeRep()) {
3292 // These apply to the scope specifier, not the template.
3293 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003294 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003295 }
3296
Douglas Gregor9db53502011-03-02 18:07:45 +00003297 if (!getDerived().AlwaysRebuild() &&
3298 SS.getScopeRep() == DTN->getQualifier() &&
3299 ObjectType.isNull())
3300 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003301
Douglas Gregor9db53502011-03-02 18:07:45 +00003302 if (DTN->isIdentifier()) {
3303 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003304 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003305 NameLoc,
3306 ObjectType,
3307 FirstQualifierInScope);
3308 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003309
Douglas Gregor9db53502011-03-02 18:07:45 +00003310 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3311 ObjectType);
3312 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003313
Douglas Gregor9db53502011-03-02 18:07:45 +00003314 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3315 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003316 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003317 Template));
3318 if (!TransTemplate)
3319 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003320
Douglas Gregor9db53502011-03-02 18:07:45 +00003321 if (!getDerived().AlwaysRebuild() &&
3322 TransTemplate == Template)
3323 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003324
Douglas Gregor9db53502011-03-02 18:07:45 +00003325 return TemplateName(TransTemplate);
3326 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003327
Douglas Gregor9db53502011-03-02 18:07:45 +00003328 if (SubstTemplateTemplateParmPackStorage *SubstPack
3329 = Name.getAsSubstTemplateTemplateParmPack()) {
3330 TemplateTemplateParmDecl *TransParam
3331 = cast_or_null<TemplateTemplateParmDecl>(
3332 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3333 if (!TransParam)
3334 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003335
Douglas Gregor9db53502011-03-02 18:07:45 +00003336 if (!getDerived().AlwaysRebuild() &&
3337 TransParam == SubstPack->getParameterPack())
3338 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003339
3340 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003341 SubstPack->getArgumentPack());
3342 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003343
Douglas Gregor9db53502011-03-02 18:07:45 +00003344 // These should be getting filtered out before they reach the AST.
3345 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003346}
3347
3348template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003349void TreeTransform<Derived>::InventTemplateArgumentLoc(
3350 const TemplateArgument &Arg,
3351 TemplateArgumentLoc &Output) {
3352 SourceLocation Loc = getDerived().getBaseLocation();
3353 switch (Arg.getKind()) {
3354 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003355 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003356 break;
3357
3358 case TemplateArgument::Type:
3359 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003360 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003361
John McCall0ad16662009-10-29 08:12:44 +00003362 break;
3363
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003364 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003365 case TemplateArgument::TemplateExpansion: {
3366 NestedNameSpecifierLocBuilder Builder;
3367 TemplateName Template = Arg.getAsTemplate();
3368 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3369 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3370 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3371 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003372
Douglas Gregor9d802122011-03-02 17:09:35 +00003373 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003374 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003375 Builder.getWithLocInContext(SemaRef.Context),
3376 Loc);
3377 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003378 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003379 Builder.getWithLocInContext(SemaRef.Context),
3380 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003381
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003382 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003383 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003384
John McCall0ad16662009-10-29 08:12:44 +00003385 case TemplateArgument::Expression:
3386 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3387 break;
3388
3389 case TemplateArgument::Declaration:
3390 case TemplateArgument::Integral:
3391 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003392 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003393 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003394 break;
3395 }
3396}
3397
3398template<typename Derived>
3399bool TreeTransform<Derived>::TransformTemplateArgument(
3400 const TemplateArgumentLoc &Input,
3401 TemplateArgumentLoc &Output) {
3402 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003403 switch (Arg.getKind()) {
3404 case TemplateArgument::Null:
3405 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003406 case TemplateArgument::Pack:
3407 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003408 case TemplateArgument::NullPtr:
3409 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003410
Douglas Gregore922c772009-08-04 22:27:00 +00003411 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003412 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003413 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003414 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003415
3416 DI = getDerived().TransformType(DI);
3417 if (!DI) return true;
3418
3419 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3420 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003421 }
Mike Stump11289f42009-09-09 15:08:12 +00003422
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003423 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003424 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3425 if (QualifierLoc) {
3426 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3427 if (!QualifierLoc)
3428 return true;
3429 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003430
Douglas Gregordf846d12011-03-02 18:46:51 +00003431 CXXScopeSpec SS;
3432 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003433 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003434 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3435 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003436 if (Template.isNull())
3437 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003438
Douglas Gregor9d802122011-03-02 17:09:35 +00003439 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003440 Input.getTemplateNameLoc());
3441 return false;
3442 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003443
3444 case TemplateArgument::TemplateExpansion:
3445 llvm_unreachable("Caller should expand pack expansions");
3446
Douglas Gregore922c772009-08-04 22:27:00 +00003447 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003448 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003449 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003450 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003451
John McCall0ad16662009-10-29 08:12:44 +00003452 Expr *InputExpr = Input.getSourceExpression();
3453 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3454
Chris Lattnercdb591a2011-04-25 20:37:58 +00003455 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003456 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003457 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003458 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003459 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003460 }
Douglas Gregore922c772009-08-04 22:27:00 +00003461 }
Mike Stump11289f42009-09-09 15:08:12 +00003462
Douglas Gregore922c772009-08-04 22:27:00 +00003463 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003464 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003465}
3466
Douglas Gregorfe921a72010-12-20 23:36:19 +00003467/// \brief Iterator adaptor that invents template argument location information
3468/// for each of the template arguments in its underlying iterator.
3469template<typename Derived, typename InputIterator>
3470class TemplateArgumentLocInventIterator {
3471 TreeTransform<Derived> &Self;
3472 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003473
Douglas Gregorfe921a72010-12-20 23:36:19 +00003474public:
3475 typedef TemplateArgumentLoc value_type;
3476 typedef TemplateArgumentLoc reference;
3477 typedef typename std::iterator_traits<InputIterator>::difference_type
3478 difference_type;
3479 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003480
Douglas Gregorfe921a72010-12-20 23:36:19 +00003481 class pointer {
3482 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003483
Douglas Gregorfe921a72010-12-20 23:36:19 +00003484 public:
3485 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003486
Douglas Gregorfe921a72010-12-20 23:36:19 +00003487 const TemplateArgumentLoc *operator->() const { return &Arg; }
3488 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003489
Douglas Gregorfe921a72010-12-20 23:36:19 +00003490 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003491
Douglas Gregorfe921a72010-12-20 23:36:19 +00003492 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3493 InputIterator Iter)
3494 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003495
Douglas Gregorfe921a72010-12-20 23:36:19 +00003496 TemplateArgumentLocInventIterator &operator++() {
3497 ++Iter;
3498 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003499 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003500
Douglas Gregorfe921a72010-12-20 23:36:19 +00003501 TemplateArgumentLocInventIterator operator++(int) {
3502 TemplateArgumentLocInventIterator Old(*this);
3503 ++(*this);
3504 return Old;
3505 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003506
Douglas Gregorfe921a72010-12-20 23:36:19 +00003507 reference operator*() const {
3508 TemplateArgumentLoc Result;
3509 Self.InventTemplateArgumentLoc(*Iter, Result);
3510 return Result;
3511 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003512
Douglas Gregorfe921a72010-12-20 23:36:19 +00003513 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003514
Douglas Gregorfe921a72010-12-20 23:36:19 +00003515 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3516 const TemplateArgumentLocInventIterator &Y) {
3517 return X.Iter == Y.Iter;
3518 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003519
Douglas Gregorfe921a72010-12-20 23:36:19 +00003520 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3521 const TemplateArgumentLocInventIterator &Y) {
3522 return X.Iter != Y.Iter;
3523 }
3524};
Chad Rosier1dcde962012-08-08 18:46:20 +00003525
Douglas Gregor42cafa82010-12-20 17:42:22 +00003526template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003527template<typename InputIterator>
3528bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3529 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003530 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003531 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003532 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003533 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003534
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003535 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3536 // Unpack argument packs, which we translate them into separate
3537 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003538 // FIXME: We could do much better if we could guarantee that the
3539 // TemplateArgumentLocInfo for the pack expansion would be usable for
3540 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003541 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003542 TemplateArgument::pack_iterator>
3543 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003544 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003545 In.getArgument().pack_begin()),
3546 PackLocIterator(*this,
3547 In.getArgument().pack_end()),
3548 Outputs))
3549 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003550
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003551 continue;
3552 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003553
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003554 if (In.getArgument().isPackExpansion()) {
3555 // We have a pack expansion, for which we will be substituting into
3556 // the pattern.
3557 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003558 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003559 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003560 = getSema().getTemplateArgumentPackExpansionPattern(
3561 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003562
Chris Lattner01cf8db2011-07-20 06:58:45 +00003563 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003564 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3565 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003566
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003567 // Determine whether the set of unexpanded parameter packs can and should
3568 // be expanded.
3569 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003570 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003571 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003572 if (getDerived().TryExpandParameterPacks(Ellipsis,
3573 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003574 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003575 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003576 RetainExpansion,
3577 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003578 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003579
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003580 if (!Expand) {
3581 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003582 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003583 // expansion.
3584 TemplateArgumentLoc OutPattern;
3585 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3586 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3587 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003588
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003589 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3590 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003591 if (Out.getArgument().isNull())
3592 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003593
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003594 Outputs.addArgument(Out);
3595 continue;
3596 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003597
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003598 // The transform has determined that we should perform an elementwise
3599 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003600 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003601 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3602
3603 if (getDerived().TransformTemplateArgument(Pattern, Out))
3604 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003605
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003606 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003607 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3608 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003609 if (Out.getArgument().isNull())
3610 return true;
3611 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003612
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003613 Outputs.addArgument(Out);
3614 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003615
Douglas Gregor48d24112011-01-10 20:53:55 +00003616 // If we're supposed to retain a pack expansion, do so by temporarily
3617 // forgetting the partially-substituted parameter pack.
3618 if (RetainExpansion) {
3619 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003620
Douglas Gregor48d24112011-01-10 20:53:55 +00003621 if (getDerived().TransformTemplateArgument(Pattern, Out))
3622 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003623
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003624 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3625 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003626 if (Out.getArgument().isNull())
3627 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003628
Douglas Gregor48d24112011-01-10 20:53:55 +00003629 Outputs.addArgument(Out);
3630 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003631
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003632 continue;
3633 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003634
3635 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003636 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003637 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003638
Douglas Gregor42cafa82010-12-20 17:42:22 +00003639 Outputs.addArgument(Out);
3640 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003641
Douglas Gregor42cafa82010-12-20 17:42:22 +00003642 return false;
3643
3644}
3645
Douglas Gregord6ff3322009-08-04 16:50:30 +00003646//===----------------------------------------------------------------------===//
3647// Type transformation
3648//===----------------------------------------------------------------------===//
3649
3650template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003651QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003652 if (getDerived().AlreadyTransformed(T))
3653 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003654
John McCall550e0c22009-10-21 00:40:46 +00003655 // Temporary workaround. All of these transformations should
3656 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003657 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3658 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003659
John McCall31f82722010-11-12 08:19:04 +00003660 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003661
John McCall550e0c22009-10-21 00:40:46 +00003662 if (!NewDI)
3663 return QualType();
3664
3665 return NewDI->getType();
3666}
3667
3668template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003669TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003670 // Refine the base location to the type's location.
3671 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3672 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003673 if (getDerived().AlreadyTransformed(DI->getType()))
3674 return DI;
3675
3676 TypeLocBuilder TLB;
3677
3678 TypeLoc TL = DI->getTypeLoc();
3679 TLB.reserve(TL.getFullDataSize());
3680
John McCall31f82722010-11-12 08:19:04 +00003681 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003682 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003683 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003684
John McCallbcd03502009-12-07 02:54:59 +00003685 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003686}
3687
3688template<typename Derived>
3689QualType
John McCall31f82722010-11-12 08:19:04 +00003690TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003691 switch (T.getTypeLocClass()) {
3692#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003693#define TYPELOC(CLASS, PARENT) \
3694 case TypeLoc::CLASS: \
3695 return getDerived().Transform##CLASS##Type(TLB, \
3696 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003697#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003698 }
Mike Stump11289f42009-09-09 15:08:12 +00003699
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003700 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003701}
3702
3703/// FIXME: By default, this routine adds type qualifiers only to types
3704/// that can have qualifiers, and silently suppresses those qualifiers
3705/// that are not permitted (e.g., qualifiers on reference or function
3706/// types). This is the right thing for template instantiation, but
3707/// probably not for other clients.
3708template<typename Derived>
3709QualType
3710TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003711 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003712 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003713
John McCall31f82722010-11-12 08:19:04 +00003714 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003715 if (Result.isNull())
3716 return QualType();
3717
3718 // Silently suppress qualifiers if the result type can't be qualified.
3719 // FIXME: this is the right thing for template instantiation, but
3720 // probably not for other clients.
3721 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003722 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003723
John McCall31168b02011-06-15 23:02:42 +00003724 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003725 // resulting type.
3726 if (Quals.hasObjCLifetime()) {
3727 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3728 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003729 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003730 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003731 // A lifetime qualifier applied to a substituted template parameter
3732 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003733 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003734 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003735 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3736 QualType Replacement = SubstTypeParam->getReplacementType();
3737 Qualifiers Qs = Replacement.getQualifiers();
3738 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003739 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003740 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3741 Qs);
3742 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003743 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003744 Replacement);
3745 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003746 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3747 // 'auto' types behave the same way as template parameters.
3748 QualType Deduced = AutoTy->getDeducedType();
3749 Qualifiers Qs = Deduced.getQualifiers();
3750 Qs.removeObjCLifetime();
3751 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3752 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003753 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3754 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003755 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003756 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003757 // Otherwise, complain about the addition of a qualifier to an
3758 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003759 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003760 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003761 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003762
Douglas Gregore46db902011-06-17 22:11:49 +00003763 Quals.removeObjCLifetime();
3764 }
3765 }
3766 }
John McCallcb0f89a2010-06-05 06:41:15 +00003767 if (!Quals.empty()) {
3768 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003769 // BuildQualifiedType might not add qualifiers if they are invalid.
3770 if (Result.hasLocalQualifiers())
3771 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003772 // No location information to preserve.
3773 }
John McCall550e0c22009-10-21 00:40:46 +00003774
3775 return Result;
3776}
3777
Douglas Gregor14454802011-02-25 02:25:35 +00003778template<typename Derived>
3779TypeLoc
3780TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3781 QualType ObjectType,
3782 NamedDecl *UnqualLookup,
3783 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003784 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003785 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003786
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003787 TypeSourceInfo *TSI =
3788 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3789 if (TSI)
3790 return TSI->getTypeLoc();
3791 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003792}
3793
Douglas Gregor579c15f2011-03-02 18:32:08 +00003794template<typename Derived>
3795TypeSourceInfo *
3796TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3797 QualType ObjectType,
3798 NamedDecl *UnqualLookup,
3799 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003800 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003801 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003802
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003803 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3804 UnqualLookup, SS);
3805}
3806
3807template <typename Derived>
3808TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3809 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3810 CXXScopeSpec &SS) {
3811 QualType T = TL.getType();
3812 assert(!getDerived().AlreadyTransformed(T));
3813
Douglas Gregor579c15f2011-03-02 18:32:08 +00003814 TypeLocBuilder TLB;
3815 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003816
Douglas Gregor579c15f2011-03-02 18:32:08 +00003817 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003818 TemplateSpecializationTypeLoc SpecTL =
3819 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003820
Douglas Gregor579c15f2011-03-02 18:32:08 +00003821 TemplateName Template
3822 = getDerived().TransformTemplateName(SS,
3823 SpecTL.getTypePtr()->getTemplateName(),
3824 SpecTL.getTemplateNameLoc(),
3825 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003826 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003827 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003828
3829 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003830 Template);
3831 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003832 DependentTemplateSpecializationTypeLoc SpecTL =
3833 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003834
Douglas Gregor579c15f2011-03-02 18:32:08 +00003835 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003836 = getDerived().RebuildTemplateName(SS,
3837 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003838 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003839 ObjectType, UnqualLookup);
3840 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003841 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003842
3843 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003844 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003845 Template,
3846 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003847 } else {
3848 // Nothing special needs to be done for these.
3849 Result = getDerived().TransformType(TLB, TL);
3850 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003851
3852 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003853 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003854
Douglas Gregor579c15f2011-03-02 18:32:08 +00003855 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3856}
3857
John McCall550e0c22009-10-21 00:40:46 +00003858template <class TyLoc> static inline
3859QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3860 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3861 NewT.setNameLoc(T.getNameLoc());
3862 return T.getType();
3863}
3864
John McCall550e0c22009-10-21 00:40:46 +00003865template<typename Derived>
3866QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003867 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003868 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3869 NewT.setBuiltinLoc(T.getBuiltinLoc());
3870 if (T.needsExtraLocalData())
3871 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3872 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003873}
Mike Stump11289f42009-09-09 15:08:12 +00003874
Douglas Gregord6ff3322009-08-04 16:50:30 +00003875template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003876QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003877 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003878 // FIXME: recurse?
3879 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003880}
Mike Stump11289f42009-09-09 15:08:12 +00003881
Reid Kleckner0503a872013-12-05 01:23:43 +00003882template <typename Derived>
3883QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3884 AdjustedTypeLoc TL) {
3885 // Adjustments applied during transformation are handled elsewhere.
3886 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3887}
3888
Douglas Gregord6ff3322009-08-04 16:50:30 +00003889template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003890QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3891 DecayedTypeLoc TL) {
3892 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3893 if (OriginalType.isNull())
3894 return QualType();
3895
3896 QualType Result = TL.getType();
3897 if (getDerived().AlwaysRebuild() ||
3898 OriginalType != TL.getOriginalLoc().getType())
3899 Result = SemaRef.Context.getDecayedType(OriginalType);
3900 TLB.push<DecayedTypeLoc>(Result);
3901 // Nothing to set for DecayedTypeLoc.
3902 return Result;
3903}
3904
3905template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003906QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003907 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003908 QualType PointeeType
3909 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003910 if (PointeeType.isNull())
3911 return QualType();
3912
3913 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003914 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003915 // A dependent pointer type 'T *' has is being transformed such
3916 // that an Objective-C class type is being replaced for 'T'. The
3917 // resulting pointer type is an ObjCObjectPointerType, not a
3918 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003919 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003920
John McCall8b07ec22010-05-15 11:32:37 +00003921 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3922 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003923 return Result;
3924 }
John McCall31f82722010-11-12 08:19:04 +00003925
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003926 if (getDerived().AlwaysRebuild() ||
3927 PointeeType != TL.getPointeeLoc().getType()) {
3928 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3929 if (Result.isNull())
3930 return QualType();
3931 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003932
John McCall31168b02011-06-15 23:02:42 +00003933 // Objective-C ARC can add lifetime qualifiers to the type that we're
3934 // pointing to.
3935 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003936
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003937 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3938 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003939 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003940}
Mike Stump11289f42009-09-09 15:08:12 +00003941
3942template<typename Derived>
3943QualType
John McCall550e0c22009-10-21 00:40:46 +00003944TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003945 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003946 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003947 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3948 if (PointeeType.isNull())
3949 return QualType();
3950
3951 QualType Result = TL.getType();
3952 if (getDerived().AlwaysRebuild() ||
3953 PointeeType != TL.getPointeeLoc().getType()) {
3954 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003955 TL.getSigilLoc());
3956 if (Result.isNull())
3957 return QualType();
3958 }
3959
Douglas Gregor049211a2010-04-22 16:50:51 +00003960 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003961 NewT.setSigilLoc(TL.getSigilLoc());
3962 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003963}
3964
John McCall70dd5f62009-10-30 00:06:24 +00003965/// Transforms a reference type. Note that somewhat paradoxically we
3966/// don't care whether the type itself is an l-value type or an r-value
3967/// type; we only care if the type was *written* as an l-value type
3968/// or an r-value type.
3969template<typename Derived>
3970QualType
3971TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003972 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003973 const ReferenceType *T = TL.getTypePtr();
3974
3975 // Note that this works with the pointee-as-written.
3976 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3977 if (PointeeType.isNull())
3978 return QualType();
3979
3980 QualType Result = TL.getType();
3981 if (getDerived().AlwaysRebuild() ||
3982 PointeeType != T->getPointeeTypeAsWritten()) {
3983 Result = getDerived().RebuildReferenceType(PointeeType,
3984 T->isSpelledAsLValue(),
3985 TL.getSigilLoc());
3986 if (Result.isNull())
3987 return QualType();
3988 }
3989
John McCall31168b02011-06-15 23:02:42 +00003990 // Objective-C ARC can add lifetime qualifiers to the type that we're
3991 // referring to.
3992 TLB.TypeWasModifiedSafely(
3993 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3994
John McCall70dd5f62009-10-30 00:06:24 +00003995 // r-value references can be rebuilt as l-value references.
3996 ReferenceTypeLoc NewTL;
3997 if (isa<LValueReferenceType>(Result))
3998 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3999 else
4000 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4001 NewTL.setSigilLoc(TL.getSigilLoc());
4002
4003 return Result;
4004}
4005
Mike Stump11289f42009-09-09 15:08:12 +00004006template<typename Derived>
4007QualType
John McCall550e0c22009-10-21 00:40:46 +00004008TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004009 LValueReferenceTypeLoc TL) {
4010 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004011}
4012
Mike Stump11289f42009-09-09 15:08:12 +00004013template<typename Derived>
4014QualType
John McCall550e0c22009-10-21 00:40:46 +00004015TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004016 RValueReferenceTypeLoc TL) {
4017 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004018}
Mike Stump11289f42009-09-09 15:08:12 +00004019
Douglas Gregord6ff3322009-08-04 16:50:30 +00004020template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004021QualType
John McCall550e0c22009-10-21 00:40:46 +00004022TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004023 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004024 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004025 if (PointeeType.isNull())
4026 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004027
Abramo Bagnara509357842011-03-05 14:42:21 +00004028 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004029 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004030 if (OldClsTInfo) {
4031 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4032 if (!NewClsTInfo)
4033 return QualType();
4034 }
4035
4036 const MemberPointerType *T = TL.getTypePtr();
4037 QualType OldClsType = QualType(T->getClass(), 0);
4038 QualType NewClsType;
4039 if (NewClsTInfo)
4040 NewClsType = NewClsTInfo->getType();
4041 else {
4042 NewClsType = getDerived().TransformType(OldClsType);
4043 if (NewClsType.isNull())
4044 return QualType();
4045 }
Mike Stump11289f42009-09-09 15:08:12 +00004046
John McCall550e0c22009-10-21 00:40:46 +00004047 QualType Result = TL.getType();
4048 if (getDerived().AlwaysRebuild() ||
4049 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004050 NewClsType != OldClsType) {
4051 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004052 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004053 if (Result.isNull())
4054 return QualType();
4055 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004056
Reid Kleckner0503a872013-12-05 01:23:43 +00004057 // If we had to adjust the pointee type when building a member pointer, make
4058 // sure to push TypeLoc info for it.
4059 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4060 if (MPT && PointeeType != MPT->getPointeeType()) {
4061 assert(isa<AdjustedType>(MPT->getPointeeType()));
4062 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4063 }
4064
John McCall550e0c22009-10-21 00:40:46 +00004065 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4066 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004067 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004068
4069 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004070}
4071
Mike Stump11289f42009-09-09 15:08:12 +00004072template<typename Derived>
4073QualType
John McCall550e0c22009-10-21 00:40:46 +00004074TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004075 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004076 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004077 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004078 if (ElementType.isNull())
4079 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004080
John McCall550e0c22009-10-21 00:40:46 +00004081 QualType Result = TL.getType();
4082 if (getDerived().AlwaysRebuild() ||
4083 ElementType != T->getElementType()) {
4084 Result = getDerived().RebuildConstantArrayType(ElementType,
4085 T->getSizeModifier(),
4086 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004087 T->getIndexTypeCVRQualifiers(),
4088 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004089 if (Result.isNull())
4090 return QualType();
4091 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004092
4093 // We might have either a ConstantArrayType or a VariableArrayType now:
4094 // a ConstantArrayType is allowed to have an element type which is a
4095 // VariableArrayType if the type is dependent. Fortunately, all array
4096 // types have the same location layout.
4097 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004098 NewTL.setLBracketLoc(TL.getLBracketLoc());
4099 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004100
John McCall550e0c22009-10-21 00:40:46 +00004101 Expr *Size = TL.getSizeExpr();
4102 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004103 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4104 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004105 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4106 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004107 }
4108 NewTL.setSizeExpr(Size);
4109
4110 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004111}
Mike Stump11289f42009-09-09 15:08:12 +00004112
Douglas Gregord6ff3322009-08-04 16:50:30 +00004113template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004114QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004115 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004116 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004117 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004118 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004119 if (ElementType.isNull())
4120 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004121
John McCall550e0c22009-10-21 00:40:46 +00004122 QualType Result = TL.getType();
4123 if (getDerived().AlwaysRebuild() ||
4124 ElementType != T->getElementType()) {
4125 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004126 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004127 T->getIndexTypeCVRQualifiers(),
4128 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004129 if (Result.isNull())
4130 return QualType();
4131 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004132
John McCall550e0c22009-10-21 00:40:46 +00004133 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4134 NewTL.setLBracketLoc(TL.getLBracketLoc());
4135 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004136 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004137
4138 return Result;
4139}
4140
4141template<typename Derived>
4142QualType
4143TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004144 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004145 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004146 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4147 if (ElementType.isNull())
4148 return QualType();
4149
John McCalldadc5752010-08-24 06:29:42 +00004150 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004151 = getDerived().TransformExpr(T->getSizeExpr());
4152 if (SizeResult.isInvalid())
4153 return QualType();
4154
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004155 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004156
4157 QualType Result = TL.getType();
4158 if (getDerived().AlwaysRebuild() ||
4159 ElementType != T->getElementType() ||
4160 Size != T->getSizeExpr()) {
4161 Result = getDerived().RebuildVariableArrayType(ElementType,
4162 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004163 Size,
John McCall550e0c22009-10-21 00:40:46 +00004164 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004165 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004166 if (Result.isNull())
4167 return QualType();
4168 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004169
Serge Pavlov774c6d02014-02-06 03:49:11 +00004170 // We might have constant size array now, but fortunately it has the same
4171 // location layout.
4172 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004173 NewTL.setLBracketLoc(TL.getLBracketLoc());
4174 NewTL.setRBracketLoc(TL.getRBracketLoc());
4175 NewTL.setSizeExpr(Size);
4176
4177 return Result;
4178}
4179
4180template<typename Derived>
4181QualType
4182TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004183 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004184 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004185 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4186 if (ElementType.isNull())
4187 return QualType();
4188
Richard Smith764d2fe2011-12-20 02:08:33 +00004189 // Array bounds are constant expressions.
4190 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4191 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004192
John McCall33ddac02011-01-19 10:06:00 +00004193 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4194 Expr *origSize = TL.getSizeExpr();
4195 if (!origSize) origSize = T->getSizeExpr();
4196
4197 ExprResult sizeResult
4198 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004199 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004200 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004201 return QualType();
4202
John McCall33ddac02011-01-19 10:06:00 +00004203 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004204
4205 QualType Result = TL.getType();
4206 if (getDerived().AlwaysRebuild() ||
4207 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004208 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004209 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4210 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004211 size,
John McCall550e0c22009-10-21 00:40:46 +00004212 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004213 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004214 if (Result.isNull())
4215 return QualType();
4216 }
John McCall550e0c22009-10-21 00:40:46 +00004217
4218 // We might have any sort of array type now, but fortunately they
4219 // all have the same location layout.
4220 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4221 NewTL.setLBracketLoc(TL.getLBracketLoc());
4222 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004223 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004224
4225 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004226}
Mike Stump11289f42009-09-09 15:08:12 +00004227
4228template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004229QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004230 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004231 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004232 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004233
4234 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004235 QualType ElementType = getDerived().TransformType(T->getElementType());
4236 if (ElementType.isNull())
4237 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004238
Richard Smith764d2fe2011-12-20 02:08:33 +00004239 // Vector sizes are constant expressions.
4240 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4241 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004242
John McCalldadc5752010-08-24 06:29:42 +00004243 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004244 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004245 if (Size.isInvalid())
4246 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004247
John McCall550e0c22009-10-21 00:40:46 +00004248 QualType Result = TL.getType();
4249 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004250 ElementType != T->getElementType() ||
4251 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004252 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004253 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004254 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004255 if (Result.isNull())
4256 return QualType();
4257 }
John McCall550e0c22009-10-21 00:40:46 +00004258
4259 // Result might be dependent or not.
4260 if (isa<DependentSizedExtVectorType>(Result)) {
4261 DependentSizedExtVectorTypeLoc NewTL
4262 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4263 NewTL.setNameLoc(TL.getNameLoc());
4264 } else {
4265 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4266 NewTL.setNameLoc(TL.getNameLoc());
4267 }
4268
4269 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004270}
Mike Stump11289f42009-09-09 15:08:12 +00004271
4272template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004273QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004274 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004275 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004276 QualType ElementType = getDerived().TransformType(T->getElementType());
4277 if (ElementType.isNull())
4278 return QualType();
4279
John McCall550e0c22009-10-21 00:40:46 +00004280 QualType Result = TL.getType();
4281 if (getDerived().AlwaysRebuild() ||
4282 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004283 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004284 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004285 if (Result.isNull())
4286 return QualType();
4287 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004288
John McCall550e0c22009-10-21 00:40:46 +00004289 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4290 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004291
John McCall550e0c22009-10-21 00:40:46 +00004292 return Result;
4293}
4294
4295template<typename Derived>
4296QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004297 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004298 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004299 QualType ElementType = getDerived().TransformType(T->getElementType());
4300 if (ElementType.isNull())
4301 return QualType();
4302
4303 QualType Result = TL.getType();
4304 if (getDerived().AlwaysRebuild() ||
4305 ElementType != T->getElementType()) {
4306 Result = getDerived().RebuildExtVectorType(ElementType,
4307 T->getNumElements(),
4308 /*FIXME*/ SourceLocation());
4309 if (Result.isNull())
4310 return QualType();
4311 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004312
John McCall550e0c22009-10-21 00:40:46 +00004313 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4314 NewTL.setNameLoc(TL.getNameLoc());
4315
4316 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004317}
Mike Stump11289f42009-09-09 15:08:12 +00004318
David Blaikie05785d12013-02-20 22:23:23 +00004319template <typename Derived>
4320ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4321 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4322 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004323 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004324 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004325
Douglas Gregor715e4612011-01-14 22:40:04 +00004326 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004327 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004328 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004329 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004330 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004331
Douglas Gregor715e4612011-01-14 22:40:04 +00004332 TypeLocBuilder TLB;
4333 TypeLoc NewTL = OldDI->getTypeLoc();
4334 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004335
4336 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004337 OldExpansionTL.getPatternLoc());
4338 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004339 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004340
4341 Result = RebuildPackExpansionType(Result,
4342 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004343 OldExpansionTL.getEllipsisLoc(),
4344 NumExpansions);
4345 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004346 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004347
Douglas Gregor715e4612011-01-14 22:40:04 +00004348 PackExpansionTypeLoc NewExpansionTL
4349 = TLB.push<PackExpansionTypeLoc>(Result);
4350 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4351 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4352 } else
4353 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004354 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004355 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004356
John McCall8fb0d9d2011-05-01 22:35:37 +00004357 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004358 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004359
4360 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4361 OldParm->getDeclContext(),
4362 OldParm->getInnerLocStart(),
4363 OldParm->getLocation(),
4364 OldParm->getIdentifier(),
4365 NewDI->getType(),
4366 NewDI,
4367 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004368 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004369 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4370 OldParm->getFunctionScopeIndex() + indexAdjustment);
4371 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004372}
4373
4374template<typename Derived>
4375bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004376 TransformFunctionTypeParams(SourceLocation Loc,
4377 ParmVarDecl **Params, unsigned NumParams,
4378 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004379 SmallVectorImpl<QualType> &OutParamTypes,
4380 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004381 int indexAdjustment = 0;
4382
Douglas Gregordd472162011-01-07 00:20:55 +00004383 for (unsigned i = 0; i != NumParams; ++i) {
4384 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004385 assert(OldParm->getFunctionScopeIndex() == i);
4386
David Blaikie05785d12013-02-20 22:23:23 +00004387 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004388 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004389 if (OldParm->isParameterPack()) {
4390 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004391 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004392
Douglas Gregor5499af42011-01-05 23:12:31 +00004393 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004394 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004395 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004396 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4397 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004398 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4399
Douglas Gregor5499af42011-01-05 23:12:31 +00004400 // Determine whether we should expand the parameter packs.
4401 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004402 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004403 Optional<unsigned> OrigNumExpansions =
4404 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004405 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004406 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4407 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004408 Unexpanded,
4409 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004410 RetainExpansion,
4411 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004412 return true;
4413 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004414
Douglas Gregor5499af42011-01-05 23:12:31 +00004415 if (ShouldExpand) {
4416 // Expand the function parameter pack into multiple, separate
4417 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004418 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004419 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004420 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004421 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004422 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004423 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004424 OrigNumExpansions,
4425 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004426 if (!NewParm)
4427 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004428
Douglas Gregordd472162011-01-07 00:20:55 +00004429 OutParamTypes.push_back(NewParm->getType());
4430 if (PVars)
4431 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004432 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004433
4434 // If we're supposed to retain a pack expansion, do so by temporarily
4435 // forgetting the partially-substituted parameter pack.
4436 if (RetainExpansion) {
4437 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004438 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004439 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004440 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004441 OrigNumExpansions,
4442 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004443 if (!NewParm)
4444 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004445
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004446 OutParamTypes.push_back(NewParm->getType());
4447 if (PVars)
4448 PVars->push_back(NewParm);
4449 }
4450
John McCall8fb0d9d2011-05-01 22:35:37 +00004451 // The next parameter should have the same adjustment as the
4452 // last thing we pushed, but we post-incremented indexAdjustment
4453 // on every push. Also, if we push nothing, the adjustment should
4454 // go down by one.
4455 indexAdjustment--;
4456
Douglas Gregor5499af42011-01-05 23:12:31 +00004457 // We're done with the pack expansion.
4458 continue;
4459 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004460
4461 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004462 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004463 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4464 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004465 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004466 NumExpansions,
4467 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004468 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004469 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004470 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004471 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004472
John McCall58f10c32010-03-11 09:03:00 +00004473 if (!NewParm)
4474 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004475
Douglas Gregordd472162011-01-07 00:20:55 +00004476 OutParamTypes.push_back(NewParm->getType());
4477 if (PVars)
4478 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004479 continue;
4480 }
John McCall58f10c32010-03-11 09:03:00 +00004481
4482 // Deal with the possibility that we don't have a parameter
4483 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004484 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004485 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004486 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004487 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004488 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004489 = dyn_cast<PackExpansionType>(OldType)) {
4490 // We have a function parameter pack that may need to be expanded.
4491 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004492 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004493 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004494
Douglas Gregor5499af42011-01-05 23:12:31 +00004495 // Determine whether we should expand the parameter packs.
4496 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004497 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004498 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004499 Unexpanded,
4500 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004501 RetainExpansion,
4502 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004503 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004504 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004505
Douglas Gregor5499af42011-01-05 23:12:31 +00004506 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004507 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004508 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004509 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004510 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4511 QualType NewType = getDerived().TransformType(Pattern);
4512 if (NewType.isNull())
4513 return true;
John McCall58f10c32010-03-11 09:03:00 +00004514
Douglas Gregordd472162011-01-07 00:20:55 +00004515 OutParamTypes.push_back(NewType);
4516 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004517 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004518 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004519
Douglas Gregor5499af42011-01-05 23:12:31 +00004520 // We're done with the pack expansion.
4521 continue;
4522 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004523
Douglas Gregor48d24112011-01-10 20:53:55 +00004524 // If we're supposed to retain a pack expansion, do so by temporarily
4525 // forgetting the partially-substituted parameter pack.
4526 if (RetainExpansion) {
4527 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4528 QualType NewType = getDerived().TransformType(Pattern);
4529 if (NewType.isNull())
4530 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004531
Douglas Gregor48d24112011-01-10 20:53:55 +00004532 OutParamTypes.push_back(NewType);
4533 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004534 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004535 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004536
Chad Rosier1dcde962012-08-08 18:46:20 +00004537 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004538 // expansion.
4539 OldType = Expansion->getPattern();
4540 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004541 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4542 NewType = getDerived().TransformType(OldType);
4543 } else {
4544 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004545 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004546
Douglas Gregor5499af42011-01-05 23:12:31 +00004547 if (NewType.isNull())
4548 return true;
4549
4550 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004551 NewType = getSema().Context.getPackExpansionType(NewType,
4552 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004553
Douglas Gregordd472162011-01-07 00:20:55 +00004554 OutParamTypes.push_back(NewType);
4555 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004556 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004557 }
4558
John McCall8fb0d9d2011-05-01 22:35:37 +00004559#ifndef NDEBUG
4560 if (PVars) {
4561 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4562 if (ParmVarDecl *parm = (*PVars)[i])
4563 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004564 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004565#endif
4566
4567 return false;
4568}
John McCall58f10c32010-03-11 09:03:00 +00004569
4570template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004571QualType
John McCall550e0c22009-10-21 00:40:46 +00004572TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004573 FunctionProtoTypeLoc TL) {
NAKAMURA Takumi23224152014-10-17 12:48:37 +00004574 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
Douglas Gregor3024f072012-04-16 07:05:22 +00004575}
4576
NAKAMURA Takumi23224152014-10-17 12:48:37 +00004577template<typename Derived>
4578QualType
4579TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4580 FunctionProtoTypeLoc TL,
4581 CXXRecordDecl *ThisContext,
4582 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004583 // Transform the parameters and return type.
4584 //
Richard Smithf623c962012-04-17 00:58:00 +00004585 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004586 // When the function has a trailing return type, we instantiate the
4587 // parameters before the return type, since the return type can then refer
4588 // to the parameters themselves (via decltype, sizeof, etc.).
4589 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004590 SmallVector<QualType, 4> ParamTypes;
4591 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004592 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004593
Douglas Gregor7fb25412010-10-01 18:44:50 +00004594 QualType ResultType;
4595
Richard Smith1226c602012-08-14 22:51:13 +00004596 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004597 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004598 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004599 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004600 return QualType();
4601
Douglas Gregor3024f072012-04-16 07:05:22 +00004602 {
4603 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004604 // If a declaration declares a member function or member function
4605 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004606 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004607 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004608 // declarator.
4609 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004610
Alp Toker42a16a62014-01-25 23:51:36 +00004611 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004612 if (ResultType.isNull())
4613 return QualType();
4614 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004615 }
4616 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004617 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004618 if (ResultType.isNull())
4619 return QualType();
4620
Alp Toker9cacbab2014-01-20 20:26:09 +00004621 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004622 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004623 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004624 return QualType();
4625 }
4626
NAKAMURA Takumi23224152014-10-17 12:48:37 +00004627 // FIXME: Need to transform the exception-specification too.
Richard Smithf623c962012-04-17 00:58:00 +00004628
John McCall550e0c22009-10-21 00:40:46 +00004629 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004630 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004631 T->getNumParams() != ParamTypes.size() ||
4632 !std::equal(T->param_type_begin(), T->param_type_end(),
NAKAMURA Takumi23224152014-10-17 12:48:37 +00004633 ParamTypes.begin())) {
4634 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
4635 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004636 if (Result.isNull())
4637 return QualType();
4638 }
Mike Stump11289f42009-09-09 15:08:12 +00004639
John McCall550e0c22009-10-21 00:40:46 +00004640 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004641 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004642 NewTL.setLParenLoc(TL.getLParenLoc());
4643 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004644 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004645 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4646 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004647
4648 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004649}
Mike Stump11289f42009-09-09 15:08:12 +00004650
Douglas Gregord6ff3322009-08-04 16:50:30 +00004651template<typename Derived>
4652QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004653 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004654 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004655 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004656 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004657 if (ResultType.isNull())
4658 return QualType();
4659
4660 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004661 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004662 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4663
4664 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004665 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004666 NewTL.setLParenLoc(TL.getLParenLoc());
4667 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004668 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004669
4670 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004671}
Mike Stump11289f42009-09-09 15:08:12 +00004672
John McCallb96ec562009-12-04 22:46:56 +00004673template<typename Derived> QualType
4674TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004675 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004676 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004677 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004678 if (!D)
4679 return QualType();
4680
4681 QualType Result = TL.getType();
4682 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4683 Result = getDerived().RebuildUnresolvedUsingType(D);
4684 if (Result.isNull())
4685 return QualType();
4686 }
4687
4688 // We might get an arbitrary type spec type back. We should at
4689 // least always get a type spec type, though.
4690 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4691 NewTL.setNameLoc(TL.getNameLoc());
4692
4693 return Result;
4694}
4695
Douglas Gregord6ff3322009-08-04 16:50:30 +00004696template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004697QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004698 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004699 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004700 TypedefNameDecl *Typedef
4701 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4702 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004703 if (!Typedef)
4704 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004705
John McCall550e0c22009-10-21 00:40:46 +00004706 QualType Result = TL.getType();
4707 if (getDerived().AlwaysRebuild() ||
4708 Typedef != T->getDecl()) {
4709 Result = getDerived().RebuildTypedefType(Typedef);
4710 if (Result.isNull())
4711 return QualType();
4712 }
Mike Stump11289f42009-09-09 15:08:12 +00004713
John McCall550e0c22009-10-21 00:40:46 +00004714 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4715 NewTL.setNameLoc(TL.getNameLoc());
4716
4717 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004718}
Mike Stump11289f42009-09-09 15:08:12 +00004719
Douglas Gregord6ff3322009-08-04 16:50:30 +00004720template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004721QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004722 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004723 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004724 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4725 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004726
John McCalldadc5752010-08-24 06:29:42 +00004727 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004728 if (E.isInvalid())
4729 return QualType();
4730
Eli Friedmane4f22df2012-02-29 04:03:55 +00004731 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4732 if (E.isInvalid())
4733 return QualType();
4734
John McCall550e0c22009-10-21 00:40:46 +00004735 QualType Result = TL.getType();
4736 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004737 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004738 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004739 if (Result.isNull())
4740 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004741 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004742 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004743
John McCall550e0c22009-10-21 00:40:46 +00004744 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004745 NewTL.setTypeofLoc(TL.getTypeofLoc());
4746 NewTL.setLParenLoc(TL.getLParenLoc());
4747 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004748
4749 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004750}
Mike Stump11289f42009-09-09 15:08:12 +00004751
4752template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004753QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004754 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004755 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4756 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4757 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004758 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004759
John McCall550e0c22009-10-21 00:40:46 +00004760 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004761 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4762 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004763 if (Result.isNull())
4764 return QualType();
4765 }
Mike Stump11289f42009-09-09 15:08:12 +00004766
John McCall550e0c22009-10-21 00:40:46 +00004767 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004768 NewTL.setTypeofLoc(TL.getTypeofLoc());
4769 NewTL.setLParenLoc(TL.getLParenLoc());
4770 NewTL.setRParenLoc(TL.getRParenLoc());
4771 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004772
4773 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004774}
Mike Stump11289f42009-09-09 15:08:12 +00004775
4776template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004777QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004778 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004779 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004780
Douglas Gregore922c772009-08-04 22:27:00 +00004781 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004782 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4783 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004784
John McCalldadc5752010-08-24 06:29:42 +00004785 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004786 if (E.isInvalid())
4787 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004788
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004789 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004790 if (E.isInvalid())
4791 return QualType();
4792
John McCall550e0c22009-10-21 00:40:46 +00004793 QualType Result = TL.getType();
4794 if (getDerived().AlwaysRebuild() ||
4795 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004796 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004797 if (Result.isNull())
4798 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004799 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004800 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004801
John McCall550e0c22009-10-21 00:40:46 +00004802 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4803 NewTL.setNameLoc(TL.getNameLoc());
4804
4805 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004806}
4807
4808template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004809QualType TreeTransform<Derived>::TransformUnaryTransformType(
4810 TypeLocBuilder &TLB,
4811 UnaryTransformTypeLoc TL) {
4812 QualType Result = TL.getType();
4813 if (Result->isDependentType()) {
4814 const UnaryTransformType *T = TL.getTypePtr();
4815 QualType NewBase =
4816 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4817 Result = getDerived().RebuildUnaryTransformType(NewBase,
4818 T->getUTTKind(),
4819 TL.getKWLoc());
4820 if (Result.isNull())
4821 return QualType();
4822 }
4823
4824 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4825 NewTL.setKWLoc(TL.getKWLoc());
4826 NewTL.setParensRange(TL.getParensRange());
4827 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4828 return Result;
4829}
4830
4831template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004832QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4833 AutoTypeLoc TL) {
4834 const AutoType *T = TL.getTypePtr();
4835 QualType OldDeduced = T->getDeducedType();
4836 QualType NewDeduced;
4837 if (!OldDeduced.isNull()) {
4838 NewDeduced = getDerived().TransformType(OldDeduced);
4839 if (NewDeduced.isNull())
4840 return QualType();
4841 }
4842
4843 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004844 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4845 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004846 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004847 if (Result.isNull())
4848 return QualType();
4849 }
4850
4851 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4852 NewTL.setNameLoc(TL.getNameLoc());
4853
4854 return Result;
4855}
4856
4857template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004858QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004859 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004860 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004861 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004862 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4863 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004864 if (!Record)
4865 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004866
John McCall550e0c22009-10-21 00:40:46 +00004867 QualType Result = TL.getType();
4868 if (getDerived().AlwaysRebuild() ||
4869 Record != T->getDecl()) {
4870 Result = getDerived().RebuildRecordType(Record);
4871 if (Result.isNull())
4872 return QualType();
4873 }
Mike Stump11289f42009-09-09 15:08:12 +00004874
John McCall550e0c22009-10-21 00:40:46 +00004875 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4876 NewTL.setNameLoc(TL.getNameLoc());
4877
4878 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004879}
Mike Stump11289f42009-09-09 15:08:12 +00004880
4881template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004882QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004883 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004884 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004885 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004886 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4887 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004888 if (!Enum)
4889 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004890
John McCall550e0c22009-10-21 00:40:46 +00004891 QualType Result = TL.getType();
4892 if (getDerived().AlwaysRebuild() ||
4893 Enum != T->getDecl()) {
4894 Result = getDerived().RebuildEnumType(Enum);
4895 if (Result.isNull())
4896 return QualType();
4897 }
Mike Stump11289f42009-09-09 15:08:12 +00004898
John McCall550e0c22009-10-21 00:40:46 +00004899 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4900 NewTL.setNameLoc(TL.getNameLoc());
4901
4902 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004903}
John McCallfcc33b02009-09-05 00:15:47 +00004904
John McCalle78aac42010-03-10 03:28:59 +00004905template<typename Derived>
4906QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4907 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004908 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004909 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4910 TL.getTypePtr()->getDecl());
4911 if (!D) return QualType();
4912
4913 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4914 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4915 return T;
4916}
4917
Douglas Gregord6ff3322009-08-04 16:50:30 +00004918template<typename Derived>
4919QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004920 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004921 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004922 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004923}
4924
Mike Stump11289f42009-09-09 15:08:12 +00004925template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004926QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004927 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004928 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004929 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004930
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004931 // Substitute into the replacement type, which itself might involve something
4932 // that needs to be transformed. This only tends to occur with default
4933 // template arguments of template template parameters.
4934 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4935 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4936 if (Replacement.isNull())
4937 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004938
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004939 // Always canonicalize the replacement type.
4940 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4941 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004942 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004943 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004944
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004945 // Propagate type-source information.
4946 SubstTemplateTypeParmTypeLoc NewTL
4947 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4948 NewTL.setNameLoc(TL.getNameLoc());
4949 return Result;
4950
John McCallcebee162009-10-18 09:09:24 +00004951}
4952
4953template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004954QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4955 TypeLocBuilder &TLB,
4956 SubstTemplateTypeParmPackTypeLoc TL) {
4957 return TransformTypeSpecType(TLB, TL);
4958}
4959
4960template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004961QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004962 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004963 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004964 const TemplateSpecializationType *T = TL.getTypePtr();
4965
Douglas Gregordf846d12011-03-02 18:46:51 +00004966 // The nested-name-specifier never matters in a TemplateSpecializationType,
4967 // because we can't have a dependent nested-name-specifier anyway.
4968 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004969 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004970 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4971 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004972 if (Template.isNull())
4973 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004974
John McCall31f82722010-11-12 08:19:04 +00004975 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4976}
4977
Eli Friedman0dfb8892011-10-06 23:00:33 +00004978template<typename Derived>
4979QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4980 AtomicTypeLoc TL) {
4981 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4982 if (ValueType.isNull())
4983 return QualType();
4984
4985 QualType Result = TL.getType();
4986 if (getDerived().AlwaysRebuild() ||
4987 ValueType != TL.getValueLoc().getType()) {
4988 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4989 if (Result.isNull())
4990 return QualType();
4991 }
4992
4993 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4994 NewTL.setKWLoc(TL.getKWLoc());
4995 NewTL.setLParenLoc(TL.getLParenLoc());
4996 NewTL.setRParenLoc(TL.getRParenLoc());
4997
4998 return Result;
4999}
5000
Chad Rosier1dcde962012-08-08 18:46:20 +00005001 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005002 /// container that provides a \c getArgLoc() member function.
5003 ///
5004 /// This iterator is intended to be used with the iterator form of
5005 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5006 template<typename ArgLocContainer>
5007 class TemplateArgumentLocContainerIterator {
5008 ArgLocContainer *Container;
5009 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005010
Douglas Gregorfe921a72010-12-20 23:36:19 +00005011 public:
5012 typedef TemplateArgumentLoc value_type;
5013 typedef TemplateArgumentLoc reference;
5014 typedef int difference_type;
5015 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005016
Douglas Gregorfe921a72010-12-20 23:36:19 +00005017 class pointer {
5018 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005019
Douglas Gregorfe921a72010-12-20 23:36:19 +00005020 public:
5021 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005022
Douglas Gregorfe921a72010-12-20 23:36:19 +00005023 const TemplateArgumentLoc *operator->() const {
5024 return &Arg;
5025 }
5026 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005027
5028
Douglas Gregorfe921a72010-12-20 23:36:19 +00005029 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005030
Douglas Gregorfe921a72010-12-20 23:36:19 +00005031 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5032 unsigned Index)
5033 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005034
Douglas Gregorfe921a72010-12-20 23:36:19 +00005035 TemplateArgumentLocContainerIterator &operator++() {
5036 ++Index;
5037 return *this;
5038 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005039
Douglas Gregorfe921a72010-12-20 23:36:19 +00005040 TemplateArgumentLocContainerIterator operator++(int) {
5041 TemplateArgumentLocContainerIterator Old(*this);
5042 ++(*this);
5043 return Old;
5044 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005045
Douglas Gregorfe921a72010-12-20 23:36:19 +00005046 TemplateArgumentLoc operator*() const {
5047 return Container->getArgLoc(Index);
5048 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005049
Douglas Gregorfe921a72010-12-20 23:36:19 +00005050 pointer operator->() const {
5051 return pointer(Container->getArgLoc(Index));
5052 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005053
Douglas Gregorfe921a72010-12-20 23:36:19 +00005054 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005055 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005056 return X.Container == Y.Container && X.Index == Y.Index;
5057 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005058
Douglas Gregorfe921a72010-12-20 23:36:19 +00005059 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005060 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005061 return !(X == Y);
5062 }
5063 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005064
5065
John McCall31f82722010-11-12 08:19:04 +00005066template <typename Derived>
5067QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5068 TypeLocBuilder &TLB,
5069 TemplateSpecializationTypeLoc TL,
5070 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005071 TemplateArgumentListInfo NewTemplateArgs;
5072 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5073 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005074 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5075 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005076 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005077 ArgIterator(TL, TL.getNumArgs()),
5078 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005079 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005080
John McCall0ad16662009-10-29 08:12:44 +00005081 // FIXME: maybe don't rebuild if all the template arguments are the same.
5082
5083 QualType Result =
5084 getDerived().RebuildTemplateSpecializationType(Template,
5085 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005086 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005087
5088 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005089 // Specializations of template template parameters are represented as
5090 // TemplateSpecializationTypes, and substitution of type alias templates
5091 // within a dependent context can transform them into
5092 // DependentTemplateSpecializationTypes.
5093 if (isa<DependentTemplateSpecializationType>(Result)) {
5094 DependentTemplateSpecializationTypeLoc NewTL
5095 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005096 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005097 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005098 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005099 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005100 NewTL.setLAngleLoc(TL.getLAngleLoc());
5101 NewTL.setRAngleLoc(TL.getRAngleLoc());
5102 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5103 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5104 return Result;
5105 }
5106
John McCall0ad16662009-10-29 08:12:44 +00005107 TemplateSpecializationTypeLoc NewTL
5108 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005109 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005110 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5111 NewTL.setLAngleLoc(TL.getLAngleLoc());
5112 NewTL.setRAngleLoc(TL.getRAngleLoc());
5113 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5114 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005115 }
Mike Stump11289f42009-09-09 15:08:12 +00005116
John McCall0ad16662009-10-29 08:12:44 +00005117 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005118}
Mike Stump11289f42009-09-09 15:08:12 +00005119
Douglas Gregor5a064722011-02-28 17:23:35 +00005120template <typename Derived>
5121QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5122 TypeLocBuilder &TLB,
5123 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005124 TemplateName Template,
5125 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005126 TemplateArgumentListInfo NewTemplateArgs;
5127 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5128 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5129 typedef TemplateArgumentLocContainerIterator<
5130 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005131 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005132 ArgIterator(TL, TL.getNumArgs()),
5133 NewTemplateArgs))
5134 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005135
Douglas Gregor5a064722011-02-28 17:23:35 +00005136 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005137
Douglas Gregor5a064722011-02-28 17:23:35 +00005138 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5139 QualType Result
5140 = getSema().Context.getDependentTemplateSpecializationType(
5141 TL.getTypePtr()->getKeyword(),
5142 DTN->getQualifier(),
5143 DTN->getIdentifier(),
5144 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005145
Douglas Gregor5a064722011-02-28 17:23:35 +00005146 DependentTemplateSpecializationTypeLoc NewTL
5147 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005148 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005149 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005150 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005151 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005152 NewTL.setLAngleLoc(TL.getLAngleLoc());
5153 NewTL.setRAngleLoc(TL.getRAngleLoc());
5154 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5155 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5156 return Result;
5157 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005158
5159 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005160 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005161 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005162 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005163
Douglas Gregor5a064722011-02-28 17:23:35 +00005164 if (!Result.isNull()) {
5165 /// FIXME: Wrap this in an elaborated-type-specifier?
5166 TemplateSpecializationTypeLoc NewTL
5167 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005168 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005169 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005170 NewTL.setLAngleLoc(TL.getLAngleLoc());
5171 NewTL.setRAngleLoc(TL.getRAngleLoc());
5172 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5173 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5174 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005175
Douglas Gregor5a064722011-02-28 17:23:35 +00005176 return Result;
5177}
5178
Mike Stump11289f42009-09-09 15:08:12 +00005179template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005180QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005181TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005182 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005183 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005184
Douglas Gregor844cb502011-03-01 18:12:44 +00005185 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005186 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005187 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005188 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005189 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5190 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005191 return QualType();
5192 }
Mike Stump11289f42009-09-09 15:08:12 +00005193
John McCall31f82722010-11-12 08:19:04 +00005194 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5195 if (NamedT.isNull())
5196 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005197
Richard Smith3f1b5d02011-05-05 21:57:07 +00005198 // C++0x [dcl.type.elab]p2:
5199 // If the identifier resolves to a typedef-name or the simple-template-id
5200 // resolves to an alias template specialization, the
5201 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005202 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5203 if (const TemplateSpecializationType *TST =
5204 NamedT->getAs<TemplateSpecializationType>()) {
5205 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005206 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5207 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005208 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5209 diag::err_tag_reference_non_tag) << 4;
5210 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5211 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005212 }
5213 }
5214
John McCall550e0c22009-10-21 00:40:46 +00005215 QualType Result = TL.getType();
5216 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005217 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005218 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005219 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005220 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005221 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005222 if (Result.isNull())
5223 return QualType();
5224 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005225
Abramo Bagnara6150c882010-05-11 21:36:43 +00005226 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005227 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005228 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005229 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005230}
Mike Stump11289f42009-09-09 15:08:12 +00005231
5232template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005233QualType TreeTransform<Derived>::TransformAttributedType(
5234 TypeLocBuilder &TLB,
5235 AttributedTypeLoc TL) {
5236 const AttributedType *oldType = TL.getTypePtr();
5237 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5238 if (modifiedType.isNull())
5239 return QualType();
5240
5241 QualType result = TL.getType();
5242
5243 // FIXME: dependent operand expressions?
5244 if (getDerived().AlwaysRebuild() ||
5245 modifiedType != oldType->getModifiedType()) {
5246 // TODO: this is really lame; we should really be rebuilding the
5247 // equivalent type from first principles.
5248 QualType equivalentType
5249 = getDerived().TransformType(oldType->getEquivalentType());
5250 if (equivalentType.isNull())
5251 return QualType();
5252 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5253 modifiedType,
5254 equivalentType);
5255 }
5256
5257 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5258 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5259 if (TL.hasAttrOperand())
5260 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5261 if (TL.hasAttrExprOperand())
5262 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5263 else if (TL.hasAttrEnumOperand())
5264 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5265
5266 return result;
5267}
5268
5269template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005270QualType
5271TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5272 ParenTypeLoc TL) {
5273 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5274 if (Inner.isNull())
5275 return QualType();
5276
5277 QualType Result = TL.getType();
5278 if (getDerived().AlwaysRebuild() ||
5279 Inner != TL.getInnerLoc().getType()) {
5280 Result = getDerived().RebuildParenType(Inner);
5281 if (Result.isNull())
5282 return QualType();
5283 }
5284
5285 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5286 NewTL.setLParenLoc(TL.getLParenLoc());
5287 NewTL.setRParenLoc(TL.getRParenLoc());
5288 return Result;
5289}
5290
5291template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005292QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005293 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005294 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005295
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005296 NestedNameSpecifierLoc QualifierLoc
5297 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5298 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005299 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005300
John McCallc392f372010-06-11 00:33:02 +00005301 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005302 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005303 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005304 QualifierLoc,
5305 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005306 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005307 if (Result.isNull())
5308 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005309
Abramo Bagnarad7548482010-05-19 21:37:53 +00005310 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5311 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005312 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5313
Abramo Bagnarad7548482010-05-19 21:37:53 +00005314 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005315 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005316 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005317 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005318 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005319 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005320 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005321 NewTL.setNameLoc(TL.getNameLoc());
5322 }
John McCall550e0c22009-10-21 00:40:46 +00005323 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005324}
Mike Stump11289f42009-09-09 15:08:12 +00005325
Douglas Gregord6ff3322009-08-04 16:50:30 +00005326template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005327QualType TreeTransform<Derived>::
5328 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005329 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005330 NestedNameSpecifierLoc QualifierLoc;
5331 if (TL.getQualifierLoc()) {
5332 QualifierLoc
5333 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5334 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005335 return QualType();
5336 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005337
John McCall31f82722010-11-12 08:19:04 +00005338 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005339 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005340}
5341
5342template<typename Derived>
5343QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005344TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5345 DependentTemplateSpecializationTypeLoc TL,
5346 NestedNameSpecifierLoc QualifierLoc) {
5347 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005348
Douglas Gregora7a795b2011-03-01 20:11:18 +00005349 TemplateArgumentListInfo NewTemplateArgs;
5350 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5351 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005352
Douglas Gregora7a795b2011-03-01 20:11:18 +00005353 typedef TemplateArgumentLocContainerIterator<
5354 DependentTemplateSpecializationTypeLoc> ArgIterator;
5355 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5356 ArgIterator(TL, TL.getNumArgs()),
5357 NewTemplateArgs))
5358 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005359
Douglas Gregora7a795b2011-03-01 20:11:18 +00005360 QualType Result
5361 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5362 QualifierLoc,
5363 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005364 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005365 NewTemplateArgs);
5366 if (Result.isNull())
5367 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005368
Douglas Gregora7a795b2011-03-01 20:11:18 +00005369 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5370 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005371
Douglas Gregora7a795b2011-03-01 20:11:18 +00005372 // Copy information relevant to the template specialization.
5373 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005374 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005375 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005376 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005377 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5378 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005379 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005380 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005381
Douglas Gregora7a795b2011-03-01 20:11:18 +00005382 // Copy information relevant to the elaborated type.
5383 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005384 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005385 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005386 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5387 DependentTemplateSpecializationTypeLoc SpecTL
5388 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005389 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005390 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005391 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005392 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005393 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5394 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005395 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005396 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005397 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005398 TemplateSpecializationTypeLoc SpecTL
5399 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005400 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005401 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005402 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5403 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005404 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005405 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005406 }
5407 return Result;
5408}
5409
5410template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005411QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5412 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005413 QualType Pattern
5414 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005415 if (Pattern.isNull())
5416 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005417
5418 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005419 if (getDerived().AlwaysRebuild() ||
5420 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005421 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005422 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005423 TL.getEllipsisLoc(),
5424 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005425 if (Result.isNull())
5426 return QualType();
5427 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005428
Douglas Gregor822d0302011-01-12 17:07:58 +00005429 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5430 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5431 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005432}
5433
5434template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005435QualType
5436TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005437 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005438 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005439 TLB.pushFullCopy(TL);
5440 return TL.getType();
5441}
5442
5443template<typename Derived>
5444QualType
5445TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005446 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005447 // ObjCObjectType is never dependent.
5448 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005449 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005450}
Mike Stump11289f42009-09-09 15:08:12 +00005451
5452template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005453QualType
5454TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005455 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005456 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005457 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005458 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005459}
5460
Douglas Gregord6ff3322009-08-04 16:50:30 +00005461//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005462// Statement transformation
5463//===----------------------------------------------------------------------===//
5464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005465StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005466TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005467 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005468}
5469
5470template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005471StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005472TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5473 return getDerived().TransformCompoundStmt(S, false);
5474}
5475
5476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005477StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005478TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005479 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005480 Sema::CompoundScopeRAII CompoundScope(getSema());
5481
John McCall1ababa62010-08-27 19:56:05 +00005482 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005483 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005484 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005485 for (auto *B : S->body()) {
5486 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005487 if (Result.isInvalid()) {
5488 // Immediately fail if this was a DeclStmt, since it's very
5489 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005490 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005491 return StmtError();
5492
5493 // Otherwise, just keep processing substatements and fail later.
5494 SubStmtInvalid = true;
5495 continue;
5496 }
Mike Stump11289f42009-09-09 15:08:12 +00005497
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005498 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005499 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005500 }
Mike Stump11289f42009-09-09 15:08:12 +00005501
John McCall1ababa62010-08-27 19:56:05 +00005502 if (SubStmtInvalid)
5503 return StmtError();
5504
Douglas Gregorebe10102009-08-20 07:17:43 +00005505 if (!getDerived().AlwaysRebuild() &&
5506 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005507 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005508
5509 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005510 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005511 S->getRBracLoc(),
5512 IsStmtExpr);
5513}
Mike Stump11289f42009-09-09 15:08:12 +00005514
Douglas Gregorebe10102009-08-20 07:17:43 +00005515template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005516StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005517TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005518 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005519 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005520 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5521 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005522
Eli Friedman06577382009-11-19 03:14:00 +00005523 // Transform the left-hand case value.
5524 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005525 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005526 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005527 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005528
Eli Friedman06577382009-11-19 03:14:00 +00005529 // Transform the right-hand case value (for the GNU case-range extension).
5530 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005531 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005532 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005533 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005534 }
Mike Stump11289f42009-09-09 15:08:12 +00005535
Douglas Gregorebe10102009-08-20 07:17:43 +00005536 // Build the case statement.
5537 // Case statements are always rebuilt so that they will attached to their
5538 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005539 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005540 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005541 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005542 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005543 S->getColonLoc());
5544 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005545 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005546
Douglas Gregorebe10102009-08-20 07:17:43 +00005547 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005548 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005549 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005550 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005551
Douglas Gregorebe10102009-08-20 07:17:43 +00005552 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005553 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005554}
5555
5556template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005557StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005558TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005559 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005560 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005561 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005562 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005563
Douglas Gregorebe10102009-08-20 07:17:43 +00005564 // Default statements are always rebuilt
5565 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005566 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005567}
Mike Stump11289f42009-09-09 15:08:12 +00005568
Douglas Gregorebe10102009-08-20 07:17:43 +00005569template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005570StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005571TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005572 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005573 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005574 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005575
Chris Lattnercab02a62011-02-17 20:34:02 +00005576 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5577 S->getDecl());
5578 if (!LD)
5579 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005580
5581
Douglas Gregorebe10102009-08-20 07:17:43 +00005582 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005583 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005584 cast<LabelDecl>(LD), SourceLocation(),
5585 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005586}
Mike Stump11289f42009-09-09 15:08:12 +00005587
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005588template <typename Derived>
5589const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
5590 if (!R)
5591 return R;
5592
5593 switch (R->getKind()) {
5594// Transform attributes with a pragma spelling by calling TransformXXXAttr.
5595#define ATTR(X)
5596#define PRAGMA_SPELLING_ATTR(X) \
5597 case attr::X: \
5598 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
5599#include "clang/Basic/AttrList.inc"
5600 default:
5601 return R;
5602 }
5603}
5604
5605template <typename Derived>
5606StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5607 bool AttrsChanged = false;
5608 SmallVector<const Attr *, 1> Attrs;
5609
5610 // Visit attributes and keep track if any are transformed.
5611 for (const auto *I : S->getAttrs()) {
5612 const Attr *R = getDerived().TransformAttr(I);
5613 AttrsChanged |= (I != R);
5614 Attrs.push_back(R);
5615 }
5616
Richard Smithc202b282012-04-14 00:33:13 +00005617 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5618 if (SubStmt.isInvalid())
5619 return StmtError();
5620
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005621 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00005622 return S;
5623
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005624 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00005625 SubStmt.get());
5626}
5627
5628template<typename Derived>
5629StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005630TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005631 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005632 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005633 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005634 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005635 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005636 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005637 getDerived().TransformDefinition(
5638 S->getConditionVariable()->getLocation(),
5639 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005640 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005641 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005642 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005643 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005644
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005645 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005646 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005647
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005648 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005649 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005650 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005651 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005652 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005653 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005654
John McCallb268a282010-08-23 23:25:46 +00005655 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005656 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005657 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005658
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005659 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005660 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005661 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005662
Douglas Gregorebe10102009-08-20 07:17:43 +00005663 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005664 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005665 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005666 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005667
Douglas Gregorebe10102009-08-20 07:17:43 +00005668 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005669 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005670 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005671 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005672
Douglas Gregorebe10102009-08-20 07:17:43 +00005673 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005674 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005675 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005676 Then.get() == S->getThen() &&
5677 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005678 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005679
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005680 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005681 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005682 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005683}
5684
5685template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005686StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005687TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005688 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005689 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005690 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005691 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005692 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005693 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005694 getDerived().TransformDefinition(
5695 S->getConditionVariable()->getLocation(),
5696 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005697 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005698 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005699 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005700 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005701
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005702 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005703 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005704 }
Mike Stump11289f42009-09-09 15:08:12 +00005705
Douglas Gregorebe10102009-08-20 07:17:43 +00005706 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005707 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005708 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005709 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005710 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005711 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005712
Douglas Gregorebe10102009-08-20 07:17:43 +00005713 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005714 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005715 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005716 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005717
Douglas Gregorebe10102009-08-20 07:17:43 +00005718 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005719 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5720 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005721}
Mike Stump11289f42009-09-09 15:08:12 +00005722
Douglas Gregorebe10102009-08-20 07:17:43 +00005723template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005724StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005725TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005726 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005727 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005728 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005729 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005730 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005731 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005732 getDerived().TransformDefinition(
5733 S->getConditionVariable()->getLocation(),
5734 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005735 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005736 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005737 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005738 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005739
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005740 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005741 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005742
5743 if (S->getCond()) {
5744 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005745 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5746 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005747 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005748 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005749 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005750 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005751 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005752 }
Mike Stump11289f42009-09-09 15:08:12 +00005753
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005754 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005755 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005756 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005757
Douglas Gregorebe10102009-08-20 07:17:43 +00005758 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005759 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005760 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005761 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005762
Douglas Gregorebe10102009-08-20 07:17:43 +00005763 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005764 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005765 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005766 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005767 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005768
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005769 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005770 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005771}
Mike Stump11289f42009-09-09 15:08:12 +00005772
Douglas Gregorebe10102009-08-20 07:17:43 +00005773template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005774StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005775TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005776 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005777 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005778 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005779 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005780
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005781 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005782 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005783 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005784 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005785
Douglas Gregorebe10102009-08-20 07:17:43 +00005786 if (!getDerived().AlwaysRebuild() &&
5787 Cond.get() == S->getCond() &&
5788 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005789 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005790
John McCallb268a282010-08-23 23:25:46 +00005791 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5792 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005793 S->getRParenLoc());
5794}
Mike Stump11289f42009-09-09 15:08:12 +00005795
Douglas Gregorebe10102009-08-20 07:17:43 +00005796template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005797StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005798TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005799 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005800 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005801 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005802 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005803
Douglas Gregorebe10102009-08-20 07:17:43 +00005804 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005805 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005806 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005807 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005808 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005809 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005810 getDerived().TransformDefinition(
5811 S->getConditionVariable()->getLocation(),
5812 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005813 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005814 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005815 } else {
5816 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005817
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005818 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005819 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005820
5821 if (S->getCond()) {
5822 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005823 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5824 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005825 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005826 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005827 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005828
John McCallb268a282010-08-23 23:25:46 +00005829 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005830 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005831 }
Mike Stump11289f42009-09-09 15:08:12 +00005832
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005833 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005834 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005835 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005836
Douglas Gregorebe10102009-08-20 07:17:43 +00005837 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005838 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005839 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005840 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005841
Richard Smith945f8d32013-01-14 22:39:08 +00005842 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005843 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005844 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005845
Douglas Gregorebe10102009-08-20 07:17:43 +00005846 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005847 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005848 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005849 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005850
Douglas Gregorebe10102009-08-20 07:17:43 +00005851 if (!getDerived().AlwaysRebuild() &&
5852 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005853 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005854 Inc.get() == S->getInc() &&
5855 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005856 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005857
Douglas Gregorebe10102009-08-20 07:17:43 +00005858 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005859 Init.get(), FullCond, ConditionVar,
5860 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005861}
5862
5863template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005864StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005865TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005866 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5867 S->getLabel());
5868 if (!LD)
5869 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005870
Douglas Gregorebe10102009-08-20 07:17:43 +00005871 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005872 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005873 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005874}
5875
5876template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005877StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005878TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005879 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005880 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005881 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005882 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00005883
Douglas Gregorebe10102009-08-20 07:17:43 +00005884 if (!getDerived().AlwaysRebuild() &&
5885 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005886 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005887
5888 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005889 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005890}
5891
5892template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005893StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005894TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005895 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005896}
Mike Stump11289f42009-09-09 15:08:12 +00005897
Douglas Gregorebe10102009-08-20 07:17:43 +00005898template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005899StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005900TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005901 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005902}
Mike Stump11289f42009-09-09 15:08:12 +00005903
Douglas Gregorebe10102009-08-20 07:17:43 +00005904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005905StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005906TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00005907 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
5908 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00005909 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005910 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005911
Mike Stump11289f42009-09-09 15:08:12 +00005912 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005913 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005914 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005915}
Mike Stump11289f42009-09-09 15:08:12 +00005916
Douglas Gregorebe10102009-08-20 07:17:43 +00005917template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005918StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005919TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005920 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005921 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005922 for (auto *D : S->decls()) {
5923 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005924 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005925 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005926
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005927 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005928 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005929
Douglas Gregorebe10102009-08-20 07:17:43 +00005930 Decls.push_back(Transformed);
5931 }
Mike Stump11289f42009-09-09 15:08:12 +00005932
Douglas Gregorebe10102009-08-20 07:17:43 +00005933 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005934 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005935
Rafael Espindolaab417692013-07-09 12:05:01 +00005936 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005937}
Mike Stump11289f42009-09-09 15:08:12 +00005938
Douglas Gregorebe10102009-08-20 07:17:43 +00005939template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005940StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005941TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005942
Benjamin Kramerf0623432012-08-23 22:51:59 +00005943 SmallVector<Expr*, 8> Constraints;
5944 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005945 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005946
John McCalldadc5752010-08-24 06:29:42 +00005947 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005948 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005949
5950 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005951
Anders Carlssonaaeef072010-01-24 05:50:09 +00005952 // Go through the outputs.
5953 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005954 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005955
Anders Carlssonaaeef072010-01-24 05:50:09 +00005956 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005957 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005958
Anders Carlssonaaeef072010-01-24 05:50:09 +00005959 // Transform the output expr.
5960 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005961 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005962 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005963 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005964
Anders Carlssonaaeef072010-01-24 05:50:09 +00005965 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005966
John McCallb268a282010-08-23 23:25:46 +00005967 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005968 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005969
Anders Carlssonaaeef072010-01-24 05:50:09 +00005970 // Go through the inputs.
5971 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005972 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005973
Anders Carlssonaaeef072010-01-24 05:50:09 +00005974 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005975 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005976
Anders Carlssonaaeef072010-01-24 05:50:09 +00005977 // Transform the input expr.
5978 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005979 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005980 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005981 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005982
Anders Carlssonaaeef072010-01-24 05:50:09 +00005983 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005984
John McCallb268a282010-08-23 23:25:46 +00005985 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005986 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005987
Anders Carlssonaaeef072010-01-24 05:50:09 +00005988 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005989 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005990
5991 // Go through the clobbers.
5992 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005993 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005994
5995 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005996 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00005997 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5998 S->isVolatile(), S->getNumOutputs(),
5999 S->getNumInputs(), Names.data(),
6000 Constraints, Exprs, AsmString.get(),
6001 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006002}
6003
Chad Rosier32503022012-06-11 20:47:18 +00006004template<typename Derived>
6005StmtResult
6006TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006007 ArrayRef<Token> AsmToks =
6008 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006009
John McCallf413f5e2013-05-03 00:10:13 +00006010 bool HadError = false, HadChange = false;
6011
6012 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6013 SmallVector<Expr*, 8> TransformedExprs;
6014 TransformedExprs.reserve(SrcExprs.size());
6015 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6016 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6017 if (!Result.isUsable()) {
6018 HadError = true;
6019 } else {
6020 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006021 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006022 }
6023 }
6024
6025 if (HadError) return StmtError();
6026 if (!HadChange && !getDerived().AlwaysRebuild())
6027 return Owned(S);
6028
Chad Rosierb6f46c12012-08-15 16:53:30 +00006029 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006030 AsmToks, S->getAsmString(),
6031 S->getNumOutputs(), S->getNumInputs(),
6032 S->getAllConstraints(), S->getClobbers(),
6033 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006034}
Douglas Gregorebe10102009-08-20 07:17:43 +00006035
6036template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006037StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006038TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006039 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006040 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006041 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006042 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006043
Douglas Gregor96c79492010-04-23 22:50:49 +00006044 // Transform the @catch statements (if present).
6045 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006046 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006047 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006048 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006049 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006050 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006051 if (Catch.get() != S->getCatchStmt(I))
6052 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006053 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006054 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006055
Douglas Gregor306de2f2010-04-22 23:59:56 +00006056 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006057 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006058 if (S->getFinallyStmt()) {
6059 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6060 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006061 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006062 }
6063
6064 // If nothing changed, just retain this statement.
6065 if (!getDerived().AlwaysRebuild() &&
6066 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006067 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006068 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006069 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006070
Douglas Gregor306de2f2010-04-22 23:59:56 +00006071 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006072 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006073 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006074}
Mike Stump11289f42009-09-09 15:08:12 +00006075
Douglas Gregorebe10102009-08-20 07:17:43 +00006076template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006077StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006078TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006079 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006080 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006081 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006082 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006083 if (FromVar->getTypeSourceInfo()) {
6084 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6085 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006086 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006087 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006088
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006089 QualType T;
6090 if (TSInfo)
6091 T = TSInfo->getType();
6092 else {
6093 T = getDerived().TransformType(FromVar->getType());
6094 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006095 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006096 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006097
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006098 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6099 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006100 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006101 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006102
John McCalldadc5752010-08-24 06:29:42 +00006103 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006104 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006105 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006106
6107 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006108 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006109 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006110}
Mike Stump11289f42009-09-09 15:08:12 +00006111
Douglas Gregorebe10102009-08-20 07:17:43 +00006112template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006113StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006114TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006115 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006116 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006117 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006118 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006119
Douglas Gregor306de2f2010-04-22 23:59:56 +00006120 // If nothing changed, just retain this statement.
6121 if (!getDerived().AlwaysRebuild() &&
6122 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006123 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006124
6125 // Build a new statement.
6126 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006127 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006128}
Mike Stump11289f42009-09-09 15:08:12 +00006129
Douglas Gregorebe10102009-08-20 07:17:43 +00006130template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006131StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006132TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006133 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006134 if (S->getThrowExpr()) {
6135 Operand = getDerived().TransformExpr(S->getThrowExpr());
6136 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006137 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006138 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006139
Douglas Gregor2900c162010-04-22 21:44:01 +00006140 if (!getDerived().AlwaysRebuild() &&
6141 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006142 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006143
John McCallb268a282010-08-23 23:25:46 +00006144 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006145}
Mike Stump11289f42009-09-09 15:08:12 +00006146
Douglas Gregorebe10102009-08-20 07:17:43 +00006147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006148StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006149TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006150 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006151 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006152 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006153 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006154 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006155 Object =
6156 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6157 Object.get());
6158 if (Object.isInvalid())
6159 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006160
Douglas Gregor6148de72010-04-22 22:01:21 +00006161 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006162 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006163 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006164 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006165
Douglas Gregor6148de72010-04-22 22:01:21 +00006166 // If nothing change, just retain the current statement.
6167 if (!getDerived().AlwaysRebuild() &&
6168 Object.get() == S->getSynchExpr() &&
6169 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006170 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006171
6172 // Build a new statement.
6173 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006174 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006175}
6176
6177template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006178StmtResult
John McCall31168b02011-06-15 23:02:42 +00006179TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6180 ObjCAutoreleasePoolStmt *S) {
6181 // Transform the body.
6182 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6183 if (Body.isInvalid())
6184 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006185
John McCall31168b02011-06-15 23:02:42 +00006186 // If nothing changed, just retain this statement.
6187 if (!getDerived().AlwaysRebuild() &&
6188 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006189 return S;
John McCall31168b02011-06-15 23:02:42 +00006190
6191 // Build a new statement.
6192 return getDerived().RebuildObjCAutoreleasePoolStmt(
6193 S->getAtLoc(), Body.get());
6194}
6195
6196template<typename Derived>
6197StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006198TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006199 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006200 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006201 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006202 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006203 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006204
Douglas Gregorf68a5082010-04-22 23:10:45 +00006205 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006206 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006207 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006208 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006209
Douglas Gregorf68a5082010-04-22 23:10:45 +00006210 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006211 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006212 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006213 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006214
Douglas Gregorf68a5082010-04-22 23:10:45 +00006215 // If nothing changed, just retain this statement.
6216 if (!getDerived().AlwaysRebuild() &&
6217 Element.get() == S->getElement() &&
6218 Collection.get() == S->getCollection() &&
6219 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006220 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006221
Douglas Gregorf68a5082010-04-22 23:10:45 +00006222 // Build a new statement.
6223 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006224 Element.get(),
6225 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006226 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006227 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006228}
6229
David Majnemer5f7efef2013-10-15 09:50:08 +00006230template <typename Derived>
6231StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006232 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006233 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006234 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6235 TypeSourceInfo *T =
6236 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006237 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006238 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006239
David Majnemer5f7efef2013-10-15 09:50:08 +00006240 Var = getDerived().RebuildExceptionDecl(
6241 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6242 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006243 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006244 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006245 }
Mike Stump11289f42009-09-09 15:08:12 +00006246
Douglas Gregorebe10102009-08-20 07:17:43 +00006247 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006248 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006249 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006250 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006251
David Majnemer5f7efef2013-10-15 09:50:08 +00006252 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006253 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006254 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006255
David Majnemer5f7efef2013-10-15 09:50:08 +00006256 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006257}
Mike Stump11289f42009-09-09 15:08:12 +00006258
David Majnemer5f7efef2013-10-15 09:50:08 +00006259template <typename Derived>
6260StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006261 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006262 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006263 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006264 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006265
Douglas Gregorebe10102009-08-20 07:17:43 +00006266 // Transform the handlers.
6267 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006268 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006269 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006270 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006271 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006272 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006273
Douglas Gregorebe10102009-08-20 07:17:43 +00006274 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006275 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006276 }
Mike Stump11289f42009-09-09 15:08:12 +00006277
David Majnemer5f7efef2013-10-15 09:50:08 +00006278 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006279 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006280 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006281
John McCallb268a282010-08-23 23:25:46 +00006282 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006283 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006284}
Mike Stump11289f42009-09-09 15:08:12 +00006285
Richard Smith02e85f32011-04-14 22:09:26 +00006286template<typename Derived>
6287StmtResult
6288TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6289 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6290 if (Range.isInvalid())
6291 return StmtError();
6292
6293 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6294 if (BeginEnd.isInvalid())
6295 return StmtError();
6296
6297 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6298 if (Cond.isInvalid())
6299 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006300 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006301 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006302 if (Cond.isInvalid())
6303 return StmtError();
6304 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006305 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006306
6307 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6308 if (Inc.isInvalid())
6309 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006310 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006311 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006312
6313 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6314 if (LoopVar.isInvalid())
6315 return StmtError();
6316
6317 StmtResult NewStmt = S;
6318 if (getDerived().AlwaysRebuild() ||
6319 Range.get() != S->getRangeStmt() ||
6320 BeginEnd.get() != S->getBeginEndStmt() ||
6321 Cond.get() != S->getCond() ||
6322 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006323 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006324 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6325 S->getColonLoc(), Range.get(),
6326 BeginEnd.get(), Cond.get(),
6327 Inc.get(), LoopVar.get(),
6328 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006329 if (NewStmt.isInvalid())
6330 return StmtError();
6331 }
Richard Smith02e85f32011-04-14 22:09:26 +00006332
6333 StmtResult Body = getDerived().TransformStmt(S->getBody());
6334 if (Body.isInvalid())
6335 return StmtError();
6336
6337 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6338 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006339 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006340 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6341 S->getColonLoc(), Range.get(),
6342 BeginEnd.get(), Cond.get(),
6343 Inc.get(), LoopVar.get(),
6344 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006345 if (NewStmt.isInvalid())
6346 return StmtError();
6347 }
Richard Smith02e85f32011-04-14 22:09:26 +00006348
6349 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006350 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006351
6352 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6353}
6354
John Wiegley1c0675e2011-04-28 01:08:34 +00006355template<typename Derived>
6356StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006357TreeTransform<Derived>::TransformMSDependentExistsStmt(
6358 MSDependentExistsStmt *S) {
6359 // Transform the nested-name-specifier, if any.
6360 NestedNameSpecifierLoc QualifierLoc;
6361 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006362 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006363 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6364 if (!QualifierLoc)
6365 return StmtError();
6366 }
6367
6368 // Transform the declaration name.
6369 DeclarationNameInfo NameInfo = S->getNameInfo();
6370 if (NameInfo.getName()) {
6371 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6372 if (!NameInfo.getName())
6373 return StmtError();
6374 }
6375
6376 // Check whether anything changed.
6377 if (!getDerived().AlwaysRebuild() &&
6378 QualifierLoc == S->getQualifierLoc() &&
6379 NameInfo.getName() == S->getNameInfo().getName())
6380 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006381
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006382 // Determine whether this name exists, if we can.
6383 CXXScopeSpec SS;
6384 SS.Adopt(QualifierLoc);
6385 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006386 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006387 case Sema::IER_Exists:
6388 if (S->isIfExists())
6389 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006390
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006391 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6392
6393 case Sema::IER_DoesNotExist:
6394 if (S->isIfNotExists())
6395 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006396
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006397 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006398
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006399 case Sema::IER_Dependent:
6400 Dependent = true;
6401 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006402
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006403 case Sema::IER_Error:
6404 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006405 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006406
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006407 // We need to continue with the instantiation, so do so now.
6408 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6409 if (SubStmt.isInvalid())
6410 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006411
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006412 // If we have resolved the name, just transform to the substatement.
6413 if (!Dependent)
6414 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006415
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006416 // The name is still dependent, so build a dependent expression again.
6417 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6418 S->isIfExists(),
6419 QualifierLoc,
6420 NameInfo,
6421 SubStmt.get());
6422}
6423
6424template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006425ExprResult
6426TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6427 NestedNameSpecifierLoc QualifierLoc;
6428 if (E->getQualifierLoc()) {
6429 QualifierLoc
6430 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6431 if (!QualifierLoc)
6432 return ExprError();
6433 }
6434
6435 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6436 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6437 if (!PD)
6438 return ExprError();
6439
6440 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6441 if (Base.isInvalid())
6442 return ExprError();
6443
6444 return new (SemaRef.getASTContext())
6445 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6446 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6447 QualifierLoc, E->getMemberLoc());
6448}
6449
David Majnemerfad8f482013-10-15 09:33:02 +00006450template <typename Derived>
6451StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006452 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006453 if (TryBlock.isInvalid())
6454 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006455
6456 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006457 if (Handler.isInvalid())
6458 return StmtError();
6459
David Majnemerfad8f482013-10-15 09:33:02 +00006460 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6461 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006462 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006463
Warren Huntf6be4cb2014-07-25 20:52:51 +00006464 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6465 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006466}
6467
David Majnemerfad8f482013-10-15 09:33:02 +00006468template <typename Derived>
6469StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006470 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006471 if (Block.isInvalid())
6472 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006473
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006474 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006475}
6476
David Majnemerfad8f482013-10-15 09:33:02 +00006477template <typename Derived>
6478StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006479 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006480 if (FilterExpr.isInvalid())
6481 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006482
David Majnemer7e755502013-10-15 09:30:14 +00006483 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006484 if (Block.isInvalid())
6485 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006486
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006487 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6488 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006489}
6490
David Majnemerfad8f482013-10-15 09:33:02 +00006491template <typename Derived>
6492StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6493 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006494 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6495 else
6496 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6497}
6498
Nico Weber9b982072014-07-07 00:12:30 +00006499template<typename Derived>
6500StmtResult
6501TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6502 return S;
6503}
6504
Alexander Musman64d33f12014-06-04 07:53:32 +00006505//===----------------------------------------------------------------------===//
6506// OpenMP directive transformation
6507//===----------------------------------------------------------------------===//
6508template <typename Derived>
6509StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6510 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006511
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006512 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006513 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006514 ArrayRef<OMPClause *> Clauses = D->clauses();
6515 TClauses.reserve(Clauses.size());
6516 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6517 I != E; ++I) {
6518 if (*I) {
6519 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevc5e02582014-06-16 07:08:35 +00006520 if (Clause)
6521 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006522 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006523 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006524 }
6525 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006526 StmtResult AssociatedStmt;
6527 if (D->hasAssociatedStmt()) {
6528 if (!D->getAssociatedStmt()) {
6529 return StmtError();
6530 }
6531 AssociatedStmt = getDerived().TransformStmt(D->getAssociatedStmt());
6532 if (AssociatedStmt.isInvalid()) {
6533 return StmtError();
6534 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006535 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006536 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006537 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006538 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006539
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006540 // Transform directive name for 'omp critical' directive.
6541 DeclarationNameInfo DirName;
6542 if (D->getDirectiveKind() == OMPD_critical) {
6543 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6544 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6545 }
6546
Alexander Musman64d33f12014-06-04 07:53:32 +00006547 return getDerived().RebuildOMPExecutableDirective(
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006548 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
6549 D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006550}
6551
Alexander Musman64d33f12014-06-04 07:53:32 +00006552template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006553StmtResult
6554TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6555 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006556 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6557 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006558 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6559 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6560 return Res;
6561}
6562
Alexander Musman64d33f12014-06-04 07:53:32 +00006563template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006564StmtResult
6565TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6566 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006567 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6568 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006569 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6570 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006571 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006572}
6573
Alexey Bataevf29276e2014-06-18 04:14:57 +00006574template <typename Derived>
6575StmtResult
6576TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6577 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006578 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6579 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006580 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6581 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6582 return Res;
6583}
6584
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006585template <typename Derived>
6586StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00006587TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
6588 DeclarationNameInfo DirName;
6589 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
6590 D->getLocStart());
6591 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6592 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6593 return Res;
6594}
6595
6596template <typename Derived>
6597StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006598TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6599 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006600 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6601 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006602 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6603 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6604 return Res;
6605}
6606
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006607template <typename Derived>
6608StmtResult
6609TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6610 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006611 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6612 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006613 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6614 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6615 return Res;
6616}
6617
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006618template <typename Derived>
6619StmtResult
6620TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6621 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006622 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6623 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006624 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6625 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6626 return Res;
6627}
6628
Alexey Bataev4acb8592014-07-07 13:01:15 +00006629template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006630StmtResult
6631TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6632 DeclarationNameInfo DirName;
6633 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6634 D->getLocStart());
6635 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6636 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6637 return Res;
6638}
6639
6640template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006641StmtResult
6642TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6643 getDerived().getSema().StartOpenMPDSABlock(
6644 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
6645 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6646 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6647 return Res;
6648}
6649
6650template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00006651StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6652 OMPParallelForDirective *D) {
6653 DeclarationNameInfo DirName;
6654 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6655 nullptr, D->getLocStart());
6656 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6657 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6658 return Res;
6659}
6660
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006661template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00006662StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
6663 OMPParallelForSimdDirective *D) {
6664 DeclarationNameInfo DirName;
6665 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
6666 nullptr, D->getLocStart());
6667 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6668 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6669 return Res;
6670}
6671
6672template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006673StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6674 OMPParallelSectionsDirective *D) {
6675 DeclarationNameInfo DirName;
6676 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6677 nullptr, D->getLocStart());
6678 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6679 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6680 return Res;
6681}
6682
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00006683template <typename Derived>
6684StmtResult
6685TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6686 DeclarationNameInfo DirName;
6687 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6688 D->getLocStart());
6689 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6690 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6691 return Res;
6692}
6693
Alexey Bataev68446b72014-07-18 07:47:19 +00006694template <typename Derived>
6695StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
6696 OMPTaskyieldDirective *D) {
6697 DeclarationNameInfo DirName;
6698 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
6699 D->getLocStart());
6700 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6701 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6702 return Res;
6703}
6704
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00006705template <typename Derived>
6706StmtResult
6707TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
6708 DeclarationNameInfo DirName;
6709 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
6710 D->getLocStart());
6711 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6712 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6713 return Res;
6714}
6715
Alexey Bataev2df347a2014-07-18 10:17:07 +00006716template <typename Derived>
6717StmtResult
6718TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
6719 DeclarationNameInfo DirName;
6720 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
6721 D->getLocStart());
6722 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6723 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6724 return Res;
6725}
6726
Alexey Bataev6125da92014-07-21 11:26:11 +00006727template <typename Derived>
6728StmtResult
6729TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
6730 DeclarationNameInfo DirName;
6731 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
6732 D->getLocStart());
6733 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6734 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6735 return Res;
6736}
6737
Alexey Bataev9fb6e642014-07-22 06:45:04 +00006738template <typename Derived>
6739StmtResult
6740TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
6741 DeclarationNameInfo DirName;
6742 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
6743 D->getLocStart());
6744 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6745 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6746 return Res;
6747}
6748
Alexey Bataev0162e452014-07-22 10:10:35 +00006749template <typename Derived>
6750StmtResult
6751TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
6752 DeclarationNameInfo DirName;
6753 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
6754 D->getLocStart());
6755 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6756 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6757 return Res;
6758}
6759
Alexey Bataev0bd520b2014-09-19 08:19:49 +00006760template <typename Derived>
6761StmtResult
6762TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
6763 DeclarationNameInfo DirName;
6764 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
6765 D->getLocStart());
6766 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6767 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6768 return Res;
6769}
6770
Alexey Bataev13314bf2014-10-09 04:18:56 +00006771template <typename Derived>
6772StmtResult
6773TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
6774 DeclarationNameInfo DirName;
6775 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
6776 D->getLocStart());
6777 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6778 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6779 return Res;
6780}
6781
Alexander Musman64d33f12014-06-04 07:53:32 +00006782//===----------------------------------------------------------------------===//
6783// OpenMP clause transformation
6784//===----------------------------------------------------------------------===//
6785template <typename Derived>
6786OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006787 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6788 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006789 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006790 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006791 C->getLParenLoc(), C->getLocEnd());
6792}
6793
Alexander Musman64d33f12014-06-04 07:53:32 +00006794template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00006795OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
6796 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6797 if (Cond.isInvalid())
6798 return nullptr;
6799 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
6800 C->getLParenLoc(), C->getLocEnd());
6801}
6802
6803template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006804OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006805TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6806 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6807 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006808 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006809 return getDerived().RebuildOMPNumThreadsClause(
6810 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006811}
6812
Alexey Bataev62c87d22014-03-21 04:51:18 +00006813template <typename Derived>
6814OMPClause *
6815TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6816 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6817 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006818 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006819 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006820 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006821}
6822
Alexander Musman8bd31e62014-05-27 15:12:19 +00006823template <typename Derived>
6824OMPClause *
6825TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6826 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6827 if (E.isInvalid())
6828 return 0;
6829 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006830 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006831}
6832
Alexander Musman64d33f12014-06-04 07:53:32 +00006833template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006834OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006835TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006836 return getDerived().RebuildOMPDefaultClause(
6837 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6838 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006839}
6840
Alexander Musman64d33f12014-06-04 07:53:32 +00006841template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006842OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006843TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006844 return getDerived().RebuildOMPProcBindClause(
6845 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6846 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006847}
6848
Alexander Musman64d33f12014-06-04 07:53:32 +00006849template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006850OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00006851TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
6852 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
6853 if (E.isInvalid())
6854 return nullptr;
6855 return getDerived().RebuildOMPScheduleClause(
6856 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
6857 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
6858}
6859
6860template <typename Derived>
6861OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00006862TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
6863 // No need to rebuild this clause, no template-dependent parameters.
6864 return C;
6865}
6866
6867template <typename Derived>
6868OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00006869TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
6870 // No need to rebuild this clause, no template-dependent parameters.
6871 return C;
6872}
6873
6874template <typename Derived>
6875OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00006876TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
6877 // No need to rebuild this clause, no template-dependent parameters.
6878 return C;
6879}
6880
6881template <typename Derived>
6882OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00006883TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
6884 // No need to rebuild this clause, no template-dependent parameters.
6885 return C;
6886}
6887
6888template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00006889OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
6890 // No need to rebuild this clause, no template-dependent parameters.
6891 return C;
6892}
6893
6894template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00006895OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
6896 // No need to rebuild this clause, no template-dependent parameters.
6897 return C;
6898}
6899
6900template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00006901OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00006902TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
6903 // No need to rebuild this clause, no template-dependent parameters.
6904 return C;
6905}
6906
6907template <typename Derived>
6908OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00006909TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
6910 // No need to rebuild this clause, no template-dependent parameters.
6911 return C;
6912}
6913
6914template <typename Derived>
6915OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00006916TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
6917 // No need to rebuild this clause, no template-dependent parameters.
6918 return C;
6919}
6920
6921template <typename Derived>
6922OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006923TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006924 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006925 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006926 for (auto *VE : C->varlists()) {
6927 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006928 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006929 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006930 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006931 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006932 return getDerived().RebuildOMPPrivateClause(
6933 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006934}
6935
Alexander Musman64d33f12014-06-04 07:53:32 +00006936template <typename Derived>
6937OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
6938 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006939 llvm::SmallVector<Expr *, 16> Vars;
6940 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006941 for (auto *VE : C->varlists()) {
6942 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006943 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006944 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006945 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006946 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006947 return getDerived().RebuildOMPFirstprivateClause(
6948 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006949}
6950
Alexander Musman64d33f12014-06-04 07:53:32 +00006951template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006952OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00006953TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
6954 llvm::SmallVector<Expr *, 16> Vars;
6955 Vars.reserve(C->varlist_size());
6956 for (auto *VE : C->varlists()) {
6957 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6958 if (EVar.isInvalid())
6959 return nullptr;
6960 Vars.push_back(EVar.get());
6961 }
6962 return getDerived().RebuildOMPLastprivateClause(
6963 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6964}
6965
6966template <typename Derived>
6967OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006968TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6969 llvm::SmallVector<Expr *, 16> Vars;
6970 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006971 for (auto *VE : C->varlists()) {
6972 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006973 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006974 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006975 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006976 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006977 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
6978 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006979}
6980
Alexander Musman64d33f12014-06-04 07:53:32 +00006981template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006982OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00006983TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
6984 llvm::SmallVector<Expr *, 16> Vars;
6985 Vars.reserve(C->varlist_size());
6986 for (auto *VE : C->varlists()) {
6987 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6988 if (EVar.isInvalid())
6989 return nullptr;
6990 Vars.push_back(EVar.get());
6991 }
6992 CXXScopeSpec ReductionIdScopeSpec;
6993 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
6994
6995 DeclarationNameInfo NameInfo = C->getNameInfo();
6996 if (NameInfo.getName()) {
6997 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6998 if (!NameInfo.getName())
6999 return nullptr;
7000 }
7001 return getDerived().RebuildOMPReductionClause(
7002 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7003 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7004}
7005
7006template <typename Derived>
7007OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007008TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7009 llvm::SmallVector<Expr *, 16> Vars;
7010 Vars.reserve(C->varlist_size());
7011 for (auto *VE : C->varlists()) {
7012 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7013 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007014 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007015 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007016 }
7017 ExprResult Step = getDerived().TransformExpr(C->getStep());
7018 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007019 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007020 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
7021 C->getLParenLoc(),
7022 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007023}
7024
Alexander Musman64d33f12014-06-04 07:53:32 +00007025template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007026OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007027TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7028 llvm::SmallVector<Expr *, 16> Vars;
7029 Vars.reserve(C->varlist_size());
7030 for (auto *VE : C->varlists()) {
7031 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7032 if (EVar.isInvalid())
7033 return nullptr;
7034 Vars.push_back(EVar.get());
7035 }
7036 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7037 if (Alignment.isInvalid())
7038 return nullptr;
7039 return getDerived().RebuildOMPAlignedClause(
7040 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7041 C->getColonLoc(), C->getLocEnd());
7042}
7043
Alexander Musman64d33f12014-06-04 07:53:32 +00007044template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007045OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007046TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7047 llvm::SmallVector<Expr *, 16> Vars;
7048 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007049 for (auto *VE : C->varlists()) {
7050 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007051 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007052 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007053 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007054 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007055 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7056 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007057}
7058
Alexey Bataevbae9a792014-06-27 10:37:06 +00007059template <typename Derived>
7060OMPClause *
7061TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7062 llvm::SmallVector<Expr *, 16> Vars;
7063 Vars.reserve(C->varlist_size());
7064 for (auto *VE : C->varlists()) {
7065 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7066 if (EVar.isInvalid())
7067 return nullptr;
7068 Vars.push_back(EVar.get());
7069 }
7070 return getDerived().RebuildOMPCopyprivateClause(
7071 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7072}
7073
Alexey Bataev6125da92014-07-21 11:26:11 +00007074template <typename Derived>
7075OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7076 llvm::SmallVector<Expr *, 16> Vars;
7077 Vars.reserve(C->varlist_size());
7078 for (auto *VE : C->varlists()) {
7079 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7080 if (EVar.isInvalid())
7081 return nullptr;
7082 Vars.push_back(EVar.get());
7083 }
7084 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7085 C->getLParenLoc(), C->getLocEnd());
7086}
7087
Douglas Gregorebe10102009-08-20 07:17:43 +00007088//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007089// Expression transformation
7090//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007092ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007093TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007094 if (!E->isTypeDependent())
7095 return E;
7096
7097 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7098 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007099}
Mike Stump11289f42009-09-09 15:08:12 +00007100
7101template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007102ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007103TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007104 NestedNameSpecifierLoc QualifierLoc;
7105 if (E->getQualifierLoc()) {
7106 QualifierLoc
7107 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7108 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007109 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007110 }
John McCallce546572009-12-08 09:08:17 +00007111
7112 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007113 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7114 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007115 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007116 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007117
John McCall815039a2010-08-17 21:27:17 +00007118 DeclarationNameInfo NameInfo = E->getNameInfo();
7119 if (NameInfo.getName()) {
7120 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7121 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007122 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007123 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007124
7125 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007126 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007127 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007128 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007129 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007130
7131 // Mark it referenced in the new context regardless.
7132 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007133 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007134
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007135 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007136 }
John McCallce546572009-12-08 09:08:17 +00007137
Craig Topperc3ec1492014-05-26 06:22:03 +00007138 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007139 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007140 TemplateArgs = &TransArgs;
7141 TransArgs.setLAngleLoc(E->getLAngleLoc());
7142 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007143 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7144 E->getNumTemplateArgs(),
7145 TransArgs))
7146 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007147 }
7148
Chad Rosier1dcde962012-08-08 18:46:20 +00007149 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007150 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007151}
Mike Stump11289f42009-09-09 15:08:12 +00007152
Douglas Gregora16548e2009-08-11 05:31:07 +00007153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007154ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007155TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007156 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007157}
Mike Stump11289f42009-09-09 15:08:12 +00007158
Douglas Gregora16548e2009-08-11 05:31:07 +00007159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007160ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007161TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007162 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007163}
Mike Stump11289f42009-09-09 15:08:12 +00007164
Douglas Gregora16548e2009-08-11 05:31:07 +00007165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007166ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007167TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007168 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007169}
Mike Stump11289f42009-09-09 15:08:12 +00007170
Douglas Gregora16548e2009-08-11 05:31:07 +00007171template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007172ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007173TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007174 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007175}
Mike Stump11289f42009-09-09 15:08:12 +00007176
Douglas Gregora16548e2009-08-11 05:31:07 +00007177template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007178ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007179TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007180 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007181}
7182
7183template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007184ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007185TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007186 if (FunctionDecl *FD = E->getDirectCallee())
7187 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007188 return SemaRef.MaybeBindToTemporary(E);
7189}
7190
7191template<typename Derived>
7192ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007193TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7194 ExprResult ControllingExpr =
7195 getDerived().TransformExpr(E->getControllingExpr());
7196 if (ControllingExpr.isInvalid())
7197 return ExprError();
7198
Chris Lattner01cf8db2011-07-20 06:58:45 +00007199 SmallVector<Expr *, 4> AssocExprs;
7200 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007201 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7202 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7203 if (TS) {
7204 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7205 if (!AssocType)
7206 return ExprError();
7207 AssocTypes.push_back(AssocType);
7208 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007209 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007210 }
7211
7212 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7213 if (AssocExpr.isInvalid())
7214 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007215 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007216 }
7217
7218 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7219 E->getDefaultLoc(),
7220 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007221 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007222 AssocTypes,
7223 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007224}
7225
7226template<typename Derived>
7227ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007228TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007229 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007230 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007231 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007232
Douglas Gregora16548e2009-08-11 05:31:07 +00007233 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007234 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007235
John McCallb268a282010-08-23 23:25:46 +00007236 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007237 E->getRParen());
7238}
7239
Richard Smithdb2630f2012-10-21 03:28:35 +00007240/// \brief The operand of a unary address-of operator has special rules: it's
7241/// allowed to refer to a non-static member of a class even if there's no 'this'
7242/// object available.
7243template<typename Derived>
7244ExprResult
7245TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7246 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007247 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007248 else
7249 return getDerived().TransformExpr(E);
7250}
7251
Mike Stump11289f42009-09-09 15:08:12 +00007252template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007253ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007254TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007255 ExprResult SubExpr;
7256 if (E->getOpcode() == UO_AddrOf)
7257 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7258 else
7259 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007260 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007261 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007262
Douglas Gregora16548e2009-08-11 05:31:07 +00007263 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007264 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007265
Douglas Gregora16548e2009-08-11 05:31:07 +00007266 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7267 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007268 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007269}
Mike Stump11289f42009-09-09 15:08:12 +00007270
Douglas Gregora16548e2009-08-11 05:31:07 +00007271template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007272ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007273TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7274 // Transform the type.
7275 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7276 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007277 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007278
Douglas Gregor882211c2010-04-28 22:16:22 +00007279 // Transform all of the components into components similar to what the
7280 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007281 // FIXME: It would be slightly more efficient in the non-dependent case to
7282 // just map FieldDecls, rather than requiring the rebuilder to look for
7283 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007284 // template code that we don't care.
7285 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007286 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007287 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007288 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007289 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7290 const Node &ON = E->getComponent(I);
7291 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007292 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007293 Comp.LocStart = ON.getSourceRange().getBegin();
7294 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007295 switch (ON.getKind()) {
7296 case Node::Array: {
7297 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007298 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007299 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007300 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007301
Douglas Gregor882211c2010-04-28 22:16:22 +00007302 ExprChanged = ExprChanged || Index.get() != FromIndex;
7303 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007304 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007305 break;
7306 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007307
Douglas Gregor882211c2010-04-28 22:16:22 +00007308 case Node::Field:
7309 case Node::Identifier:
7310 Comp.isBrackets = false;
7311 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007312 if (!Comp.U.IdentInfo)
7313 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007314
Douglas Gregor882211c2010-04-28 22:16:22 +00007315 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007316
Douglas Gregord1702062010-04-29 00:18:15 +00007317 case Node::Base:
7318 // Will be recomputed during the rebuild.
7319 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007320 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007321
Douglas Gregor882211c2010-04-28 22:16:22 +00007322 Components.push_back(Comp);
7323 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007324
Douglas Gregor882211c2010-04-28 22:16:22 +00007325 // If nothing changed, retain the existing expression.
7326 if (!getDerived().AlwaysRebuild() &&
7327 Type == E->getTypeSourceInfo() &&
7328 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007329 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007330
Douglas Gregor882211c2010-04-28 22:16:22 +00007331 // Build a new offsetof expression.
7332 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7333 Components.data(), Components.size(),
7334 E->getRParenLoc());
7335}
7336
7337template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007338ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007339TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7340 assert(getDerived().AlreadyTransformed(E->getType()) &&
7341 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007342 return E;
John McCall8d69a212010-11-15 23:31:06 +00007343}
7344
7345template<typename Derived>
7346ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00007347TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
7348 return E;
7349}
7350
7351template<typename Derived>
7352ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007353TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007354 // Rebuild the syntactic form. The original syntactic form has
7355 // opaque-value expressions in it, so strip those away and rebuild
7356 // the result. This is a really awful way of doing this, but the
7357 // better solution (rebuilding the semantic expressions and
7358 // rebinding OVEs as necessary) doesn't work; we'd need
7359 // TreeTransform to not strip away implicit conversions.
7360 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7361 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007362 if (result.isInvalid()) return ExprError();
7363
7364 // If that gives us a pseudo-object result back, the pseudo-object
7365 // expression must have been an lvalue-to-rvalue conversion which we
7366 // should reapply.
7367 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007368 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007369
7370 return result;
7371}
7372
7373template<typename Derived>
7374ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007375TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7376 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007377 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007378 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007379
John McCallbcd03502009-12-07 02:54:59 +00007380 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007381 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007382 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007383
John McCall4c98fd82009-11-04 07:28:41 +00007384 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007385 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007386
Peter Collingbournee190dee2011-03-11 19:24:49 +00007387 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7388 E->getKind(),
7389 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007390 }
Mike Stump11289f42009-09-09 15:08:12 +00007391
Eli Friedmane4f22df2012-02-29 04:03:55 +00007392 // C++0x [expr.sizeof]p1:
7393 // The operand is either an expression, which is an unevaluated operand
7394 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007395 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7396 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007397
Reid Kleckner32506ed2014-06-12 23:03:48 +00007398 // Try to recover if we have something like sizeof(T::X) where X is a type.
7399 // Notably, there must be *exactly* one set of parens if X is a type.
7400 TypeSourceInfo *RecoveryTSI = nullptr;
7401 ExprResult SubExpr;
7402 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7403 if (auto *DRE =
7404 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7405 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7406 PE, DRE, false, &RecoveryTSI);
7407 else
7408 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7409
7410 if (RecoveryTSI) {
7411 return getDerived().RebuildUnaryExprOrTypeTrait(
7412 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7413 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007414 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007415
Eli Friedmane4f22df2012-02-29 04:03:55 +00007416 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007417 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007418
Peter Collingbournee190dee2011-03-11 19:24:49 +00007419 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7420 E->getOperatorLoc(),
7421 E->getKind(),
7422 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007423}
Mike Stump11289f42009-09-09 15:08:12 +00007424
Douglas Gregora16548e2009-08-11 05:31:07 +00007425template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007426ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007427TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007428 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007429 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007430 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007431
John McCalldadc5752010-08-24 06:29:42 +00007432 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007433 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007434 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007435
7436
Douglas Gregora16548e2009-08-11 05:31:07 +00007437 if (!getDerived().AlwaysRebuild() &&
7438 LHS.get() == E->getLHS() &&
7439 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007440 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007441
John McCallb268a282010-08-23 23:25:46 +00007442 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007443 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007444 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007445 E->getRBracketLoc());
7446}
Mike Stump11289f42009-09-09 15:08:12 +00007447
7448template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007449ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007450TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007451 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007452 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007453 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007454 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007455
7456 // Transform arguments.
7457 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007458 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007459 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007460 &ArgChanged))
7461 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007462
Douglas Gregora16548e2009-08-11 05:31:07 +00007463 if (!getDerived().AlwaysRebuild() &&
7464 Callee.get() == E->getCallee() &&
7465 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007466 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007467
Douglas Gregora16548e2009-08-11 05:31:07 +00007468 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007469 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007470 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007471 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007472 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007473 E->getRParenLoc());
7474}
Mike Stump11289f42009-09-09 15:08:12 +00007475
7476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007477ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007478TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007479 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007480 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007481 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007482
Douglas Gregorea972d32011-02-28 21:54:11 +00007483 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007484 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007485 QualifierLoc
7486 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007487
Douglas Gregorea972d32011-02-28 21:54:11 +00007488 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007489 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007490 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007491 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007492
Eli Friedman2cfcef62009-12-04 06:40:45 +00007493 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007494 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7495 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007496 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007497 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007498
John McCall16df1e52010-03-30 21:47:33 +00007499 NamedDecl *FoundDecl = E->getFoundDecl();
7500 if (FoundDecl == E->getMemberDecl()) {
7501 FoundDecl = Member;
7502 } else {
7503 FoundDecl = cast_or_null<NamedDecl>(
7504 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7505 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007506 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007507 }
7508
Douglas Gregora16548e2009-08-11 05:31:07 +00007509 if (!getDerived().AlwaysRebuild() &&
7510 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007511 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007512 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007513 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007514 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007515
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007516 // Mark it referenced in the new context regardless.
7517 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007518 SemaRef.MarkMemberReferenced(E);
7519
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007520 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007521 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007522
John McCall6b51f282009-11-23 01:53:49 +00007523 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007524 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007525 TransArgs.setLAngleLoc(E->getLAngleLoc());
7526 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007527 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7528 E->getNumTemplateArgs(),
7529 TransArgs))
7530 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007531 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007532
Douglas Gregora16548e2009-08-11 05:31:07 +00007533 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007534 SourceLocation FakeOperatorLoc =
7535 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007536
John McCall38836f02010-01-15 08:34:02 +00007537 // FIXME: to do this check properly, we will need to preserve the
7538 // first-qualifier-in-scope here, just in case we had a dependent
7539 // base (and therefore couldn't do the check) and a
7540 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007541 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007542
John McCallb268a282010-08-23 23:25:46 +00007543 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007544 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007545 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007546 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007547 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007548 Member,
John McCall16df1e52010-03-30 21:47:33 +00007549 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007550 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007551 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007552 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007553}
Mike Stump11289f42009-09-09 15:08:12 +00007554
Douglas Gregora16548e2009-08-11 05:31:07 +00007555template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007556ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007557TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007558 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007559 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007560 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007561
John McCalldadc5752010-08-24 06:29:42 +00007562 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007563 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007564 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007565
Douglas Gregora16548e2009-08-11 05:31:07 +00007566 if (!getDerived().AlwaysRebuild() &&
7567 LHS.get() == E->getLHS() &&
7568 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007569 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007570
Lang Hames5de91cc2012-10-02 04:45:10 +00007571 Sema::FPContractStateRAII FPContractState(getSema());
7572 getSema().FPFeatures.fp_contract = E->isFPContractable();
7573
Douglas Gregora16548e2009-08-11 05:31:07 +00007574 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007575 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007576}
7577
Mike Stump11289f42009-09-09 15:08:12 +00007578template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007579ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007580TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007581 CompoundAssignOperator *E) {
7582 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007583}
Mike Stump11289f42009-09-09 15:08:12 +00007584
Douglas Gregora16548e2009-08-11 05:31:07 +00007585template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007586ExprResult TreeTransform<Derived>::
7587TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7588 // Just rebuild the common and RHS expressions and see whether we
7589 // get any changes.
7590
7591 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7592 if (commonExpr.isInvalid())
7593 return ExprError();
7594
7595 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7596 if (rhs.isInvalid())
7597 return ExprError();
7598
7599 if (!getDerived().AlwaysRebuild() &&
7600 commonExpr.get() == e->getCommon() &&
7601 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007602 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007603
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007604 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007605 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007606 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007607 e->getColonLoc(),
7608 rhs.get());
7609}
7610
7611template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007612ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007613TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007614 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007615 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007616 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007617
John McCalldadc5752010-08-24 06:29:42 +00007618 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007619 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007620 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007621
John McCalldadc5752010-08-24 06:29:42 +00007622 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007623 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007624 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007625
Douglas Gregora16548e2009-08-11 05:31:07 +00007626 if (!getDerived().AlwaysRebuild() &&
7627 Cond.get() == E->getCond() &&
7628 LHS.get() == E->getLHS() &&
7629 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007630 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007631
John McCallb268a282010-08-23 23:25:46 +00007632 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007633 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007634 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007635 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007636 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007637}
Mike Stump11289f42009-09-09 15:08:12 +00007638
7639template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007640ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007641TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007642 // Implicit casts are eliminated during transformation, since they
7643 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007644 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007645}
Mike Stump11289f42009-09-09 15:08:12 +00007646
Douglas Gregora16548e2009-08-11 05:31:07 +00007647template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007648ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007649TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007650 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7651 if (!Type)
7652 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007653
John McCalldadc5752010-08-24 06:29:42 +00007654 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007655 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007656 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007657 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007658
Douglas Gregora16548e2009-08-11 05:31:07 +00007659 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007660 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007661 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007662 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007663
John McCall97513962010-01-15 18:39:57 +00007664 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007665 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007666 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007667 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007668}
Mike Stump11289f42009-09-09 15:08:12 +00007669
Douglas Gregora16548e2009-08-11 05:31:07 +00007670template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007671ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007672TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007673 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7674 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7675 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007676 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007677
John McCalldadc5752010-08-24 06:29:42 +00007678 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007679 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007680 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007681
Douglas Gregora16548e2009-08-11 05:31:07 +00007682 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007683 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007684 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007685 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007686
John McCall5d7aa7f2010-01-19 22:33:45 +00007687 // Note: the expression type doesn't necessarily match the
7688 // type-as-written, but that's okay, because it should always be
7689 // derivable from the initializer.
7690
John McCalle15bbff2010-01-18 19:35:47 +00007691 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007692 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007693 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007694}
Mike Stump11289f42009-09-09 15:08:12 +00007695
Douglas Gregora16548e2009-08-11 05:31:07 +00007696template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007697ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007698TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007699 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007700 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007701 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007702
Douglas Gregora16548e2009-08-11 05:31:07 +00007703 if (!getDerived().AlwaysRebuild() &&
7704 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007705 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007706
Douglas Gregora16548e2009-08-11 05:31:07 +00007707 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007708 SourceLocation FakeOperatorLoc =
7709 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007710 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007711 E->getAccessorLoc(),
7712 E->getAccessor());
7713}
Mike Stump11289f42009-09-09 15:08:12 +00007714
Douglas Gregora16548e2009-08-11 05:31:07 +00007715template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007716ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007717TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007718 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007719
Benjamin Kramerf0623432012-08-23 22:51:59 +00007720 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007721 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007722 Inits, &InitChanged))
7723 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007724
Douglas Gregora16548e2009-08-11 05:31:07 +00007725 if (!getDerived().AlwaysRebuild() && !InitChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007726 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007727
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007728 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007729 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007730}
Mike Stump11289f42009-09-09 15:08:12 +00007731
Douglas Gregora16548e2009-08-11 05:31:07 +00007732template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007733ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007734TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007735 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007736
Douglas Gregorebe10102009-08-20 07:17:43 +00007737 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007738 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007739 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007740 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007741
Douglas Gregorebe10102009-08-20 07:17:43 +00007742 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007743 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007744 bool ExprChanged = false;
7745 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7746 DEnd = E->designators_end();
7747 D != DEnd; ++D) {
7748 if (D->isFieldDesignator()) {
7749 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7750 D->getDotLoc(),
7751 D->getFieldLoc()));
7752 continue;
7753 }
Mike Stump11289f42009-09-09 15:08:12 +00007754
Douglas Gregora16548e2009-08-11 05:31:07 +00007755 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007756 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007757 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007758 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007759
7760 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007761 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007762
Douglas Gregora16548e2009-08-11 05:31:07 +00007763 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007764 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007765 continue;
7766 }
Mike Stump11289f42009-09-09 15:08:12 +00007767
Douglas Gregora16548e2009-08-11 05:31:07 +00007768 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007769 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007770 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7771 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007772 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007773
John McCalldadc5752010-08-24 06:29:42 +00007774 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007775 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007776 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007777
7778 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007779 End.get(),
7780 D->getLBracketLoc(),
7781 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007782
Douglas Gregora16548e2009-08-11 05:31:07 +00007783 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7784 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007785
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007786 ArrayExprs.push_back(Start.get());
7787 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007788 }
Mike Stump11289f42009-09-09 15:08:12 +00007789
Douglas Gregora16548e2009-08-11 05:31:07 +00007790 if (!getDerived().AlwaysRebuild() &&
7791 Init.get() == E->getInit() &&
7792 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007793 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007794
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007795 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007796 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007797 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007798}
Mike Stump11289f42009-09-09 15:08:12 +00007799
Douglas Gregora16548e2009-08-11 05:31:07 +00007800template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007801ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007802TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007803 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007804 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007805
Douglas Gregor3da3c062009-10-28 00:29:27 +00007806 // FIXME: Will we ever have proper type location here? Will we actually
7807 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007808 QualType T = getDerived().TransformType(E->getType());
7809 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007810 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007811
Douglas Gregora16548e2009-08-11 05:31:07 +00007812 if (!getDerived().AlwaysRebuild() &&
7813 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007814 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007815
Douglas Gregora16548e2009-08-11 05:31:07 +00007816 return getDerived().RebuildImplicitValueInitExpr(T);
7817}
Mike Stump11289f42009-09-09 15:08:12 +00007818
Douglas Gregora16548e2009-08-11 05:31:07 +00007819template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007820ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007821TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007822 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7823 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007824 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007825
John McCalldadc5752010-08-24 06:29:42 +00007826 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007827 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007828 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007829
Douglas Gregora16548e2009-08-11 05:31:07 +00007830 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007831 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007832 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007833 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007834
John McCallb268a282010-08-23 23:25:46 +00007835 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007836 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007837}
7838
7839template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007840ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007841TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007842 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007843 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007844 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7845 &ArgumentChanged))
7846 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007847
Douglas Gregora16548e2009-08-11 05:31:07 +00007848 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007849 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007850 E->getRParenLoc());
7851}
Mike Stump11289f42009-09-09 15:08:12 +00007852
Douglas Gregora16548e2009-08-11 05:31:07 +00007853/// \brief Transform an address-of-label expression.
7854///
7855/// By default, the transformation of an address-of-label expression always
7856/// rebuilds the expression, so that the label identifier can be resolved to
7857/// the corresponding label statement by semantic analysis.
7858template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007859ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007860TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007861 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7862 E->getLabel());
7863 if (!LD)
7864 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007865
Douglas Gregora16548e2009-08-11 05:31:07 +00007866 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007867 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007868}
Mike Stump11289f42009-09-09 15:08:12 +00007869
7870template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007871ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007872TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007873 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007874 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007875 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007876 if (SubStmt.isInvalid()) {
7877 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007878 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007879 }
Mike Stump11289f42009-09-09 15:08:12 +00007880
Douglas Gregora16548e2009-08-11 05:31:07 +00007881 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007882 SubStmt.get() == E->getSubStmt()) {
7883 // Calling this an 'error' is unintuitive, but it does the right thing.
7884 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007885 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007886 }
Mike Stump11289f42009-09-09 15:08:12 +00007887
7888 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007889 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007890 E->getRParenLoc());
7891}
Mike Stump11289f42009-09-09 15:08:12 +00007892
Douglas Gregora16548e2009-08-11 05:31:07 +00007893template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007894ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007895TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007896 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007897 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007898 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007899
John McCalldadc5752010-08-24 06:29:42 +00007900 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007901 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007902 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007903
John McCalldadc5752010-08-24 06:29:42 +00007904 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007905 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007906 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007907
Douglas Gregora16548e2009-08-11 05:31:07 +00007908 if (!getDerived().AlwaysRebuild() &&
7909 Cond.get() == E->getCond() &&
7910 LHS.get() == E->getLHS() &&
7911 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007912 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007913
Douglas Gregora16548e2009-08-11 05:31:07 +00007914 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007915 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007916 E->getRParenLoc());
7917}
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
John McCall47f29ea2009-12-08 09:21:05 +00007921TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007922 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007923}
7924
7925template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007926ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007927TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007928 switch (E->getOperator()) {
7929 case OO_New:
7930 case OO_Delete:
7931 case OO_Array_New:
7932 case OO_Array_Delete:
7933 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007934
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007935 case OO_Call: {
7936 // This is a call to an object's operator().
7937 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7938
7939 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007940 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007941 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007942 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007943
7944 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007945 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7946 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007947
7948 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007949 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007950 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007951 Args))
7952 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007953
John McCallb268a282010-08-23 23:25:46 +00007954 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007955 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007956 E->getLocEnd());
7957 }
7958
7959#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7960 case OO_##Name:
7961#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7962#include "clang/Basic/OperatorKinds.def"
7963 case OO_Subscript:
7964 // Handled below.
7965 break;
7966
7967 case OO_Conditional:
7968 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007969
7970 case OO_None:
7971 case NUM_OVERLOADED_OPERATORS:
7972 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007973 }
7974
John McCalldadc5752010-08-24 06:29:42 +00007975 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007976 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007977 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007978
Richard Smithdb2630f2012-10-21 03:28:35 +00007979 ExprResult First;
7980 if (E->getOperator() == OO_Amp)
7981 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7982 else
7983 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007984 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007985 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007986
John McCalldadc5752010-08-24 06:29:42 +00007987 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007988 if (E->getNumArgs() == 2) {
7989 Second = getDerived().TransformExpr(E->getArg(1));
7990 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007991 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007992 }
Mike Stump11289f42009-09-09 15:08:12 +00007993
Douglas Gregora16548e2009-08-11 05:31:07 +00007994 if (!getDerived().AlwaysRebuild() &&
7995 Callee.get() == E->getCallee() &&
7996 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007997 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007998 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007999
Lang Hames5de91cc2012-10-02 04:45:10 +00008000 Sema::FPContractStateRAII FPContractState(getSema());
8001 getSema().FPFeatures.fp_contract = E->isFPContractable();
8002
Douglas Gregora16548e2009-08-11 05:31:07 +00008003 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8004 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008005 Callee.get(),
8006 First.get(),
8007 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008008}
Mike Stump11289f42009-09-09 15:08:12 +00008009
Douglas Gregora16548e2009-08-11 05:31:07 +00008010template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008011ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008012TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8013 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008014}
Mike Stump11289f42009-09-09 15:08:12 +00008015
Douglas Gregora16548e2009-08-11 05:31:07 +00008016template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008017ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008018TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8019 // Transform the callee.
8020 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8021 if (Callee.isInvalid())
8022 return ExprError();
8023
8024 // Transform exec config.
8025 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8026 if (EC.isInvalid())
8027 return ExprError();
8028
8029 // Transform arguments.
8030 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008031 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008032 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008033 &ArgChanged))
8034 return ExprError();
8035
8036 if (!getDerived().AlwaysRebuild() &&
8037 Callee.get() == E->getCallee() &&
8038 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008039 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008040
8041 // FIXME: Wrong source location information for the '('.
8042 SourceLocation FakeLParenLoc
8043 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8044 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008045 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008046 E->getRParenLoc(), EC.get());
8047}
8048
8049template<typename Derived>
8050ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008051TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008052 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8053 if (!Type)
8054 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008055
John McCalldadc5752010-08-24 06:29:42 +00008056 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008057 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008058 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008059 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008060
Douglas Gregora16548e2009-08-11 05:31:07 +00008061 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008062 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008063 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008064 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008065 return getDerived().RebuildCXXNamedCastExpr(
8066 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8067 Type, E->getAngleBrackets().getEnd(),
8068 // FIXME. this should be '(' location
8069 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008070}
Mike Stump11289f42009-09-09 15:08:12 +00008071
Douglas Gregora16548e2009-08-11 05:31:07 +00008072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008073ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008074TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8075 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008076}
Mike Stump11289f42009-09-09 15:08:12 +00008077
8078template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008079ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008080TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8081 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008082}
8083
Douglas Gregora16548e2009-08-11 05:31:07 +00008084template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008085ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008086TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008087 CXXReinterpretCastExpr *E) {
8088 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008089}
Mike Stump11289f42009-09-09 15:08:12 +00008090
Douglas Gregora16548e2009-08-11 05:31:07 +00008091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008092ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008093TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8094 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008095}
Mike Stump11289f42009-09-09 15:08:12 +00008096
Douglas Gregora16548e2009-08-11 05:31:07 +00008097template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008098ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008099TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008100 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008101 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8102 if (!Type)
8103 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008104
John McCalldadc5752010-08-24 06:29:42 +00008105 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008106 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008107 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008108 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008109
Douglas Gregora16548e2009-08-11 05:31:07 +00008110 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008111 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008112 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008113 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008114
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008115 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008116 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008117 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008118 E->getRParenLoc());
8119}
Mike Stump11289f42009-09-09 15:08:12 +00008120
Douglas Gregora16548e2009-08-11 05:31:07 +00008121template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008122ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008123TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008124 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008125 TypeSourceInfo *TInfo
8126 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8127 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008128 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008129
Douglas Gregora16548e2009-08-11 05:31:07 +00008130 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008131 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008132 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008133
Douglas Gregor9da64192010-04-26 22:37:10 +00008134 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8135 E->getLocStart(),
8136 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008137 E->getLocEnd());
8138 }
Mike Stump11289f42009-09-09 15:08:12 +00008139
Eli Friedman456f0182012-01-20 01:26:23 +00008140 // We don't know whether the subexpression is potentially evaluated until
8141 // after we perform semantic analysis. We speculatively assume it is
8142 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008143 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008144 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8145 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008146
John McCalldadc5752010-08-24 06:29:42 +00008147 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008148 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008149 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008150
Douglas Gregora16548e2009-08-11 05:31:07 +00008151 if (!getDerived().AlwaysRebuild() &&
8152 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008153 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008154
Douglas Gregor9da64192010-04-26 22:37:10 +00008155 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8156 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008157 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008158 E->getLocEnd());
8159}
8160
8161template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008162ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008163TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8164 if (E->isTypeOperand()) {
8165 TypeSourceInfo *TInfo
8166 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8167 if (!TInfo)
8168 return ExprError();
8169
8170 if (!getDerived().AlwaysRebuild() &&
8171 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008172 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008173
Douglas Gregor69735112011-03-06 17:40:41 +00008174 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008175 E->getLocStart(),
8176 TInfo,
8177 E->getLocEnd());
8178 }
8179
Francois Pichet9f4f2072010-09-08 12:20:18 +00008180 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8181
8182 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8183 if (SubExpr.isInvalid())
8184 return ExprError();
8185
8186 if (!getDerived().AlwaysRebuild() &&
8187 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008188 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008189
8190 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8191 E->getLocStart(),
8192 SubExpr.get(),
8193 E->getLocEnd());
8194}
8195
8196template<typename Derived>
8197ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008198TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008199 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008200}
Mike Stump11289f42009-09-09 15:08:12 +00008201
Douglas Gregora16548e2009-08-11 05:31:07 +00008202template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008203ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008204TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008205 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008206 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008207}
Mike Stump11289f42009-09-09 15:08:12 +00008208
Douglas Gregora16548e2009-08-11 05:31:07 +00008209template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008210ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008211TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008212 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008213
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008214 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8215 // Make sure that we capture 'this'.
8216 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008217 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008218 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008219
Douglas Gregorb15af892010-01-07 23:12:05 +00008220 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008221}
Mike Stump11289f42009-09-09 15:08:12 +00008222
Douglas Gregora16548e2009-08-11 05:31:07 +00008223template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008224ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008225TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008226 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008227 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008228 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008229
Douglas Gregora16548e2009-08-11 05:31:07 +00008230 if (!getDerived().AlwaysRebuild() &&
8231 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008232 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008233
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008234 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8235 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008236}
Mike Stump11289f42009-09-09 15:08:12 +00008237
Douglas Gregora16548e2009-08-11 05:31:07 +00008238template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008239ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008240TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008241 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008242 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8243 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008244 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008245 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008246
Chandler Carruth794da4c2010-02-08 06:42:49 +00008247 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008248 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008249 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008250
Douglas Gregor033f6752009-12-23 23:03:06 +00008251 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008252}
Mike Stump11289f42009-09-09 15:08:12 +00008253
Douglas Gregora16548e2009-08-11 05:31:07 +00008254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008255ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008256TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8257 FieldDecl *Field
8258 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8259 E->getField()));
8260 if (!Field)
8261 return ExprError();
8262
8263 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008264 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008265
8266 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8267}
8268
8269template<typename Derived>
8270ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008271TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8272 CXXScalarValueInitExpr *E) {
8273 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8274 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008275 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008276
Douglas Gregora16548e2009-08-11 05:31:07 +00008277 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008278 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008279 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008280
Chad Rosier1dcde962012-08-08 18:46:20 +00008281 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008282 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008283 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008284}
Mike Stump11289f42009-09-09 15:08:12 +00008285
Douglas Gregora16548e2009-08-11 05:31:07 +00008286template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008287ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008288TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008289 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008290 TypeSourceInfo *AllocTypeInfo
8291 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8292 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008293 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008294
Douglas Gregora16548e2009-08-11 05:31:07 +00008295 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008296 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008297 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008298 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008299
Douglas Gregora16548e2009-08-11 05:31:07 +00008300 // Transform the placement arguments (if any).
8301 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008302 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008303 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008304 E->getNumPlacementArgs(), true,
8305 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008306 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008307
Sebastian Redl6047f072012-02-16 12:22:20 +00008308 // Transform the initializer (if any).
8309 Expr *OldInit = E->getInitializer();
8310 ExprResult NewInit;
8311 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008312 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008313 if (NewInit.isInvalid())
8314 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008315
Sebastian Redl6047f072012-02-16 12:22:20 +00008316 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008317 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008318 if (E->getOperatorNew()) {
8319 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008320 getDerived().TransformDecl(E->getLocStart(),
8321 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008322 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008323 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008324 }
8325
Craig Topperc3ec1492014-05-26 06:22:03 +00008326 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008327 if (E->getOperatorDelete()) {
8328 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008329 getDerived().TransformDecl(E->getLocStart(),
8330 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008331 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008332 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008333 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008334
Douglas Gregora16548e2009-08-11 05:31:07 +00008335 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008336 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008337 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008338 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008339 OperatorNew == E->getOperatorNew() &&
8340 OperatorDelete == E->getOperatorDelete() &&
8341 !ArgumentChanged) {
8342 // Mark any declarations we need as referenced.
8343 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008344 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008345 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008346 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008347 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008348
Sebastian Redl6047f072012-02-16 12:22:20 +00008349 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008350 QualType ElementType
8351 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8352 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8353 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8354 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008355 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008356 }
8357 }
8358 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008359
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008360 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008361 }
Mike Stump11289f42009-09-09 15:08:12 +00008362
Douglas Gregor0744ef62010-09-07 21:49:58 +00008363 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008364 if (!ArraySize.get()) {
8365 // If no array size was specified, but the new expression was
8366 // instantiated with an array type (e.g., "new T" where T is
8367 // instantiated with "int[4]"), extract the outer bound from the
8368 // array type as our array size. We do this with constant and
8369 // dependently-sized array types.
8370 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8371 if (!ArrayT) {
8372 // Do nothing
8373 } else if (const ConstantArrayType *ConsArrayT
8374 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008375 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8376 SemaRef.Context.getSizeType(),
8377 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008378 AllocType = ConsArrayT->getElementType();
8379 } else if (const DependentSizedArrayType *DepArrayT
8380 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8381 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008382 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008383 AllocType = DepArrayT->getElementType();
8384 }
8385 }
8386 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008387
Douglas Gregora16548e2009-08-11 05:31:07 +00008388 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8389 E->isGlobalNew(),
8390 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008391 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008392 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008393 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008394 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008395 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008396 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008397 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008398 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008399}
Mike Stump11289f42009-09-09 15:08:12 +00008400
Douglas Gregora16548e2009-08-11 05:31:07 +00008401template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008402ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008403TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008404 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008405 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008406 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008407
Douglas Gregord2d9da02010-02-26 00:38:10 +00008408 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008409 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008410 if (E->getOperatorDelete()) {
8411 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008412 getDerived().TransformDecl(E->getLocStart(),
8413 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008414 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008415 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008416 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008417
Douglas Gregora16548e2009-08-11 05:31:07 +00008418 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008419 Operand.get() == E->getArgument() &&
8420 OperatorDelete == E->getOperatorDelete()) {
8421 // Mark any declarations we need as referenced.
8422 // FIXME: instantiation-specific.
8423 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008424 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008425
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008426 if (!E->getArgument()->isTypeDependent()) {
8427 QualType Destroyed = SemaRef.Context.getBaseElementType(
8428 E->getDestroyedType());
8429 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8430 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008431 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008432 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008433 }
8434 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008435
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008436 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008437 }
Mike Stump11289f42009-09-09 15:08:12 +00008438
Douglas Gregora16548e2009-08-11 05:31:07 +00008439 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8440 E->isGlobalDelete(),
8441 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008442 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008443}
Mike Stump11289f42009-09-09 15:08:12 +00008444
Douglas Gregora16548e2009-08-11 05:31:07 +00008445template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008446ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008447TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008448 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008449 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008450 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008451 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008452
John McCallba7bf592010-08-24 05:47:05 +00008453 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008454 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008455 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008456 E->getOperatorLoc(),
8457 E->isArrow()? tok::arrow : tok::period,
8458 ObjectTypePtr,
8459 MayBePseudoDestructor);
8460 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008461 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008462
John McCallba7bf592010-08-24 05:47:05 +00008463 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008464 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8465 if (QualifierLoc) {
8466 QualifierLoc
8467 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8468 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008469 return ExprError();
8470 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008471 CXXScopeSpec SS;
8472 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008473
Douglas Gregor678f90d2010-02-25 01:56:36 +00008474 PseudoDestructorTypeStorage Destroyed;
8475 if (E->getDestroyedTypeInfo()) {
8476 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008477 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008478 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008479 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008480 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008481 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008482 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008483 // We aren't likely to be able to resolve the identifier down to a type
8484 // now anyway, so just retain the identifier.
8485 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8486 E->getDestroyedTypeLoc());
8487 } else {
8488 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008489 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008490 *E->getDestroyedTypeIdentifier(),
8491 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008492 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008493 SS, ObjectTypePtr,
8494 false);
8495 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008496 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008497
Douglas Gregor678f90d2010-02-25 01:56:36 +00008498 Destroyed
8499 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8500 E->getDestroyedTypeLoc());
8501 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008502
Craig Topperc3ec1492014-05-26 06:22:03 +00008503 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008504 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008505 CXXScopeSpec EmptySS;
8506 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008507 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008508 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008509 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008510 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008511
John McCallb268a282010-08-23 23:25:46 +00008512 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008513 E->getOperatorLoc(),
8514 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008515 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008516 ScopeTypeInfo,
8517 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008518 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008519 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008520}
Mike Stump11289f42009-09-09 15:08:12 +00008521
Douglas Gregorad8a3362009-09-04 17:36:40 +00008522template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008523ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008524TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008525 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008526 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8527 Sema::LookupOrdinaryName);
8528
8529 // Transform all the decls.
8530 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8531 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008532 NamedDecl *InstD = static_cast<NamedDecl*>(
8533 getDerived().TransformDecl(Old->getNameLoc(),
8534 *I));
John McCall84d87672009-12-10 09:41:52 +00008535 if (!InstD) {
8536 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8537 // This can happen because of dependent hiding.
8538 if (isa<UsingShadowDecl>(*I))
8539 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008540 else {
8541 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008542 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008543 }
John McCall84d87672009-12-10 09:41:52 +00008544 }
John McCalle66edc12009-11-24 19:00:30 +00008545
8546 // Expand using declarations.
8547 if (isa<UsingDecl>(InstD)) {
8548 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008549 for (auto *I : UD->shadows())
8550 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008551 continue;
8552 }
8553
8554 R.addDecl(InstD);
8555 }
8556
8557 // Resolve a kind, but don't do any further analysis. If it's
8558 // ambiguous, the callee needs to deal with it.
8559 R.resolveKind();
8560
8561 // Rebuild the nested-name qualifier, if present.
8562 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008563 if (Old->getQualifierLoc()) {
8564 NestedNameSpecifierLoc QualifierLoc
8565 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8566 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008567 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008568
Douglas Gregor0da1d432011-02-28 20:01:57 +00008569 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008570 }
8571
Douglas Gregor9262f472010-04-27 18:19:34 +00008572 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008573 CXXRecordDecl *NamingClass
8574 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8575 Old->getNameLoc(),
8576 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008577 if (!NamingClass) {
8578 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008579 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008580 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008581
Douglas Gregorda7be082010-04-27 16:10:10 +00008582 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008583 }
8584
Abramo Bagnara7945c982012-01-27 09:46:47 +00008585 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8586
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008587 // If we have neither explicit template arguments, nor the template keyword,
8588 // it's a normal declaration name.
8589 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008590 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8591
8592 // If we have template arguments, rebuild them, then rebuild the
8593 // templateid expression.
8594 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008595 if (Old->hasExplicitTemplateArgs() &&
8596 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008597 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008598 TransArgs)) {
8599 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008600 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008601 }
John McCalle66edc12009-11-24 19:00:30 +00008602
Abramo Bagnara7945c982012-01-27 09:46:47 +00008603 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008604 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008605}
Mike Stump11289f42009-09-09 15:08:12 +00008606
Douglas Gregora16548e2009-08-11 05:31:07 +00008607template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008608ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008609TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8610 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008611 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008612 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8613 TypeSourceInfo *From = E->getArg(I);
8614 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008615 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008616 TypeLocBuilder TLB;
8617 TLB.reserve(FromTL.getFullDataSize());
8618 QualType To = getDerived().TransformType(TLB, FromTL);
8619 if (To.isNull())
8620 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008621
Douglas Gregor29c42f22012-02-24 07:38:34 +00008622 if (To == From->getType())
8623 Args.push_back(From);
8624 else {
8625 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8626 ArgChanged = true;
8627 }
8628 continue;
8629 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008630
Douglas Gregor29c42f22012-02-24 07:38:34 +00008631 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008632
Douglas Gregor29c42f22012-02-24 07:38:34 +00008633 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008634 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008635 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8636 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8637 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008638
Douglas Gregor29c42f22012-02-24 07:38:34 +00008639 // Determine whether the set of unexpanded parameter packs can and should
8640 // be expanded.
8641 bool Expand = true;
8642 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008643 Optional<unsigned> OrigNumExpansions =
8644 ExpansionTL.getTypePtr()->getNumExpansions();
8645 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008646 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8647 PatternTL.getSourceRange(),
8648 Unexpanded,
8649 Expand, RetainExpansion,
8650 NumExpansions))
8651 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008652
Douglas Gregor29c42f22012-02-24 07:38:34 +00008653 if (!Expand) {
8654 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008655 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008656 // expansion.
8657 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008658
Douglas Gregor29c42f22012-02-24 07:38:34 +00008659 TypeLocBuilder TLB;
8660 TLB.reserve(From->getTypeLoc().getFullDataSize());
8661
8662 QualType To = getDerived().TransformType(TLB, PatternTL);
8663 if (To.isNull())
8664 return ExprError();
8665
Chad Rosier1dcde962012-08-08 18:46:20 +00008666 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008667 PatternTL.getSourceRange(),
8668 ExpansionTL.getEllipsisLoc(),
8669 NumExpansions);
8670 if (To.isNull())
8671 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008672
Douglas Gregor29c42f22012-02-24 07:38:34 +00008673 PackExpansionTypeLoc ToExpansionTL
8674 = TLB.push<PackExpansionTypeLoc>(To);
8675 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8676 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8677 continue;
8678 }
8679
8680 // Expand the pack expansion by substituting for each argument in the
8681 // pack(s).
8682 for (unsigned I = 0; I != *NumExpansions; ++I) {
8683 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8684 TypeLocBuilder TLB;
8685 TLB.reserve(PatternTL.getFullDataSize());
8686 QualType To = getDerived().TransformType(TLB, PatternTL);
8687 if (To.isNull())
8688 return ExprError();
8689
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008690 if (To->containsUnexpandedParameterPack()) {
8691 To = getDerived().RebuildPackExpansionType(To,
8692 PatternTL.getSourceRange(),
8693 ExpansionTL.getEllipsisLoc(),
8694 NumExpansions);
8695 if (To.isNull())
8696 return ExprError();
8697
8698 PackExpansionTypeLoc ToExpansionTL
8699 = TLB.push<PackExpansionTypeLoc>(To);
8700 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8701 }
8702
Douglas Gregor29c42f22012-02-24 07:38:34 +00008703 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8704 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008705
Douglas Gregor29c42f22012-02-24 07:38:34 +00008706 if (!RetainExpansion)
8707 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008708
Douglas Gregor29c42f22012-02-24 07:38:34 +00008709 // If we're supposed to retain a pack expansion, do so by temporarily
8710 // forgetting the partially-substituted parameter pack.
8711 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8712
8713 TypeLocBuilder TLB;
8714 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008715
Douglas Gregor29c42f22012-02-24 07:38:34 +00008716 QualType To = getDerived().TransformType(TLB, PatternTL);
8717 if (To.isNull())
8718 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008719
8720 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008721 PatternTL.getSourceRange(),
8722 ExpansionTL.getEllipsisLoc(),
8723 NumExpansions);
8724 if (To.isNull())
8725 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008726
Douglas Gregor29c42f22012-02-24 07:38:34 +00008727 PackExpansionTypeLoc ToExpansionTL
8728 = TLB.push<PackExpansionTypeLoc>(To);
8729 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8730 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8731 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008732
Douglas Gregor29c42f22012-02-24 07:38:34 +00008733 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008734 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008735
8736 return getDerived().RebuildTypeTrait(E->getTrait(),
8737 E->getLocStart(),
8738 Args,
8739 E->getLocEnd());
8740}
8741
8742template<typename Derived>
8743ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008744TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8745 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8746 if (!T)
8747 return ExprError();
8748
8749 if (!getDerived().AlwaysRebuild() &&
8750 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008751 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008752
8753 ExprResult SubExpr;
8754 {
8755 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8756 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8757 if (SubExpr.isInvalid())
8758 return ExprError();
8759
8760 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008761 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008762 }
8763
8764 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8765 E->getLocStart(),
8766 T,
8767 SubExpr.get(),
8768 E->getLocEnd());
8769}
8770
8771template<typename Derived>
8772ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008773TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8774 ExprResult SubExpr;
8775 {
8776 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8777 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8778 if (SubExpr.isInvalid())
8779 return ExprError();
8780
8781 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008782 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008783 }
8784
8785 return getDerived().RebuildExpressionTrait(
8786 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8787}
8788
Reid Kleckner32506ed2014-06-12 23:03:48 +00008789template <typename Derived>
8790ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8791 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8792 TypeSourceInfo **RecoveryTSI) {
8793 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8794 DRE, AddrTaken, RecoveryTSI);
8795
8796 // Propagate both errors and recovered types, which return ExprEmpty.
8797 if (!NewDRE.isUsable())
8798 return NewDRE;
8799
8800 // We got an expr, wrap it up in parens.
8801 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8802 return PE;
8803 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8804 PE->getRParen());
8805}
8806
8807template <typename Derived>
8808ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8809 DependentScopeDeclRefExpr *E) {
8810 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8811 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008812}
8813
8814template<typename Derived>
8815ExprResult
8816TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8817 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00008818 bool IsAddressOfOperand,
8819 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008820 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008821 NestedNameSpecifierLoc QualifierLoc
8822 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8823 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008824 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008825 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008826
John McCall31f82722010-11-12 08:19:04 +00008827 // TODO: If this is a conversion-function-id, verify that the
8828 // destination type name (if present) resolves the same way after
8829 // instantiation as it did in the local scope.
8830
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008831 DeclarationNameInfo NameInfo
8832 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8833 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008834 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008835
John McCalle66edc12009-11-24 19:00:30 +00008836 if (!E->hasExplicitTemplateArgs()) {
8837 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008838 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008839 // Note: it is sufficient to compare the Name component of NameInfo:
8840 // if name has not changed, DNLoc has not changed either.
8841 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008842 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008843
Reid Kleckner32506ed2014-06-12 23:03:48 +00008844 return getDerived().RebuildDependentScopeDeclRefExpr(
8845 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
8846 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00008847 }
John McCall6b51f282009-11-23 01:53:49 +00008848
8849 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008850 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8851 E->getNumTemplateArgs(),
8852 TransArgs))
8853 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008854
Reid Kleckner32506ed2014-06-12 23:03:48 +00008855 return getDerived().RebuildDependentScopeDeclRefExpr(
8856 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
8857 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00008858}
8859
8860template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008861ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008862TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008863 // CXXConstructExprs other than for list-initialization and
8864 // CXXTemporaryObjectExpr are always implicit, so when we have
8865 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008866 if ((E->getNumArgs() == 1 ||
8867 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008868 (!getDerived().DropCallArgument(E->getArg(0))) &&
8869 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008870 return getDerived().TransformExpr(E->getArg(0));
8871
Douglas Gregora16548e2009-08-11 05:31:07 +00008872 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8873
8874 QualType T = getDerived().TransformType(E->getType());
8875 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008876 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008877
8878 CXXConstructorDecl *Constructor
8879 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008880 getDerived().TransformDecl(E->getLocStart(),
8881 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008882 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008883 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008884
Douglas Gregora16548e2009-08-11 05:31:07 +00008885 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008886 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008887 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008888 &ArgumentChanged))
8889 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008890
Douglas Gregora16548e2009-08-11 05:31:07 +00008891 if (!getDerived().AlwaysRebuild() &&
8892 T == E->getType() &&
8893 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008894 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008895 // Mark the constructor as referenced.
8896 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008897 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008898 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00008899 }
Mike Stump11289f42009-09-09 15:08:12 +00008900
Douglas Gregordb121ba2009-12-14 16:27:04 +00008901 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8902 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008903 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008904 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008905 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00008906 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008907 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008908 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008909 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008910}
Mike Stump11289f42009-09-09 15:08:12 +00008911
Douglas Gregora16548e2009-08-11 05:31:07 +00008912/// \brief Transform a C++ temporary-binding expression.
8913///
Douglas Gregor363b1512009-12-24 18:51:59 +00008914/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8915/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008916template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008917ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008918TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008919 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008920}
Mike Stump11289f42009-09-09 15:08:12 +00008921
John McCall5d413782010-12-06 08:20:24 +00008922/// \brief Transform a C++ expression that contains cleanups that should
8923/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008924///
John McCall5d413782010-12-06 08:20:24 +00008925/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008926/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008927template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008928ExprResult
John McCall5d413782010-12-06 08:20:24 +00008929TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008930 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008931}
Mike Stump11289f42009-09-09 15:08:12 +00008932
Douglas Gregora16548e2009-08-11 05:31:07 +00008933template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008934ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008935TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008936 CXXTemporaryObjectExpr *E) {
8937 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8938 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008939 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008940
Douglas Gregora16548e2009-08-11 05:31:07 +00008941 CXXConstructorDecl *Constructor
8942 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008943 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008944 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008945 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008946 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008947
Douglas Gregora16548e2009-08-11 05:31:07 +00008948 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008949 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008950 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008951 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008952 &ArgumentChanged))
8953 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008954
Douglas Gregora16548e2009-08-11 05:31:07 +00008955 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008956 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008957 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008958 !ArgumentChanged) {
8959 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008960 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008961 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008962 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008963
Richard Smithd59b8322012-12-19 01:39:02 +00008964 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008965 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8966 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008967 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008968 E->getLocEnd());
8969}
Mike Stump11289f42009-09-09 15:08:12 +00008970
Douglas Gregora16548e2009-08-11 05:31:07 +00008971template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008972ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008973TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008974
8975 // Transform any init-capture expressions before entering the scope of the
8976 // lambda body, because they are not semantically within that scope.
8977 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8978 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8979 E->explicit_capture_begin());
8980
8981 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8982 CEnd = E->capture_end();
8983 C != CEnd; ++C) {
8984 if (!C->isInitCapture())
8985 continue;
8986 EnterExpressionEvaluationContext EEEC(getSema(),
8987 Sema::PotentiallyEvaluated);
8988 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8989 C->getCapturedVar()->getInit(),
8990 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8991
8992 if (NewExprInitResult.isInvalid())
8993 return ExprError();
8994 Expr *NewExprInit = NewExprInitResult.get();
8995
8996 VarDecl *OldVD = C->getCapturedVar();
8997 QualType NewInitCaptureType =
8998 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8999 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
9000 NewExprInit);
9001 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009002 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9003 std::make_pair(NewExprInitResult, NewInitCaptureType);
9004
9005 }
9006
Faisal Vali524ca282013-11-12 01:40:44 +00009007 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00009008 // Transform the template parameters, and add them to the current
9009 // instantiation scope. The null case is handled correctly.
9010 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
9011 E->getTemplateParameterList());
9012
9013 // Check to see if the TypeSourceInfo of the call operator needs to
9014 // be transformed, and if so do the transformation in the
9015 // CurrentInstantiationScope.
9016
9017 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9018 FunctionProtoTypeLoc OldCallOpFPTL =
9019 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Craig Topperc3ec1492014-05-26 06:22:03 +00009020 TypeSourceInfo *NewCallOpTSI = nullptr;
9021
Faisal Vali2cba1332013-10-23 06:44:28 +00009022 const bool CallOpWasAlreadyTransformed =
9023 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
9024
9025 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
9026 if (CallOpWasAlreadyTransformed)
9027 NewCallOpTSI = OldCallOpTSI;
9028 else {
9029 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
9030 // The transformation MUST be done in the CurrentInstantiationScope since
9031 // it introduces a mapping of the original to the newly created
9032 // transformed parameters.
9033
9034 TypeLocBuilder NewCallOpTLBuilder;
NAKAMURA Takumi23224152014-10-17 12:48:37 +00009035 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
9036 OldCallOpFPTL,
9037 nullptr, 0);
Faisal Vali2cba1332013-10-23 06:44:28 +00009038 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9039 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009040 }
Faisal Vali2cba1332013-10-23 06:44:28 +00009041 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
9042 // the vector below - this will be used to synthesize the
9043 // NewCallOperator. Additionally, add the parameters of the untransformed
9044 // lambda call operator to the CurrentInstantiationScope.
9045 SmallVector<ParmVarDecl *, 4> Params;
9046 {
9047 FunctionProtoTypeLoc NewCallOpFPTL =
9048 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
9049 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00009050 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00009051
9052 for (unsigned I = 0; I < NewNumArgs; ++I) {
9053 // If this call operator's type does not require transformation,
9054 // the parameters do not get added to the current instantiation scope,
9055 // - so ADD them! This allows the following to compile when the enclosing
9056 // template is specialized and the entire lambda expression has to be
9057 // transformed.
9058 // template<class T> void foo(T t) {
9059 // auto L = [](auto a) {
9060 // auto M = [](char b) { <-- note: non-generic lambda
9061 // auto N = [](auto c) {
9062 // int x = sizeof(a);
9063 // x = sizeof(b); <-- specifically this line
9064 // x = sizeof(c);
9065 // };
9066 // };
9067 // };
9068 // }
9069 // foo('a')
9070 if (CallOpWasAlreadyTransformed)
9071 getDerived().transformedLocalDecl(NewParamDeclArray[I],
9072 NewParamDeclArray[I]);
9073 // Add to Params array, so these parameters can be used to create
9074 // the newly transformed call operator.
9075 Params.push_back(NewParamDeclArray[I]);
9076 }
9077 }
9078
9079 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009080 return ExprError();
9081
Eli Friedmand564afb2012-09-19 01:18:11 +00009082 // Create the local class that will describe the lambda.
9083 CXXRecordDecl *Class
9084 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009085 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009086 /*KnownDependent=*/false,
9087 E->getCaptureDefault());
9088
Eli Friedmand564afb2012-09-19 01:18:11 +00009089 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9090
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009091 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00009092 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009093 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009094 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00009095 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00009096 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00009097 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009098
Faisal Vali2cba1332013-10-23 06:44:28 +00009099 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
9100
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009101 return getDerived().TransformLambdaScope(E, NewCallOperator,
9102 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00009103}
9104
9105template<typename Derived>
9106ExprResult
9107TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009108 CXXMethodDecl *CallOperator,
9109 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00009110 bool Invalid = false;
9111
Douglas Gregorb4328232012-02-14 00:00:48 +00009112 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009113 Sema::ContextRAII SavedContext(getSema(), CallOperator,
9114 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009115
Faisal Vali2b391ab2013-09-26 19:54:12 +00009116 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009117 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00009118 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009119 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00009120 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009121 E->hasExplicitParameters(),
9122 E->hasExplicitResultType(),
9123 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00009124
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009125 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009126 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009127 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009128 CEnd = E->capture_end();
9129 C != CEnd; ++C) {
9130 // When we hit the first implicit capture, tell Sema that we've finished
9131 // the list of explicit captures.
9132 if (!FinishedExplicitCaptures && C->isImplicit()) {
9133 getSema().finishLambdaExplicitCaptures(LSI);
9134 FinishedExplicitCaptures = true;
9135 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009136
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009137 // Capturing 'this' is trivial.
9138 if (C->capturesThis()) {
9139 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9140 continue;
9141 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009142 // Captured expression will be recaptured during captured variables
9143 // rebuilding.
9144 if (C->capturesVLAType())
9145 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009146
Richard Smithba71c082013-05-16 06:20:58 +00009147 // Rebuild init-captures, including the implied field declaration.
9148 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009149
9150 InitCaptureInfoTy InitExprTypePair =
9151 InitCaptureExprsAndTypes[C - E->capture_begin()];
9152 ExprResult Init = InitExprTypePair.first;
9153 QualType InitQualType = InitExprTypePair.second;
9154 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009155 Invalid = true;
9156 continue;
9157 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009158 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009159 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9160 OldVD->getLocation(), InitExprTypePair.second,
9161 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009162 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009163 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009164 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009165 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009166 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009167 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009168 continue;
9169 }
9170
9171 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9172
Douglas Gregor3e308b12012-02-14 19:27:52 +00009173 // Determine the capture kind for Sema.
9174 Sema::TryCaptureKind Kind
9175 = C->isImplicit()? Sema::TryCapture_Implicit
9176 : C->getCaptureKind() == LCK_ByCopy
9177 ? Sema::TryCapture_ExplicitByVal
9178 : Sema::TryCapture_ExplicitByRef;
9179 SourceLocation EllipsisLoc;
9180 if (C->isPackExpansion()) {
9181 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9182 bool ShouldExpand = false;
9183 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009184 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009185 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9186 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009187 Unexpanded,
9188 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009189 NumExpansions)) {
9190 Invalid = true;
9191 continue;
9192 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009193
Douglas Gregor3e308b12012-02-14 19:27:52 +00009194 if (ShouldExpand) {
9195 // The transform has determined that we should perform an expansion;
9196 // transform and capture each of the arguments.
9197 // expansion of the pattern. Do so.
9198 VarDecl *Pack = C->getCapturedVar();
9199 for (unsigned I = 0; I != *NumExpansions; ++I) {
9200 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9201 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009202 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009203 Pack));
9204 if (!CapturedVar) {
9205 Invalid = true;
9206 continue;
9207 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009208
Douglas Gregor3e308b12012-02-14 19:27:52 +00009209 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009210 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9211 }
Richard Smith9467be42014-06-06 17:33:35 +00009212
9213 // FIXME: Retain a pack expansion if RetainExpansion is true.
9214
Douglas Gregor3e308b12012-02-14 19:27:52 +00009215 continue;
9216 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009217
Douglas Gregor3e308b12012-02-14 19:27:52 +00009218 EllipsisLoc = C->getEllipsisLoc();
9219 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009220
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009221 // Transform the captured variable.
9222 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009223 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009224 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009225 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009226 Invalid = true;
9227 continue;
9228 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009229
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009230 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00009231 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009232 }
9233 if (!FinishedExplicitCaptures)
9234 getSema().finishLambdaExplicitCaptures(LSI);
9235
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009236
9237 // Enter a new evaluation context to insulate the lambda from any
9238 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009239 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009240
9241 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009242 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009243 /*IsInstantiation=*/true);
9244 return ExprError();
9245 }
9246
9247 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00009248 StmtResult Body = getDerived().TransformStmt(E->getBody());
9249 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009250 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009251 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009252 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009253 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009254
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009255 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009256 /*CurScope=*/nullptr,
9257 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00009258}
9259
9260template<typename Derived>
9261ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009262TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009263 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009264 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9265 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009266 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009267
Douglas Gregora16548e2009-08-11 05:31:07 +00009268 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009269 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009270 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009271 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009272 &ArgumentChanged))
9273 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009274
Douglas Gregora16548e2009-08-11 05:31:07 +00009275 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009276 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009277 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009278 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009279
Douglas Gregora16548e2009-08-11 05:31:07 +00009280 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009281 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009282 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009283 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009284 E->getRParenLoc());
9285}
Mike Stump11289f42009-09-09 15:08:12 +00009286
Douglas Gregora16548e2009-08-11 05:31:07 +00009287template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009288ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009289TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009290 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009291 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009292 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009293 Expr *OldBase;
9294 QualType BaseType;
9295 QualType ObjectType;
9296 if (!E->isImplicitAccess()) {
9297 OldBase = E->getBase();
9298 Base = getDerived().TransformExpr(OldBase);
9299 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009300 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009301
John McCall2d74de92009-12-01 22:10:20 +00009302 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009303 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009304 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009305 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009306 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009307 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009308 ObjectTy,
9309 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009310 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009311 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009312
John McCallba7bf592010-08-24 05:47:05 +00009313 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009314 BaseType = ((Expr*) Base.get())->getType();
9315 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009316 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009317 BaseType = getDerived().TransformType(E->getBaseType());
9318 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9319 }
Mike Stump11289f42009-09-09 15:08:12 +00009320
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009321 // Transform the first part of the nested-name-specifier that qualifies
9322 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009323 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009324 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009325 E->getFirstQualifierFoundInScope(),
9326 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009327
Douglas Gregore16af532011-02-28 18:50:33 +00009328 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009329 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009330 QualifierLoc
9331 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9332 ObjectType,
9333 FirstQualifierInScope);
9334 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009335 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009336 }
Mike Stump11289f42009-09-09 15:08:12 +00009337
Abramo Bagnara7945c982012-01-27 09:46:47 +00009338 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9339
John McCall31f82722010-11-12 08:19:04 +00009340 // TODO: If this is a conversion-function-id, verify that the
9341 // destination type name (if present) resolves the same way after
9342 // instantiation as it did in the local scope.
9343
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009344 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009345 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009346 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009347 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009348
John McCall2d74de92009-12-01 22:10:20 +00009349 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009350 // This is a reference to a member without an explicitly-specified
9351 // template argument list. Optimize for this common case.
9352 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009353 Base.get() == OldBase &&
9354 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009355 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009356 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009357 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009358 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009359
John McCallb268a282010-08-23 23:25:46 +00009360 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009361 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009362 E->isArrow(),
9363 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009364 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009365 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009366 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009367 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009368 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009369 }
9370
John McCall6b51f282009-11-23 01:53:49 +00009371 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009372 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9373 E->getNumTemplateArgs(),
9374 TransArgs))
9375 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009376
John McCallb268a282010-08-23 23:25:46 +00009377 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009378 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009379 E->isArrow(),
9380 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009381 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009382 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009383 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009384 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009385 &TransArgs);
9386}
9387
9388template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009389ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009390TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009391 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009392 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009393 QualType BaseType;
9394 if (!Old->isImplicitAccess()) {
9395 Base = getDerived().TransformExpr(Old->getBase());
9396 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009397 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009398 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009399 Old->isArrow());
9400 if (Base.isInvalid())
9401 return ExprError();
9402 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009403 } else {
9404 BaseType = getDerived().TransformType(Old->getBaseType());
9405 }
John McCall10eae182009-11-30 22:42:35 +00009406
Douglas Gregor0da1d432011-02-28 20:01:57 +00009407 NestedNameSpecifierLoc QualifierLoc;
9408 if (Old->getQualifierLoc()) {
9409 QualifierLoc
9410 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9411 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009412 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009413 }
9414
Abramo Bagnara7945c982012-01-27 09:46:47 +00009415 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9416
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009417 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009418 Sema::LookupOrdinaryName);
9419
9420 // Transform all the decls.
9421 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9422 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009423 NamedDecl *InstD = static_cast<NamedDecl*>(
9424 getDerived().TransformDecl(Old->getMemberLoc(),
9425 *I));
John McCall84d87672009-12-10 09:41:52 +00009426 if (!InstD) {
9427 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9428 // This can happen because of dependent hiding.
9429 if (isa<UsingShadowDecl>(*I))
9430 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009431 else {
9432 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009433 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009434 }
John McCall84d87672009-12-10 09:41:52 +00009435 }
John McCall10eae182009-11-30 22:42:35 +00009436
9437 // Expand using declarations.
9438 if (isa<UsingDecl>(InstD)) {
9439 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009440 for (auto *I : UD->shadows())
9441 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009442 continue;
9443 }
9444
9445 R.addDecl(InstD);
9446 }
9447
9448 R.resolveKind();
9449
Douglas Gregor9262f472010-04-27 18:19:34 +00009450 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009451 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009452 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009453 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009454 Old->getMemberLoc(),
9455 Old->getNamingClass()));
9456 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009457 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009458
Douglas Gregorda7be082010-04-27 16:10:10 +00009459 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009460 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009461
John McCall10eae182009-11-30 22:42:35 +00009462 TemplateArgumentListInfo TransArgs;
9463 if (Old->hasExplicitTemplateArgs()) {
9464 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9465 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009466 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9467 Old->getNumTemplateArgs(),
9468 TransArgs))
9469 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009470 }
John McCall38836f02010-01-15 08:34:02 +00009471
9472 // FIXME: to do this check properly, we will need to preserve the
9473 // first-qualifier-in-scope here, just in case we had a dependent
9474 // base (and therefore couldn't do the check) and a
9475 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009476 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009477
John McCallb268a282010-08-23 23:25:46 +00009478 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009479 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009480 Old->getOperatorLoc(),
9481 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009482 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009483 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009484 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009485 R,
9486 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009487 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009488}
9489
9490template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009491ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009492TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009493 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009494 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9495 if (SubExpr.isInvalid())
9496 return ExprError();
9497
9498 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009499 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009500
9501 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9502}
9503
9504template<typename Derived>
9505ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009506TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009507 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9508 if (Pattern.isInvalid())
9509 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009510
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009511 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009512 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009513
Douglas Gregorb8840002011-01-14 21:20:45 +00009514 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9515 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009516}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009517
9518template<typename Derived>
9519ExprResult
9520TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9521 // If E is not value-dependent, then nothing will change when we transform it.
9522 // Note: This is an instantiation-centric view.
9523 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009524 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009525
9526 // Note: None of the implementations of TryExpandParameterPacks can ever
9527 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009528 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009529 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9530 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009531 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009532 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009533 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009534 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009535 ShouldExpand, RetainExpansion,
9536 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009537 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009538
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009539 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009540 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009541
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009542 NamedDecl *Pack = E->getPack();
9543 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009544 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009545 Pack));
9546 if (!Pack)
9547 return ExprError();
9548 }
9549
Chad Rosier1dcde962012-08-08 18:46:20 +00009550
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009551 // We now know the length of the parameter pack, so build a new expression
9552 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009553 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9554 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009555 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009556}
9557
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009558template<typename Derived>
9559ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009560TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9561 SubstNonTypeTemplateParmPackExpr *E) {
9562 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009563 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009564}
9565
9566template<typename Derived>
9567ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009568TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9569 SubstNonTypeTemplateParmExpr *E) {
9570 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009571 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009572}
9573
9574template<typename Derived>
9575ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009576TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9577 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009578 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009579}
9580
9581template<typename Derived>
9582ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009583TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9584 MaterializeTemporaryExpr *E) {
9585 return getDerived().TransformExpr(E->GetTemporaryExpr());
9586}
Chad Rosier1dcde962012-08-08 18:46:20 +00009587
Douglas Gregorfe314812011-06-21 17:03:29 +00009588template<typename Derived>
9589ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +00009590TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
9591 Expr *Pattern = E->getPattern();
9592
9593 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9594 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
9595 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9596
9597 // Determine whether the set of unexpanded parameter packs can and should
9598 // be expanded.
9599 bool Expand = true;
9600 bool RetainExpansion = false;
9601 Optional<unsigned> NumExpansions;
9602 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
9603 Pattern->getSourceRange(),
9604 Unexpanded,
9605 Expand, RetainExpansion,
9606 NumExpansions))
9607 return true;
9608
9609 if (!Expand) {
9610 // Do not expand any packs here, just transform and rebuild a fold
9611 // expression.
9612 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9613
9614 ExprResult LHS =
9615 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
9616 if (LHS.isInvalid())
9617 return true;
9618
9619 ExprResult RHS =
9620 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
9621 if (RHS.isInvalid())
9622 return true;
9623
9624 if (!getDerived().AlwaysRebuild() &&
9625 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
9626 return E;
9627
9628 return getDerived().RebuildCXXFoldExpr(
9629 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
9630 RHS.get(), E->getLocEnd());
9631 }
9632
9633 // The transform has determined that we should perform an elementwise
9634 // expansion of the pattern. Do so.
9635 ExprResult Result = getDerived().TransformExpr(E->getInit());
9636 if (Result.isInvalid())
9637 return true;
9638 bool LeftFold = E->isLeftFold();
9639
9640 // If we're retaining an expansion for a right fold, it is the innermost
9641 // component and takes the init (if any).
9642 if (!LeftFold && RetainExpansion) {
9643 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9644
9645 ExprResult Out = getDerived().TransformExpr(Pattern);
9646 if (Out.isInvalid())
9647 return true;
9648
9649 Result = getDerived().RebuildCXXFoldExpr(
9650 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
9651 Result.get(), E->getLocEnd());
9652 if (Result.isInvalid())
9653 return true;
9654 }
9655
9656 for (unsigned I = 0; I != *NumExpansions; ++I) {
9657 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
9658 getSema(), LeftFold ? I : *NumExpansions - I - 1);
9659 ExprResult Out = getDerived().TransformExpr(Pattern);
9660 if (Out.isInvalid())
9661 return true;
9662
9663 if (Out.get()->containsUnexpandedParameterPack()) {
9664 // We still have a pack; retain a pack expansion for this slice.
9665 Result = getDerived().RebuildCXXFoldExpr(
9666 E->getLocStart(),
9667 LeftFold ? Result.get() : Out.get(),
9668 E->getOperator(), E->getEllipsisLoc(),
9669 LeftFold ? Out.get() : Result.get(),
9670 E->getLocEnd());
9671 } else if (Result.isUsable()) {
9672 // We've got down to a single element; build a binary operator.
9673 Result = getDerived().RebuildBinaryOperator(
9674 E->getEllipsisLoc(), E->getOperator(),
9675 LeftFold ? Result.get() : Out.get(),
9676 LeftFold ? Out.get() : Result.get());
9677 } else
9678 Result = Out;
9679
9680 if (Result.isInvalid())
9681 return true;
9682 }
9683
9684 // If we're retaining an expansion for a left fold, it is the outermost
9685 // component and takes the complete expansion so far as its init (if any).
9686 if (LeftFold && RetainExpansion) {
9687 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9688
9689 ExprResult Out = getDerived().TransformExpr(Pattern);
9690 if (Out.isInvalid())
9691 return true;
9692
9693 Result = getDerived().RebuildCXXFoldExpr(
9694 E->getLocStart(), Result.get(),
9695 E->getOperator(), E->getEllipsisLoc(),
9696 Out.get(), E->getLocEnd());
9697 if (Result.isInvalid())
9698 return true;
9699 }
9700
9701 // If we had no init and an empty pack, and we're not retaining an expansion,
9702 // then produce a fallback value or error.
9703 if (Result.isUnset())
9704 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
9705 E->getOperator());
9706
9707 return Result;
9708}
9709
9710template<typename Derived>
9711ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009712TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9713 CXXStdInitializerListExpr *E) {
9714 return getDerived().TransformExpr(E->getSubExpr());
9715}
9716
9717template<typename Derived>
9718ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009719TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009720 return SemaRef.MaybeBindToTemporary(E);
9721}
9722
9723template<typename Derived>
9724ExprResult
9725TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009726 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009727}
9728
9729template<typename Derived>
9730ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009731TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9732 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9733 if (SubExpr.isInvalid())
9734 return ExprError();
9735
9736 if (!getDerived().AlwaysRebuild() &&
9737 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009738 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009739
9740 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009741}
9742
9743template<typename Derived>
9744ExprResult
9745TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9746 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009747 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009748 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009749 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009750 /*IsCall=*/false, Elements, &ArgChanged))
9751 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009752
Ted Kremeneke65b0862012-03-06 20:05:56 +00009753 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9754 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009755
Ted Kremeneke65b0862012-03-06 20:05:56 +00009756 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9757 Elements.data(),
9758 Elements.size());
9759}
9760
9761template<typename Derived>
9762ExprResult
9763TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009764 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009765 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009766 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009767 bool ArgChanged = false;
9768 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9769 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009770
Ted Kremeneke65b0862012-03-06 20:05:56 +00009771 if (OrigElement.isPackExpansion()) {
9772 // This key/value element is a pack expansion.
9773 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9774 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9775 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9776 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9777
9778 // Determine whether the set of unexpanded parameter packs can
9779 // and should be expanded.
9780 bool Expand = true;
9781 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009782 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9783 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009784 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9785 OrigElement.Value->getLocEnd());
9786 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9787 PatternRange,
9788 Unexpanded,
9789 Expand, RetainExpansion,
9790 NumExpansions))
9791 return ExprError();
9792
9793 if (!Expand) {
9794 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009795 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009796 // expansion.
9797 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9798 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9799 if (Key.isInvalid())
9800 return ExprError();
9801
9802 if (Key.get() != OrigElement.Key)
9803 ArgChanged = true;
9804
9805 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9806 if (Value.isInvalid())
9807 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009808
Ted Kremeneke65b0862012-03-06 20:05:56 +00009809 if (Value.get() != OrigElement.Value)
9810 ArgChanged = true;
9811
Chad Rosier1dcde962012-08-08 18:46:20 +00009812 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009813 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9814 };
9815 Elements.push_back(Expansion);
9816 continue;
9817 }
9818
9819 // Record right away that the argument was changed. This needs
9820 // to happen even if the array expands to nothing.
9821 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009822
Ted Kremeneke65b0862012-03-06 20:05:56 +00009823 // The transform has determined that we should perform an elementwise
9824 // expansion of the pattern. Do so.
9825 for (unsigned I = 0; I != *NumExpansions; ++I) {
9826 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9827 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9828 if (Key.isInvalid())
9829 return ExprError();
9830
9831 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9832 if (Value.isInvalid())
9833 return ExprError();
9834
Chad Rosier1dcde962012-08-08 18:46:20 +00009835 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009836 Key.get(), Value.get(), SourceLocation(), NumExpansions
9837 };
9838
9839 // If any unexpanded parameter packs remain, we still have a
9840 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +00009841 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +00009842 if (Key.get()->containsUnexpandedParameterPack() ||
9843 Value.get()->containsUnexpandedParameterPack())
9844 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009845
Ted Kremeneke65b0862012-03-06 20:05:56 +00009846 Elements.push_back(Element);
9847 }
9848
Richard Smith9467be42014-06-06 17:33:35 +00009849 // FIXME: Retain a pack expansion if RetainExpansion is true.
9850
Ted Kremeneke65b0862012-03-06 20:05:56 +00009851 // We've finished with this pack expansion.
9852 continue;
9853 }
9854
9855 // Transform and check key.
9856 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9857 if (Key.isInvalid())
9858 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009859
Ted Kremeneke65b0862012-03-06 20:05:56 +00009860 if (Key.get() != OrigElement.Key)
9861 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009862
Ted Kremeneke65b0862012-03-06 20:05:56 +00009863 // Transform and check value.
9864 ExprResult Value
9865 = getDerived().TransformExpr(OrigElement.Value);
9866 if (Value.isInvalid())
9867 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009868
Ted Kremeneke65b0862012-03-06 20:05:56 +00009869 if (Value.get() != OrigElement.Value)
9870 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009871
9872 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009873 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009874 };
9875 Elements.push_back(Element);
9876 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009877
Ted Kremeneke65b0862012-03-06 20:05:56 +00009878 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9879 return SemaRef.MaybeBindToTemporary(E);
9880
9881 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9882 Elements.data(),
9883 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009884}
9885
Mike Stump11289f42009-09-09 15:08:12 +00009886template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009887ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009888TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009889 TypeSourceInfo *EncodedTypeInfo
9890 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9891 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009892 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009893
Douglas Gregora16548e2009-08-11 05:31:07 +00009894 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009895 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009896 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009897
9898 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009899 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009900 E->getRParenLoc());
9901}
Mike Stump11289f42009-09-09 15:08:12 +00009902
Douglas Gregora16548e2009-08-11 05:31:07 +00009903template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009904ExprResult TreeTransform<Derived>::
9905TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009906 // This is a kind of implicit conversion, and it needs to get dropped
9907 // and recomputed for the same general reasons that ImplicitCastExprs
9908 // do, as well a more specific one: this expression is only valid when
9909 // it appears *immediately* as an argument expression.
9910 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009911}
9912
9913template<typename Derived>
9914ExprResult TreeTransform<Derived>::
9915TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009916 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009917 = getDerived().TransformType(E->getTypeInfoAsWritten());
9918 if (!TSInfo)
9919 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009920
John McCall31168b02011-06-15 23:02:42 +00009921 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009922 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009923 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009924
John McCall31168b02011-06-15 23:02:42 +00009925 if (!getDerived().AlwaysRebuild() &&
9926 TSInfo == E->getTypeInfoAsWritten() &&
9927 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009928 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009929
John McCall31168b02011-06-15 23:02:42 +00009930 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009931 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009932 Result.get());
9933}
9934
9935template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009936ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009937TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009938 // Transform arguments.
9939 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009940 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009941 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009942 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009943 &ArgChanged))
9944 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009945
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009946 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9947 // Class message: transform the receiver type.
9948 TypeSourceInfo *ReceiverTypeInfo
9949 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9950 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009951 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009952
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009953 // If nothing changed, just retain the existing message send.
9954 if (!getDerived().AlwaysRebuild() &&
9955 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009956 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009957
9958 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009959 SmallVector<SourceLocation, 16> SelLocs;
9960 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009961 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9962 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009963 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009964 E->getMethodDecl(),
9965 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009966 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009967 E->getRightLoc());
9968 }
9969
9970 // Instance message: transform the receiver
9971 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9972 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009973 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009974 = getDerived().TransformExpr(E->getInstanceReceiver());
9975 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009976 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009977
9978 // If nothing changed, just retain the existing message send.
9979 if (!getDerived().AlwaysRebuild() &&
9980 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009981 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009982
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009983 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009984 SmallVector<SourceLocation, 16> SelLocs;
9985 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009986 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009987 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009988 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009989 E->getMethodDecl(),
9990 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009991 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009992 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009993}
9994
Mike Stump11289f42009-09-09 15:08:12 +00009995template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009996ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009997TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009998 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009999}
10000
Mike Stump11289f42009-09-09 15:08:12 +000010001template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010002ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010003TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010004 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010005}
10006
Mike Stump11289f42009-09-09 15:08:12 +000010007template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010008ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010009TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010010 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010011 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010012 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010013 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010014
10015 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010016
Douglas Gregord51d90d2010-04-26 20:11:03 +000010017 // If nothing changed, just retain the existing expression.
10018 if (!getDerived().AlwaysRebuild() &&
10019 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010020 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010021
John McCallb268a282010-08-23 23:25:46 +000010022 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010023 E->getLocation(),
10024 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010025}
10026
Mike Stump11289f42009-09-09 15:08:12 +000010027template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010028ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010029TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010030 // 'super' and types never change. Property never changes. Just
10031 // retain the existing expression.
10032 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010033 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010034
Douglas Gregor9faee212010-04-26 20:47:02 +000010035 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010036 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010037 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010038 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010039
Douglas Gregor9faee212010-04-26 20:47:02 +000010040 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010041
Douglas Gregor9faee212010-04-26 20:47:02 +000010042 // If nothing changed, just retain the existing expression.
10043 if (!getDerived().AlwaysRebuild() &&
10044 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010045 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010046
John McCallb7bd14f2010-12-02 01:19:52 +000010047 if (E->isExplicitProperty())
10048 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10049 E->getExplicitProperty(),
10050 E->getLocation());
10051
10052 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010053 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010054 E->getImplicitPropertyGetter(),
10055 E->getImplicitPropertySetter(),
10056 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010057}
10058
Mike Stump11289f42009-09-09 15:08:12 +000010059template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010060ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010061TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10062 // Transform the base expression.
10063 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10064 if (Base.isInvalid())
10065 return ExprError();
10066
10067 // Transform the key expression.
10068 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10069 if (Key.isInvalid())
10070 return ExprError();
10071
10072 // If nothing changed, just retain the existing expression.
10073 if (!getDerived().AlwaysRebuild() &&
10074 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010075 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010076
Chad Rosier1dcde962012-08-08 18:46:20 +000010077 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010078 Base.get(), Key.get(),
10079 E->getAtIndexMethodDecl(),
10080 E->setAtIndexMethodDecl());
10081}
10082
10083template<typename Derived>
10084ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010085TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *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();
Chad Rosier1dcde962012-08-08 18:46:20 +000010090
Douglas Gregord51d90d2010-04-26 20:11:03 +000010091 // If nothing changed, just retain the existing expression.
10092 if (!getDerived().AlwaysRebuild() &&
10093 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010094 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010095
John McCallb268a282010-08-23 23:25:46 +000010096 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010097 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010098 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010099}
10100
Mike Stump11289f42009-09-09 15:08:12 +000010101template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010102ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010103TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010104 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010105 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010106 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010107 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010108 SubExprs, &ArgumentChanged))
10109 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010110
Douglas Gregora16548e2009-08-11 05:31:07 +000010111 if (!getDerived().AlwaysRebuild() &&
10112 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010113 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010114
Douglas Gregora16548e2009-08-11 05:31:07 +000010115 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010116 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010117 E->getRParenLoc());
10118}
10119
Mike Stump11289f42009-09-09 15:08:12 +000010120template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010121ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010122TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10123 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10124 if (SrcExpr.isInvalid())
10125 return ExprError();
10126
10127 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10128 if (!Type)
10129 return ExprError();
10130
10131 if (!getDerived().AlwaysRebuild() &&
10132 Type == E->getTypeSourceInfo() &&
10133 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010134 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010135
10136 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10137 SrcExpr.get(), Type,
10138 E->getRParenLoc());
10139}
10140
10141template<typename Derived>
10142ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010143TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010144 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010145
Craig Topperc3ec1492014-05-26 06:22:03 +000010146 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010147 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10148
10149 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010150 blockScope->TheDecl->setBlockMissingReturnType(
10151 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010152
Chris Lattner01cf8db2011-07-20 06:58:45 +000010153 SmallVector<ParmVarDecl*, 4> params;
10154 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010155
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010156 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010157 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
10158 oldBlock->param_begin(),
10159 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010160 nullptr, paramTypes, &params)) {
10161 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010162 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010163 }
John McCall490112f2011-02-04 18:33:18 +000010164
Jordan Rosea0a86be2013-03-08 22:25:36 +000010165 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000010166 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000010167 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000010168
Jordan Rose5c382722013-03-08 21:51:21 +000010169 QualType functionType =
10170 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010171 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000010172 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000010173
10174 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000010175 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000010176 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000010177
10178 if (!oldBlock->blockMissingReturnType()) {
10179 blockScope->HasImplicitReturnType = false;
10180 blockScope->ReturnType = exprResultType;
10181 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010182
John McCall3882ace2011-01-05 12:14:39 +000010183 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000010184 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010185 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010186 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000010187 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010188 }
John McCall3882ace2011-01-05 12:14:39 +000010189
John McCall490112f2011-02-04 18:33:18 +000010190#ifndef NDEBUG
10191 // In builds with assertions, make sure that we captured everything we
10192 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010193 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010194 for (const auto &I : oldBlock->captures()) {
10195 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010196
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010197 // Ignore parameter packs.
10198 if (isa<ParmVarDecl>(oldCapture) &&
10199 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10200 continue;
John McCall490112f2011-02-04 18:33:18 +000010201
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010202 VarDecl *newCapture =
10203 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10204 oldCapture));
10205 assert(blockScope->CaptureMap.count(newCapture));
10206 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010207 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010208 }
10209#endif
10210
10211 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010212 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010213}
10214
Mike Stump11289f42009-09-09 15:08:12 +000010215template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010216ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010217TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010218 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010219}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010220
10221template<typename Derived>
10222ExprResult
10223TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010224 QualType RetTy = getDerived().TransformType(E->getType());
10225 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010226 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010227 SubExprs.reserve(E->getNumSubExprs());
10228 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10229 SubExprs, &ArgumentChanged))
10230 return ExprError();
10231
10232 if (!getDerived().AlwaysRebuild() &&
10233 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010234 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010235
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010236 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010237 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010238}
Chad Rosier1dcde962012-08-08 18:46:20 +000010239
Douglas Gregora16548e2009-08-11 05:31:07 +000010240//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010241// Type reconstruction
10242//===----------------------------------------------------------------------===//
10243
Mike Stump11289f42009-09-09 15:08:12 +000010244template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010245QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10246 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010247 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010248 getDerived().getBaseEntity());
10249}
10250
Mike Stump11289f42009-09-09 15:08:12 +000010251template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010252QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10253 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010254 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010255 getDerived().getBaseEntity());
10256}
10257
Mike Stump11289f42009-09-09 15:08:12 +000010258template<typename Derived>
10259QualType
John McCall70dd5f62009-10-30 00:06:24 +000010260TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10261 bool WrittenAsLValue,
10262 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010263 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010264 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010265}
10266
10267template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010268QualType
John McCall70dd5f62009-10-30 00:06:24 +000010269TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10270 QualType ClassType,
10271 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010272 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10273 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010274}
10275
10276template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010277QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010278TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10279 ArrayType::ArraySizeModifier SizeMod,
10280 const llvm::APInt *Size,
10281 Expr *SizeExpr,
10282 unsigned IndexTypeQuals,
10283 SourceRange BracketsRange) {
10284 if (SizeExpr || !Size)
10285 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10286 IndexTypeQuals, BracketsRange,
10287 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010288
10289 QualType Types[] = {
10290 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10291 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10292 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010293 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010294 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010295 QualType SizeType;
10296 for (unsigned I = 0; I != NumTypes; ++I)
10297 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10298 SizeType = Types[I];
10299 break;
10300 }
Mike Stump11289f42009-09-09 15:08:12 +000010301
Eli Friedman9562f392012-01-25 23:20:27 +000010302 // Note that we can return a VariableArrayType here in the case where
10303 // the element type was a dependent VariableArrayType.
10304 IntegerLiteral *ArraySize
10305 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10306 /*FIXME*/BracketsRange.getBegin());
10307 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010308 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010309 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010310}
Mike Stump11289f42009-09-09 15:08:12 +000010311
Douglas Gregord6ff3322009-08-04 16:50:30 +000010312template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010313QualType
10314TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010315 ArrayType::ArraySizeModifier SizeMod,
10316 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010317 unsigned IndexTypeQuals,
10318 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010319 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010320 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010321}
10322
10323template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010324QualType
Mike Stump11289f42009-09-09 15:08:12 +000010325TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010326 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010327 unsigned IndexTypeQuals,
10328 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010329 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010330 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010331}
Mike Stump11289f42009-09-09 15:08:12 +000010332
Douglas Gregord6ff3322009-08-04 16:50:30 +000010333template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010334QualType
10335TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010336 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010337 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010338 unsigned IndexTypeQuals,
10339 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010340 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010341 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010342 IndexTypeQuals, BracketsRange);
10343}
10344
10345template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010346QualType
10347TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010348 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010349 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010350 unsigned IndexTypeQuals,
10351 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010352 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010353 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010354 IndexTypeQuals, BracketsRange);
10355}
10356
10357template<typename Derived>
10358QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010359 unsigned NumElements,
10360 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010361 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010362 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010363}
Mike Stump11289f42009-09-09 15:08:12 +000010364
Douglas Gregord6ff3322009-08-04 16:50:30 +000010365template<typename Derived>
10366QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10367 unsigned NumElements,
10368 SourceLocation AttributeLoc) {
10369 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10370 NumElements, true);
10371 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010372 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10373 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010374 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010375}
Mike Stump11289f42009-09-09 15:08:12 +000010376
Douglas Gregord6ff3322009-08-04 16:50:30 +000010377template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010378QualType
10379TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010380 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010381 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010382 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010383}
Mike Stump11289f42009-09-09 15:08:12 +000010384
Douglas Gregord6ff3322009-08-04 16:50:30 +000010385template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010386QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10387 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010388 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010389 const FunctionProtoType::ExtProtoInfo &EPI) {
10390 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010391 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010392 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010393 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010394}
Mike Stump11289f42009-09-09 15:08:12 +000010395
Douglas Gregord6ff3322009-08-04 16:50:30 +000010396template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010397QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10398 return SemaRef.Context.getFunctionNoProtoType(T);
10399}
10400
10401template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010402QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10403 assert(D && "no decl found");
10404 if (D->isInvalidDecl()) return QualType();
10405
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010406 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010407 TypeDecl *Ty;
10408 if (isa<UsingDecl>(D)) {
10409 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010410 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010411 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10412
10413 // A valid resolved using typename decl points to exactly one type decl.
10414 assert(++Using->shadow_begin() == Using->shadow_end());
10415 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010416
John McCallb96ec562009-12-04 22:46:56 +000010417 } else {
10418 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10419 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10420 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10421 }
10422
10423 return SemaRef.Context.getTypeDeclType(Ty);
10424}
10425
10426template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010427QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10428 SourceLocation Loc) {
10429 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010430}
10431
10432template<typename Derived>
10433QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10434 return SemaRef.Context.getTypeOfType(Underlying);
10435}
10436
10437template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010438QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10439 SourceLocation Loc) {
10440 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010441}
10442
10443template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010444QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10445 UnaryTransformType::UTTKind UKind,
10446 SourceLocation Loc) {
10447 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10448}
10449
10450template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010451QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010452 TemplateName Template,
10453 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010454 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010455 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010456}
Mike Stump11289f42009-09-09 15:08:12 +000010457
Douglas Gregor1135c352009-08-06 05:28:30 +000010458template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010459QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10460 SourceLocation KWLoc) {
10461 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10462}
10463
10464template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010465TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010466TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010467 bool TemplateKW,
10468 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010469 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010470 Template);
10471}
10472
10473template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010474TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010475TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10476 const IdentifierInfo &Name,
10477 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010478 QualType ObjectType,
10479 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010480 UnqualifiedId TemplateName;
10481 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010482 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010483 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010484 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010485 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010486 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010487 /*EnteringContext=*/false,
10488 Template);
John McCall31f82722010-11-12 08:19:04 +000010489 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010490}
Mike Stump11289f42009-09-09 15:08:12 +000010491
Douglas Gregora16548e2009-08-11 05:31:07 +000010492template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010493TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010494TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010495 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010496 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010497 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010498 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010499 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010500 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010501 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010502 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010503 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010504 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010505 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010506 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010507 /*EnteringContext=*/false,
10508 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010509 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010510}
Chad Rosier1dcde962012-08-08 18:46:20 +000010511
Douglas Gregor71395fa2009-11-04 00:56:37 +000010512template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010513ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010514TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10515 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010516 Expr *OrigCallee,
10517 Expr *First,
10518 Expr *Second) {
10519 Expr *Callee = OrigCallee->IgnoreParenCasts();
10520 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010521
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010522 if (First->getObjectKind() == OK_ObjCProperty) {
10523 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10524 if (BinaryOperator::isAssignmentOp(Opc))
10525 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10526 First, Second);
10527 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10528 if (Result.isInvalid())
10529 return ExprError();
10530 First = Result.get();
10531 }
10532
10533 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10534 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10535 if (Result.isInvalid())
10536 return ExprError();
10537 Second = Result.get();
10538 }
10539
Douglas Gregora16548e2009-08-11 05:31:07 +000010540 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010541 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010542 if (!First->getType()->isOverloadableType() &&
10543 !Second->getType()->isOverloadableType())
10544 return getSema().CreateBuiltinArraySubscriptExpr(First,
10545 Callee->getLocStart(),
10546 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010547 } else if (Op == OO_Arrow) {
10548 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010549 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10550 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010551 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010552 // The argument is not of overloadable type, so try to create a
10553 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010554 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010555 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010556
John McCallb268a282010-08-23 23:25:46 +000010557 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010558 }
10559 } else {
John McCallb268a282010-08-23 23:25:46 +000010560 if (!First->getType()->isOverloadableType() &&
10561 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010562 // Neither of the arguments is an overloadable type, so try to
10563 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010564 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010565 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010566 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010567 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010568 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010569
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010570 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010571 }
10572 }
Mike Stump11289f42009-09-09 15:08:12 +000010573
10574 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010575 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010576 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010577
John McCallb268a282010-08-23 23:25:46 +000010578 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010579 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010580 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010581 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010582 // If we've resolved this to a particular non-member function, just call
10583 // that function. If we resolved it to a member function,
10584 // CreateOverloaded* will find that function for us.
10585 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10586 if (!isa<CXXMethodDecl>(ND))
10587 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000010588 }
Mike Stump11289f42009-09-09 15:08:12 +000010589
Douglas Gregora16548e2009-08-11 05:31:07 +000010590 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000010591 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000010592 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000010593
Douglas Gregora16548e2009-08-11 05:31:07 +000010594 // Create the overloaded operator invocation for unary operators.
10595 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000010596 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010597 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000010598 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010599 }
Mike Stump11289f42009-09-09 15:08:12 +000010600
Douglas Gregore9d62932011-07-15 16:25:15 +000010601 if (Op == OO_Subscript) {
10602 SourceLocation LBrace;
10603 SourceLocation RBrace;
10604
10605 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000010606 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000010607 LBrace = SourceLocation::getFromRawEncoding(
10608 NameLoc.CXXOperatorName.BeginOpNameLoc);
10609 RBrace = SourceLocation::getFromRawEncoding(
10610 NameLoc.CXXOperatorName.EndOpNameLoc);
10611 } else {
10612 LBrace = Callee->getLocStart();
10613 RBrace = OpLoc;
10614 }
10615
10616 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10617 First, Second);
10618 }
Sebastian Redladba46e2009-10-29 20:17:01 +000010619
Douglas Gregora16548e2009-08-11 05:31:07 +000010620 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000010621 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010622 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000010623 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10624 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010625 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010626
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010627 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010628}
Mike Stump11289f42009-09-09 15:08:12 +000010629
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010630template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010631ExprResult
John McCallb268a282010-08-23 23:25:46 +000010632TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010633 SourceLocation OperatorLoc,
10634 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010635 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010636 TypeSourceInfo *ScopeType,
10637 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010638 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010639 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010640 QualType BaseType = Base->getType();
10641 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010642 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010643 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010644 !BaseType->getAs<PointerType>()->getPointeeType()
10645 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010646 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +000010647 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010648 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010649 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010650 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010651 /*FIXME?*/true);
10652 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010653
Douglas Gregor678f90d2010-02-25 01:56:36 +000010654 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010655 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10656 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10657 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10658 NameInfo.setNamedTypeInfo(DestroyedType);
10659
Richard Smith8e4a3862012-05-15 06:15:11 +000010660 // The scope type is now known to be a valid nested name specifier
10661 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000010662 if (ScopeType) {
10663 if (!ScopeType->getType()->getAs<TagType>()) {
10664 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
10665 diag::err_expected_class_or_namespace)
10666 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
10667 return ExprError();
10668 }
10669 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
10670 CCLoc);
10671 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010672
Abramo Bagnara7945c982012-01-27 09:46:47 +000010673 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010674 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010675 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010676 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010677 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010678 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010679 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010680}
10681
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010682template<typename Derived>
10683StmtResult
10684TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010685 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010686 CapturedDecl *CD = S->getCapturedDecl();
10687 unsigned NumParams = CD->getNumParams();
10688 unsigned ContextParamPos = CD->getContextParamPosition();
10689 SmallVector<Sema::CapturedParamNameType, 4> Params;
10690 for (unsigned I = 0; I < NumParams; ++I) {
10691 if (I != ContextParamPos) {
10692 Params.push_back(
10693 std::make_pair(
10694 CD->getParam(I)->getName(),
10695 getDerived().TransformType(CD->getParam(I)->getType())));
10696 } else {
10697 Params.push_back(std::make_pair(StringRef(), QualType()));
10698 }
10699 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010700 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010701 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010702 StmtResult Body;
10703 {
10704 Sema::CompoundScopeRAII CompoundScope(getSema());
10705 Body = getDerived().TransformStmt(S->getCapturedStmt());
10706 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010707
10708 if (Body.isInvalid()) {
10709 getSema().ActOnCapturedRegionError();
10710 return StmtError();
10711 }
10712
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010713 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010714}
10715
Douglas Gregord6ff3322009-08-04 16:50:30 +000010716} // end namespace clang
10717
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000010718#endif