blob: 3b2a17c54973e0b7dfb3a74e11e2870d5ff52211 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000016
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000101
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000106
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000114
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000119
Mike Stump11289f42009-09-09 15:08:12 +0000120public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000123
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 }
131
John McCalldadc5752010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000134
Douglas Gregord6ff3322009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000144 ///
145 /// We must always rebuild all AST nodes when performing variadic template
146 /// pack expansion, in order to avoid violating the AST invariant that each
147 /// statement node appears at most once in its containing declaration.
148 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregord6ff3322009-08-04 16:50:30 +0000150 /// \brief Returns the location of the entity being transformed, if that
151 /// information was not available elsewhere in the AST.
152 ///
Mike Stump11289f42009-09-09 15:08:12 +0000153 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000154 /// provide an alternative implementation that provides better location
155 /// information.
156 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregord6ff3322009-08-04 16:50:30 +0000158 /// \brief Returns the name of the entity being transformed, if that
159 /// information was not available elsewhere in the AST.
160 ///
161 /// By default, returns an empty name. Subclasses can provide an alternative
162 /// implementation with a more precise name.
163 DeclarationName getBaseEntity() { return DeclarationName(); }
164
Douglas Gregora16548e2009-08-11 05:31:07 +0000165 /// \brief Sets the "base" location and entity when that
166 /// information is known based on another transformation.
167 ///
168 /// By default, the source location and entity are ignored. Subclasses can
169 /// override this function to provide a customized implementation.
170 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000171
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 /// \brief RAII object that temporarily sets the base location and entity
173 /// used for reporting diagnostics in types.
174 class TemporaryBase {
175 TreeTransform &Self;
176 SourceLocation OldLocation;
177 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 public:
180 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000181 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000182 OldLocation = Self.getDerived().getBaseLocation();
183 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000184
Douglas Gregora518d5b2011-01-25 17:51:48 +0000185 if (Location.isValid())
186 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000187 }
Mike Stump11289f42009-09-09 15:08:12 +0000188
Douglas Gregora16548e2009-08-11 05:31:07 +0000189 ~TemporaryBase() {
190 Self.getDerived().setBase(OldLocation, OldEntity);
191 }
192 };
Mike Stump11289f42009-09-09 15:08:12 +0000193
194 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000195 /// transformed.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000198 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000199 /// not change. For example, template instantiation need not traverse
200 /// non-dependent types.
201 bool AlreadyTransformed(QualType T) {
202 return T.isNull();
203 }
204
Douglas Gregord196a582009-12-14 19:27:10 +0000205 /// \brief Determine whether the given call argument should be dropped, e.g.,
206 /// because it is a default argument.
207 ///
208 /// Subclasses can provide an alternative implementation of this routine to
209 /// determine which kinds of call arguments get dropped. By default,
210 /// CXXDefaultArgument nodes are dropped (prior to transformation).
211 bool DropCallArgument(Expr *E) {
212 return E->isDefaultArgument();
213 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000214
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000215 /// \brief Determine whether we should expand a pack expansion with the
216 /// given set of parameter packs into separate arguments by repeatedly
217 /// transforming the pattern.
218 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000219 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000220 /// Subclasses can override this routine to provide different behavior.
221 ///
222 /// \param EllipsisLoc The location of the ellipsis that identifies the
223 /// pack expansion.
224 ///
225 /// \param PatternRange The source range that covers the entire pattern of
226 /// the pack expansion.
227 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000228 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000229 /// pattern.
230 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// \param ShouldExpand Will be set to \c true if the transformer should
232 /// expand the corresponding pack expansions into separate arguments. When
233 /// set, \c NumExpansions must also be set.
234 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000235 /// \param RetainExpansion Whether the caller should add an unexpanded
236 /// pack expansion after all of the expanded arguments. This is used
237 /// when extending explicitly-specified template argument packs per
238 /// C++0x [temp.arg.explicit]p9.
239 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000241 /// the expanded form of the corresponding pack expansion. This is both an
242 /// input and an output parameter, which can be set by the caller if the
243 /// number of expansions is known a priori (e.g., due to a prior substitution)
244 /// and will be set by the callee when the number of expansions is known.
245 /// The callee must set this value when \c ShouldExpand is \c true; it may
246 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000247 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000248 /// \returns true if an error occurred (e.g., because the parameter packs
249 /// are to be instantiated with arguments of different lengths), false
250 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 /// must be set.
252 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
253 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000254 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000255 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000257 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000258 ShouldExpand = false;
259 return false;
260 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000261
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000262 /// \brief "Forget" about the partially-substituted pack template argument,
263 /// when performing an instantiation that must preserve the parameter pack
264 /// use.
265 ///
266 /// This routine is meant to be overridden by the template instantiator.
267 TemplateArgument ForgetPartiallySubstitutedPack() {
268 return TemplateArgument();
269 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000270
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000271 /// \brief "Remember" the partially-substituted pack template argument
272 /// after performing an instantiation that must preserve the parameter pack
273 /// use.
274 ///
275 /// This routine is meant to be overridden by the template instantiator.
276 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000277
Douglas Gregorf3010112011-01-07 16:43:16 +0000278 /// \brief Note to the derived class when a function parameter pack is
279 /// being expanded.
280 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transforms the given type into another type.
283 ///
John McCall550e0c22009-10-21 00:40:46 +0000284 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000285 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000286 /// function. This is expensive, but we don't mind, because
287 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000288 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
290 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000291 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000292
John McCall550e0c22009-10-21 00:40:46 +0000293 /// \brief Transforms the given type-with-location into a new
294 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000295 ///
John McCall550e0c22009-10-21 00:40:46 +0000296 /// By default, this routine transforms a type by delegating to the
297 /// appropriate TransformXXXType to build a new type. Subclasses
298 /// may override this function (to take over all type
299 /// transformations) or some set of the TransformXXXType functions
300 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000301 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000302
303 /// \brief Transform the given type-with-location into a new
304 /// type, collecting location information in the given builder
305 /// as necessary.
306 ///
John McCall31f82722010-11-12 08:19:04 +0000307 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000308
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000309 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000310 ///
Mike Stump11289f42009-09-09 15:08:12 +0000311 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000312 /// appropriate TransformXXXStmt function to transform a specific kind of
313 /// statement or the TransformExpr() function to transform an expression.
314 /// Subclasses may override this function to transform statements using some
315 /// other mechanism.
316 ///
317 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000318 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000319
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000320 /// \brief Transform the given statement.
321 ///
322 /// By default, this routine transforms a statement by delegating to the
323 /// appropriate TransformOMPXXXClause function to transform a specific kind
324 /// of clause. Subclasses may override this function to transform statements
325 /// using some other mechanism.
326 ///
327 /// \returns the transformed OpenMP clause.
328 OMPClause *TransformOMPClause(OMPClause *S);
329
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000330 /// \brief Transform the given attribute.
331 ///
332 /// By default, this routine transforms a statement by delegating to the
333 /// appropriate TransformXXXAttr function to transform a specific kind
334 /// of attribute. Subclasses may override this function to transform
335 /// attributed statements using some other mechanism.
336 ///
337 /// \returns the transformed attribute
338 const Attr *TransformAttr(const Attr *S);
339
340/// \brief Transform the specified attribute.
341///
342/// Subclasses should override the transformation of attributes with a pragma
343/// spelling to transform expressions stored within the attribute.
344///
345/// \returns the transformed attribute.
346#define ATTR(X)
347#define PRAGMA_SPELLING_ATTR(X) \
348 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
349#include "clang/Basic/AttrList.inc"
350
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000351 /// \brief Transform the given expression.
352 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000353 /// By default, this routine transforms an expression by delegating to the
354 /// appropriate TransformXXXExpr function to build a new expression.
355 /// Subclasses may override this function to transform expressions using some
356 /// other mechanism.
357 ///
358 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000359 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000360
Richard Smithd59b8322012-12-19 01:39:02 +0000361 /// \brief Transform the given initializer.
362 ///
363 /// By default, this routine transforms an initializer by stripping off the
364 /// semantic nodes added by initialization, then passing the result to
365 /// TransformExpr or TransformExprs.
366 ///
367 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000368 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000369
Douglas Gregora3efea12011-01-03 19:04:46 +0000370 /// \brief Transform the given list of expressions.
371 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000372 /// This routine transforms a list of expressions by invoking
373 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000374 /// support for variadic templates by expanding any pack expansions (if the
375 /// derived class permits such expansion) along the way. When pack expansions
376 /// are present, the number of outputs may not equal the number of inputs.
377 ///
378 /// \param Inputs The set of expressions to be transformed.
379 ///
380 /// \param NumInputs The number of expressions in \c Inputs.
381 ///
382 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000383 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000384 /// be.
385 ///
386 /// \param Outputs The transformed input expressions will be added to this
387 /// vector.
388 ///
389 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
390 /// due to transformation.
391 ///
392 /// \returns true if an error occurred, false otherwise.
393 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000394 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000395 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000396
Douglas Gregord6ff3322009-08-04 16:50:30 +0000397 /// \brief Transform the given declaration, which is referenced from a type
398 /// or expression.
399 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000400 /// By default, acts as the identity function on declarations, unless the
401 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000402 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000403 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000404 llvm::DenseMap<Decl *, Decl *>::iterator Known
405 = TransformedLocalDecls.find(D);
406 if (Known != TransformedLocalDecls.end())
407 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
409 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000410 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000411
Chad Rosier1dcde962012-08-08 18:46:20 +0000412 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000413 /// place them on the new declaration.
414 ///
415 /// By default, this operation does nothing. Subclasses may override this
416 /// behavior to transform attributes.
417 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000418
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000419 /// \brief Note that a local declaration has been transformed by this
420 /// transformer.
421 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000422 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000423 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
424 /// the transformer itself has to transform the declarations. This routine
425 /// can be overridden by a subclass that keeps track of such mappings.
426 void transformedLocalDecl(Decl *Old, Decl *New) {
427 TransformedLocalDecls[Old] = New;
428 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000429
Douglas Gregorebe10102009-08-20 07:17:43 +0000430 /// \brief Transform the definition of the given declaration.
431 ///
Mike Stump11289f42009-09-09 15:08:12 +0000432 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000433 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000434 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
435 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000436 }
Mike Stump11289f42009-09-09 15:08:12 +0000437
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000438 /// \brief Transform the given declaration, which was the first part of a
439 /// nested-name-specifier in a member access expression.
440 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000441 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000442 /// identifier in a nested-name-specifier of a member access expression, e.g.,
443 /// the \c T in \c x->T::member
444 ///
445 /// By default, invokes TransformDecl() to transform the declaration.
446 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000447 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
448 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000449 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000450
Douglas Gregor14454802011-02-25 02:25:35 +0000451 /// \brief Transform the given nested-name-specifier with source-location
452 /// information.
453 ///
454 /// By default, transforms all of the types and declarations within the
455 /// nested-name-specifier. Subclasses may override this function to provide
456 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000457 NestedNameSpecifierLoc
458 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
459 QualType ObjectType = QualType(),
460 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000461
Douglas Gregorf816bd72009-09-03 22:13:48 +0000462 /// \brief Transform the given declaration name.
463 ///
464 /// By default, transforms the types of conversion function, constructor,
465 /// and destructor names and then (if needed) rebuilds the declaration name.
466 /// Identifiers and selectors are returned unmodified. Sublcasses may
467 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000468 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000469 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000470
Douglas Gregord6ff3322009-08-04 16:50:30 +0000471 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000472 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000473 /// \param SS The nested-name-specifier that qualifies the template
474 /// name. This nested-name-specifier must already have been transformed.
475 ///
476 /// \param Name The template name to transform.
477 ///
478 /// \param NameLoc The source location of the template name.
479 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000480 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000481 /// access expression, this is the type of the object whose member template
482 /// is being referenced.
483 ///
484 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
485 /// also refers to a name within the current (lexical) scope, this is the
486 /// declaration it refers to.
487 ///
488 /// By default, transforms the template name by transforming the declarations
489 /// and nested-name-specifiers that occur within the template name.
490 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000491 TemplateName
492 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
493 SourceLocation NameLoc,
494 QualType ObjectType = QualType(),
495 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000496
Douglas Gregord6ff3322009-08-04 16:50:30 +0000497 /// \brief Transform the given template argument.
498 ///
Mike Stump11289f42009-09-09 15:08:12 +0000499 /// By default, this operation transforms the type, expression, or
500 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000501 /// new template argument from the transformed result. Subclasses may
502 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000503 ///
504 /// Returns true if there was an error.
505 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
506 TemplateArgumentLoc &Output);
507
Douglas Gregor62e06f22010-12-20 17:31:10 +0000508 /// \brief Transform the given set of template arguments.
509 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000510 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000511 /// in the input set using \c TransformTemplateArgument(), and appends
512 /// the transformed arguments to the output list.
513 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000514 /// Note that this overload of \c TransformTemplateArguments() is merely
515 /// a convenience function. Subclasses that wish to override this behavior
516 /// should override the iterator-based member template version.
517 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000518 /// \param Inputs The set of template arguments to be transformed.
519 ///
520 /// \param NumInputs The number of template arguments in \p Inputs.
521 ///
522 /// \param Outputs The set of transformed template arguments output by this
523 /// routine.
524 ///
525 /// Returns true if an error occurred.
526 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
527 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000528 TemplateArgumentListInfo &Outputs) {
529 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
530 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000531
532 /// \brief Transform the given set of template arguments.
533 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000534 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000535 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000536 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000537 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000538 /// \param First An iterator to the first template argument.
539 ///
540 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000541 ///
542 /// \param Outputs The set of transformed template arguments output by this
543 /// routine.
544 ///
545 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000546 template<typename InputIterator>
547 bool TransformTemplateArguments(InputIterator First,
548 InputIterator Last,
549 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000550
John McCall0ad16662009-10-29 08:12:44 +0000551 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
552 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
553 TemplateArgumentLoc &ArgLoc);
554
John McCallbcd03502009-12-07 02:54:59 +0000555 /// \brief Fakes up a TypeSourceInfo for a type.
556 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
557 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000558 getDerived().getBaseLocation());
559 }
Mike Stump11289f42009-09-09 15:08:12 +0000560
John McCall550e0c22009-10-21 00:40:46 +0000561#define ABSTRACT_TYPELOC(CLASS, PARENT)
562#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000563 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000564#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000565
Richard Smith2e321552014-11-12 02:00:47 +0000566 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000567 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
568 FunctionProtoTypeLoc TL,
569 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000570 unsigned ThisTypeQuals,
571 Fn TransformExceptionSpec);
572
573 bool TransformExceptionSpec(SourceLocation Loc,
574 FunctionProtoType::ExceptionSpecInfo &ESI,
575 SmallVectorImpl<QualType> &Exceptions,
576 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000577
David Majnemerfad8f482013-10-15 09:33:02 +0000578 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000579
Chad Rosier1dcde962012-08-08 18:46:20 +0000580 QualType
John McCall31f82722010-11-12 08:19:04 +0000581 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
582 TemplateSpecializationTypeLoc TL,
583 TemplateName Template);
584
Chad Rosier1dcde962012-08-08 18:46:20 +0000585 QualType
John McCall31f82722010-11-12 08:19:04 +0000586 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
587 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000588 TemplateName Template,
589 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000590
Nico Weberc153d242014-07-28 00:02:09 +0000591 QualType TransformDependentTemplateSpecializationType(
592 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
593 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000594
John McCall58f10c32010-03-11 09:03:00 +0000595 /// \brief Transforms the parameters of a function type into the
596 /// given vectors.
597 ///
598 /// The result vectors should be kept in sync; null entries in the
599 /// variables vector are acceptable.
600 ///
601 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000602 bool TransformFunctionTypeParams(SourceLocation Loc,
603 ParmVarDecl **Params, unsigned NumParams,
604 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000605 SmallVectorImpl<QualType> &PTypes,
606 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000607
608 /// \brief Transforms a single function-type parameter. Return null
609 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000610 ///
611 /// \param indexAdjustment - A number to add to the parameter's
612 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000613 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000614 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000615 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000616 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000617
John McCall31f82722010-11-12 08:19:04 +0000618 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000619
John McCalldadc5752010-08-24 06:29:42 +0000620 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
621 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000622
Faisal Vali2cba1332013-10-23 06:44:28 +0000623 TemplateParameterList *TransformTemplateParameterList(
624 TemplateParameterList *TPL) {
625 return TPL;
626 }
627
Richard Smithdb2630f2012-10-21 03:28:35 +0000628 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000629
Richard Smithdb2630f2012-10-21 03:28:35 +0000630 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000631 bool IsAddressOfOperand,
632 TypeSourceInfo **RecoveryTSI);
633
634 ExprResult TransformParenDependentScopeDeclRefExpr(
635 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
636 TypeSourceInfo **RecoveryTSI);
637
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000638 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000639
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000640// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
641// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000642#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000643 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000644 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000645#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000646 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000647 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000648#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000649#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000650
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000651#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000652 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000653 OMPClause *Transform ## Class(Class *S);
654#include "clang/Basic/OpenMPKinds.def"
655
Douglas Gregord6ff3322009-08-04 16:50:30 +0000656 /// \brief Build a new pointer type given its pointee type.
657 ///
658 /// By default, performs semantic analysis when building the pointer type.
659 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000660 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661
662 /// \brief Build a new block pointer type given its pointee type.
663 ///
Mike Stump11289f42009-09-09 15:08:12 +0000664 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000665 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000666 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667
John McCall70dd5f62009-10-30 00:06:24 +0000668 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000669 ///
John McCall70dd5f62009-10-30 00:06:24 +0000670 /// By default, performs semantic analysis when building the
671 /// reference type. Subclasses may override this routine to provide
672 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000673 ///
John McCall70dd5f62009-10-30 00:06:24 +0000674 /// \param LValue whether the type was written with an lvalue sigil
675 /// or an rvalue sigil.
676 QualType RebuildReferenceType(QualType ReferentType,
677 bool LValue,
678 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000679
Douglas Gregord6ff3322009-08-04 16:50:30 +0000680 /// \brief Build a new member pointer type given the pointee type and the
681 /// class type it refers into.
682 ///
683 /// By default, performs semantic analysis when building the member pointer
684 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000685 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
686 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000687
Douglas Gregord6ff3322009-08-04 16:50:30 +0000688 /// \brief Build a new array type given the element type, size
689 /// modifier, size of the array (if known), size expression, and index type
690 /// qualifiers.
691 ///
692 /// By default, performs semantic analysis when building the array type.
693 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000694 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 QualType RebuildArrayType(QualType ElementType,
696 ArrayType::ArraySizeModifier SizeMod,
697 const llvm::APInt *Size,
698 Expr *SizeExpr,
699 unsigned IndexTypeQuals,
700 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000701
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702 /// \brief Build a new constant array type given the element type, size
703 /// modifier, (known) size of the array, and index type qualifiers.
704 ///
705 /// By default, performs semantic analysis when building the array type.
706 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000707 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000708 ArrayType::ArraySizeModifier SizeMod,
709 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000710 unsigned IndexTypeQuals,
711 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000712
Douglas Gregord6ff3322009-08-04 16:50:30 +0000713 /// \brief Build a new incomplete array type given the element type, size
714 /// modifier, and index type qualifiers.
715 ///
716 /// By default, performs semantic analysis when building the array type.
717 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000718 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000719 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000720 unsigned IndexTypeQuals,
721 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000722
Mike Stump11289f42009-09-09 15:08:12 +0000723 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724 /// size modifier, size expression, and index type qualifiers.
725 ///
726 /// By default, performs semantic analysis when building the array type.
727 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000728 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000729 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000730 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000731 unsigned IndexTypeQuals,
732 SourceRange BracketsRange);
733
Mike Stump11289f42009-09-09 15:08:12 +0000734 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000735 /// size modifier, size expression, and index type qualifiers.
736 ///
737 /// By default, performs semantic analysis when building the array type.
738 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000739 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000741 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000742 unsigned IndexTypeQuals,
743 SourceRange BracketsRange);
744
745 /// \brief Build a new vector type given the element type and
746 /// number of elements.
747 ///
748 /// By default, performs semantic analysis when building the vector type.
749 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000750 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000751 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000752
Douglas Gregord6ff3322009-08-04 16:50:30 +0000753 /// \brief Build a new extended vector type given the element type and
754 /// number of elements.
755 ///
756 /// By default, performs semantic analysis when building the vector type.
757 /// Subclasses may override this routine to provide different behavior.
758 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
759 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000760
761 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000762 /// given the element type and number of elements.
763 ///
764 /// By default, performs semantic analysis when building the vector type.
765 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000766 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000767 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000768 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000769
Douglas Gregord6ff3322009-08-04 16:50:30 +0000770 /// \brief Build a new function type.
771 ///
772 /// By default, performs semantic analysis when building the function type.
773 /// Subclasses may override this routine to provide different behavior.
774 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000775 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000776 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000777
John McCall550e0c22009-10-21 00:40:46 +0000778 /// \brief Build a new unprototyped function type.
779 QualType RebuildFunctionNoProtoType(QualType ResultType);
780
John McCallb96ec562009-12-04 22:46:56 +0000781 /// \brief Rebuild an unresolved typename type, given the decl that
782 /// the UnresolvedUsingTypenameDecl was transformed to.
783 QualType RebuildUnresolvedUsingType(Decl *D);
784
Douglas Gregord6ff3322009-08-04 16:50:30 +0000785 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000786 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000787 return SemaRef.Context.getTypeDeclType(Typedef);
788 }
789
790 /// \brief Build a new class/struct/union type.
791 QualType RebuildRecordType(RecordDecl *Record) {
792 return SemaRef.Context.getTypeDeclType(Record);
793 }
794
795 /// \brief Build a new Enum type.
796 QualType RebuildEnumType(EnumDecl *Enum) {
797 return SemaRef.Context.getTypeDeclType(Enum);
798 }
John McCallfcc33b02009-09-05 00:15:47 +0000799
Mike Stump11289f42009-09-09 15:08:12 +0000800 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000801 ///
802 /// By default, performs semantic analysis when building the typeof type.
803 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000804 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000805
Mike Stump11289f42009-09-09 15:08:12 +0000806 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000807 ///
808 /// By default, builds a new TypeOfType with the given underlying type.
809 QualType RebuildTypeOfType(QualType Underlying);
810
Alexis Hunte852b102011-05-24 22:41:36 +0000811 /// \brief Build a new unary transform type.
812 QualType RebuildUnaryTransformType(QualType BaseType,
813 UnaryTransformType::UTTKind UKind,
814 SourceLocation Loc);
815
Richard Smith74aeef52013-04-26 16:15:35 +0000816 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000817 ///
818 /// By default, performs semantic analysis when building the decltype type.
819 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000820 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000821
Richard Smith74aeef52013-04-26 16:15:35 +0000822 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000823 ///
824 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000825 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000826 // Note, IsDependent is always false here: we implicitly convert an 'auto'
827 // which has been deduced to a dependent type into an undeduced 'auto', so
828 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000829 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
830 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000831 }
832
Douglas Gregord6ff3322009-08-04 16:50:30 +0000833 /// \brief Build a new template specialization type.
834 ///
835 /// By default, performs semantic analysis when building the template
836 /// specialization type. Subclasses may override this routine to provide
837 /// different behavior.
838 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000839 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000840 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000841
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000842 /// \brief Build a new parenthesized type.
843 ///
844 /// By default, builds a new ParenType type from the inner type.
845 /// Subclasses may override this routine to provide different behavior.
846 QualType RebuildParenType(QualType InnerType) {
847 return SemaRef.Context.getParenType(InnerType);
848 }
849
Douglas Gregord6ff3322009-08-04 16:50:30 +0000850 /// \brief Build a new qualified name type.
851 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000852 /// By default, builds a new ElaboratedType type from the keyword,
853 /// the nested-name-specifier and the named type.
854 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000855 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
856 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000857 NestedNameSpecifierLoc QualifierLoc,
858 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000859 return SemaRef.Context.getElaboratedType(Keyword,
860 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000861 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000862 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000863
864 /// \brief Build a new typename type that refers to a template-id.
865 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000866 /// By default, builds a new DependentNameType type from the
867 /// nested-name-specifier and the given type. Subclasses may override
868 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000869 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000870 ElaboratedTypeKeyword Keyword,
871 NestedNameSpecifierLoc QualifierLoc,
872 const IdentifierInfo *Name,
873 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000874 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000875 // Rebuild the template name.
876 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000877 CXXScopeSpec SS;
878 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000879 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000880 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
881 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000882
Douglas Gregora7a795b2011-03-01 20:11:18 +0000883 if (InstName.isNull())
884 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000885
Douglas Gregora7a795b2011-03-01 20:11:18 +0000886 // If it's still dependent, make a dependent specialization.
887 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000888 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
889 QualifierLoc.getNestedNameSpecifier(),
890 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000891 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000892
Douglas Gregora7a795b2011-03-01 20:11:18 +0000893 // Otherwise, make an elaborated type wrapping a non-dependent
894 // specialization.
895 QualType T =
896 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
897 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000898
Craig Topperc3ec1492014-05-26 06:22:03 +0000899 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000900 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000901
902 return SemaRef.Context.getElaboratedType(Keyword,
903 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000904 T);
905 }
906
Douglas Gregord6ff3322009-08-04 16:50:30 +0000907 /// \brief Build a new typename type that refers to an identifier.
908 ///
909 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000910 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000911 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000912 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000913 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000914 NestedNameSpecifierLoc QualifierLoc,
915 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000916 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000917 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000918 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000919
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000920 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000921 // If the name is still dependent, just build a new dependent name type.
922 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000923 return SemaRef.Context.getDependentNameType(Keyword,
924 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000925 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000926 }
927
Abramo Bagnara6150c882010-05-11 21:36:43 +0000928 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000929 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000930 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000931
932 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
933
Abramo Bagnarad7548482010-05-19 21:37:53 +0000934 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000935 // into a non-dependent elaborated-type-specifier. Find the tag we're
936 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000937 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000938 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
939 if (!DC)
940 return QualType();
941
John McCallbf8c5192010-05-27 06:40:31 +0000942 if (SemaRef.RequireCompleteDeclContext(SS, DC))
943 return QualType();
944
Craig Topperc3ec1492014-05-26 06:22:03 +0000945 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000946 SemaRef.LookupQualifiedName(Result, DC);
947 switch (Result.getResultKind()) {
948 case LookupResult::NotFound:
949 case LookupResult::NotFoundInCurrentInstantiation:
950 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000951
Douglas Gregore677daf2010-03-31 22:19:08 +0000952 case LookupResult::Found:
953 Tag = Result.getAsSingle<TagDecl>();
954 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000955
Douglas Gregore677daf2010-03-31 22:19:08 +0000956 case LookupResult::FoundOverloaded:
957 case LookupResult::FoundUnresolvedValue:
958 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000959
Douglas Gregore677daf2010-03-31 22:19:08 +0000960 case LookupResult::Ambiguous:
961 // Let the LookupResult structure handle ambiguities.
962 return QualType();
963 }
964
965 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000966 // Check where the name exists but isn't a tag type and use that to emit
967 // better diagnostics.
968 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
969 SemaRef.LookupQualifiedName(Result, DC);
970 switch (Result.getResultKind()) {
971 case LookupResult::Found:
972 case LookupResult::FoundOverloaded:
973 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000974 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000975 unsigned Kind = 0;
976 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000977 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
978 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000979 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
980 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
981 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000982 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000983 default:
Nick Lewycky0c438082011-01-24 19:01:04 +0000984 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000985 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000986 break;
987 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000988 return QualType();
989 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000990
Richard Trieucaa33d32011-06-10 03:11:26 +0000991 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
992 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000993 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000994 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
995 return QualType();
996 }
997
998 // Build the elaborated-type-specifier type.
999 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001000 return SemaRef.Context.getElaboratedType(Keyword,
1001 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001002 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001003 }
Mike Stump11289f42009-09-09 15:08:12 +00001004
Douglas Gregor822d0302011-01-12 17:07:58 +00001005 /// \brief Build a new pack expansion type.
1006 ///
1007 /// By default, builds a new PackExpansionType type from the given pattern.
1008 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001009 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001010 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001011 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001012 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001013 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1014 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001015 }
1016
Eli Friedman0dfb8892011-10-06 23:00:33 +00001017 /// \brief Build a new atomic type given its value type.
1018 ///
1019 /// By default, performs semantic analysis when building the atomic type.
1020 /// Subclasses may override this routine to provide different behavior.
1021 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1022
Douglas Gregor71dc5092009-08-06 06:41:21 +00001023 /// \brief Build a new template name given a nested name specifier, a flag
1024 /// indicating whether the "template" keyword was provided, and the template
1025 /// that the template name refers to.
1026 ///
1027 /// By default, builds the new template name directly. Subclasses may override
1028 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001029 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001030 bool TemplateKW,
1031 TemplateDecl *Template);
1032
Douglas Gregor71dc5092009-08-06 06:41:21 +00001033 /// \brief Build a new template name given a nested name specifier and the
1034 /// name that is referred to as a template.
1035 ///
1036 /// By default, performs semantic analysis to determine whether the name can
1037 /// be resolved to a specific template, then builds the appropriate kind of
1038 /// template name. Subclasses may override this routine to provide different
1039 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001040 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1041 const IdentifierInfo &Name,
1042 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001043 QualType ObjectType,
1044 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001045
Douglas Gregor71395fa2009-11-04 00:56:37 +00001046 /// \brief Build a new template name given a nested name specifier and the
1047 /// overloaded operator name that is referred to as a template.
1048 ///
1049 /// By default, performs semantic analysis to determine whether the name can
1050 /// be resolved to a specific template, then builds the appropriate kind of
1051 /// template name. Subclasses may override this routine to provide different
1052 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001053 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001054 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001055 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001056 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001057
1058 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001059 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001060 ///
1061 /// By default, performs semantic analysis to determine whether the name can
1062 /// be resolved to a specific template, then builds the appropriate kind of
1063 /// template name. Subclasses may override this routine to provide different
1064 /// behavior.
1065 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1066 const TemplateArgument &ArgPack) {
1067 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1068 }
1069
Douglas Gregorebe10102009-08-20 07:17:43 +00001070 /// \brief Build a new compound statement.
1071 ///
1072 /// By default, performs semantic analysis to build the new statement.
1073 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001074 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001075 MultiStmtArg Statements,
1076 SourceLocation RBraceLoc,
1077 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001078 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001079 IsStmtExpr);
1080 }
1081
1082 /// \brief Build a new case statement.
1083 ///
1084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001086 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001087 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001088 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001089 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001090 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001091 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001092 ColonLoc);
1093 }
Mike Stump11289f42009-09-09 15:08:12 +00001094
Douglas Gregorebe10102009-08-20 07:17:43 +00001095 /// \brief Attach the body to a new case statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001099 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001100 getSema().ActOnCaseStmtBody(S, Body);
1101 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001102 }
Mike Stump11289f42009-09-09 15:08:12 +00001103
Douglas Gregorebe10102009-08-20 07:17:43 +00001104 /// \brief Build a new default statement.
1105 ///
1106 /// By default, performs semantic analysis to build the new statement.
1107 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001108 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001109 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001110 Stmt *SubStmt) {
1111 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001112 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 }
Mike Stump11289f42009-09-09 15:08:12 +00001114
Douglas Gregorebe10102009-08-20 07:17:43 +00001115 /// \brief Build a new label statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001119 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1120 SourceLocation ColonLoc, Stmt *SubStmt) {
1121 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001122 }
Mike Stump11289f42009-09-09 15:08:12 +00001123
Richard Smithc202b282012-04-14 00:33:13 +00001124 /// \brief Build a new label statement.
1125 ///
1126 /// By default, performs semantic analysis to build the new statement.
1127 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001128 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1129 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001130 Stmt *SubStmt) {
1131 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1132 }
1133
Douglas Gregorebe10102009-08-20 07:17:43 +00001134 /// \brief Build a new "if" statement.
1135 ///
1136 /// By default, performs semantic analysis to build the new statement.
1137 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001138 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001139 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001140 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001141 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001142 }
Mike Stump11289f42009-09-09 15:08:12 +00001143
Douglas Gregorebe10102009-08-20 07:17:43 +00001144 /// \brief Start building a new switch statement.
1145 ///
1146 /// By default, performs semantic analysis to build the new statement.
1147 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001148 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001149 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001150 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001151 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001152 }
Mike Stump11289f42009-09-09 15:08:12 +00001153
Douglas Gregorebe10102009-08-20 07:17:43 +00001154 /// \brief Attach the body to the switch statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001158 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001159 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001160 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001161 }
1162
1163 /// \brief Build a new while statement.
1164 ///
1165 /// By default, performs semantic analysis to build the new statement.
1166 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001167 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1168 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001169 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001170 }
Mike Stump11289f42009-09-09 15:08:12 +00001171
Douglas Gregorebe10102009-08-20 07:17:43 +00001172 /// \brief Build a new do-while statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001176 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001177 SourceLocation WhileLoc, SourceLocation LParenLoc,
1178 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001179 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1180 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001181 }
1182
1183 /// \brief Build a new for statement.
1184 ///
1185 /// By default, performs semantic analysis to build the new statement.
1186 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001187 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001188 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001189 VarDecl *CondVar, Sema::FullExprArg Inc,
1190 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001191 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001192 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001193 }
Mike Stump11289f42009-09-09 15:08:12 +00001194
Douglas Gregorebe10102009-08-20 07:17:43 +00001195 /// \brief Build a new goto statement.
1196 ///
1197 /// By default, performs semantic analysis to build the new statement.
1198 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001199 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1200 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001201 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001202 }
1203
1204 /// \brief Build a new indirect goto statement.
1205 ///
1206 /// By default, performs semantic analysis to build the new statement.
1207 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001208 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001209 SourceLocation StarLoc,
1210 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001211 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001212 }
Mike Stump11289f42009-09-09 15:08:12 +00001213
Douglas Gregorebe10102009-08-20 07:17:43 +00001214 /// \brief Build a new return statement.
1215 ///
1216 /// By default, performs semantic analysis to build the new statement.
1217 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001218 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001219 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001220 }
Mike Stump11289f42009-09-09 15:08:12 +00001221
Douglas Gregorebe10102009-08-20 07:17:43 +00001222 /// \brief Build a new declaration statement.
1223 ///
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001226 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001227 SourceLocation StartLoc, SourceLocation EndLoc) {
1228 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001229 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001230 }
Mike Stump11289f42009-09-09 15:08:12 +00001231
Anders Carlssonaaeef072010-01-24 05:50:09 +00001232 /// \brief Build a new inline asm statement.
1233 ///
1234 /// By default, performs semantic analysis to build the new statement.
1235 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001236 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1237 bool IsVolatile, unsigned NumOutputs,
1238 unsigned NumInputs, IdentifierInfo **Names,
1239 MultiExprArg Constraints, MultiExprArg Exprs,
1240 Expr *AsmString, MultiExprArg Clobbers,
1241 SourceLocation RParenLoc) {
1242 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1243 NumInputs, Names, Constraints, Exprs,
1244 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001245 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001246
Chad Rosier32503022012-06-11 20:47:18 +00001247 /// \brief Build a new MS style inline asm statement.
1248 ///
1249 /// By default, performs semantic analysis to build the new statement.
1250 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001251 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001252 ArrayRef<Token> AsmToks,
1253 StringRef AsmString,
1254 unsigned NumOutputs, unsigned NumInputs,
1255 ArrayRef<StringRef> Constraints,
1256 ArrayRef<StringRef> Clobbers,
1257 ArrayRef<Expr*> Exprs,
1258 SourceLocation EndLoc) {
1259 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1260 NumOutputs, NumInputs,
1261 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001262 }
1263
James Dennett2a4d13c2012-06-15 07:13:21 +00001264 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001265 ///
1266 /// By default, performs semantic analysis to build the new statement.
1267 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001268 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001269 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001270 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001271 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001272 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001273 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001274 }
1275
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001276 /// \brief Rebuild an Objective-C exception declaration.
1277 ///
1278 /// By default, performs semantic analysis to build the new declaration.
1279 /// Subclasses may override this routine to provide different behavior.
1280 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1281 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001282 return getSema().BuildObjCExceptionDecl(TInfo, T,
1283 ExceptionDecl->getInnerLocStart(),
1284 ExceptionDecl->getLocation(),
1285 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001286 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001287
James Dennett2a4d13c2012-06-15 07:13:21 +00001288 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001289 ///
1290 /// By default, performs semantic analysis to build the new statement.
1291 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001292 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001293 SourceLocation RParenLoc,
1294 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001295 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001296 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001297 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001298 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001299
James Dennett2a4d13c2012-06-15 07:13:21 +00001300 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001301 ///
1302 /// By default, performs semantic analysis to build the new statement.
1303 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001304 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001305 Stmt *Body) {
1306 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001307 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001308
James Dennett2a4d13c2012-06-15 07:13:21 +00001309 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001310 ///
1311 /// By default, performs semantic analysis to build the new statement.
1312 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001313 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001314 Expr *Operand) {
1315 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001316 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001317
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001318 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001319 ///
1320 /// By default, performs semantic analysis to build the new statement.
1321 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001322 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001323 DeclarationNameInfo DirName,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001324 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001325 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001326 SourceLocation EndLoc) {
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001327 return getSema().ActOnOpenMPExecutableDirective(Kind, DirName, Clauses,
1328 AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001329 }
1330
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001331 /// \brief Build a new OpenMP 'if' clause.
1332 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001333 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001334 /// Subclasses may override this routine to provide different behavior.
1335 OMPClause *RebuildOMPIfClause(Expr *Condition,
1336 SourceLocation StartLoc,
1337 SourceLocation LParenLoc,
1338 SourceLocation EndLoc) {
1339 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1340 LParenLoc, EndLoc);
1341 }
1342
Alexey Bataev3778b602014-07-17 07:32:53 +00001343 /// \brief Build a new OpenMP 'final' clause.
1344 ///
1345 /// By default, performs semantic analysis to build the new OpenMP clause.
1346 /// Subclasses may override this routine to provide different behavior.
1347 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1348 SourceLocation LParenLoc,
1349 SourceLocation EndLoc) {
1350 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1351 EndLoc);
1352 }
1353
Alexey Bataev568a8332014-03-06 06:15:19 +00001354 /// \brief Build a new OpenMP 'num_threads' clause.
1355 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001356 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001357 /// Subclasses may override this routine to provide different behavior.
1358 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1359 SourceLocation StartLoc,
1360 SourceLocation LParenLoc,
1361 SourceLocation EndLoc) {
1362 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1363 LParenLoc, EndLoc);
1364 }
1365
Alexey Bataev62c87d22014-03-21 04:51:18 +00001366 /// \brief Build a new OpenMP 'safelen' clause.
1367 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001368 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001369 /// Subclasses may override this routine to provide different behavior.
1370 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1371 SourceLocation LParenLoc,
1372 SourceLocation EndLoc) {
1373 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1374 }
1375
Alexander Musman8bd31e62014-05-27 15:12:19 +00001376 /// \brief Build a new OpenMP 'collapse' clause.
1377 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001378 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001379 /// Subclasses may override this routine to provide different behavior.
1380 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1381 SourceLocation LParenLoc,
1382 SourceLocation EndLoc) {
1383 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1384 EndLoc);
1385 }
1386
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001387 /// \brief Build a new OpenMP 'default' clause.
1388 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001389 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001390 /// Subclasses may override this routine to provide different behavior.
1391 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1392 SourceLocation KindKwLoc,
1393 SourceLocation StartLoc,
1394 SourceLocation LParenLoc,
1395 SourceLocation EndLoc) {
1396 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1397 StartLoc, LParenLoc, EndLoc);
1398 }
1399
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001400 /// \brief Build a new OpenMP 'proc_bind' clause.
1401 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001402 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001403 /// Subclasses may override this routine to provide different behavior.
1404 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1405 SourceLocation KindKwLoc,
1406 SourceLocation StartLoc,
1407 SourceLocation LParenLoc,
1408 SourceLocation EndLoc) {
1409 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1410 StartLoc, LParenLoc, EndLoc);
1411 }
1412
Alexey Bataev56dafe82014-06-20 07:16:17 +00001413 /// \brief Build a new OpenMP 'schedule' clause.
1414 ///
1415 /// By default, performs semantic analysis to build the new OpenMP clause.
1416 /// Subclasses may override this routine to provide different behavior.
1417 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1418 Expr *ChunkSize,
1419 SourceLocation StartLoc,
1420 SourceLocation LParenLoc,
1421 SourceLocation KindLoc,
1422 SourceLocation CommaLoc,
1423 SourceLocation EndLoc) {
1424 return getSema().ActOnOpenMPScheduleClause(
1425 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1426 }
1427
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001428 /// \brief Build a new OpenMP 'private' clause.
1429 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001430 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001431 /// Subclasses may override this routine to provide different behavior.
1432 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1433 SourceLocation StartLoc,
1434 SourceLocation LParenLoc,
1435 SourceLocation EndLoc) {
1436 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1437 EndLoc);
1438 }
1439
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001440 /// \brief Build a new OpenMP 'firstprivate' clause.
1441 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001442 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001443 /// Subclasses may override this routine to provide different behavior.
1444 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1445 SourceLocation StartLoc,
1446 SourceLocation LParenLoc,
1447 SourceLocation EndLoc) {
1448 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1449 EndLoc);
1450 }
1451
Alexander Musman1bb328c2014-06-04 13:06:39 +00001452 /// \brief Build a new OpenMP 'lastprivate' clause.
1453 ///
1454 /// By default, performs semantic analysis to build the new OpenMP clause.
1455 /// Subclasses may override this routine to provide different behavior.
1456 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1457 SourceLocation StartLoc,
1458 SourceLocation LParenLoc,
1459 SourceLocation EndLoc) {
1460 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1461 EndLoc);
1462 }
1463
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001464 /// \brief Build a new OpenMP 'shared' clause.
1465 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001466 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001467 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001468 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1469 SourceLocation StartLoc,
1470 SourceLocation LParenLoc,
1471 SourceLocation EndLoc) {
1472 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1473 EndLoc);
1474 }
1475
Alexey Bataevc5e02582014-06-16 07:08:35 +00001476 /// \brief Build a new OpenMP 'reduction' clause.
1477 ///
1478 /// By default, performs semantic analysis to build the new statement.
1479 /// Subclasses may override this routine to provide different behavior.
1480 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1481 SourceLocation StartLoc,
1482 SourceLocation LParenLoc,
1483 SourceLocation ColonLoc,
1484 SourceLocation EndLoc,
1485 CXXScopeSpec &ReductionIdScopeSpec,
1486 const DeclarationNameInfo &ReductionId) {
1487 return getSema().ActOnOpenMPReductionClause(
1488 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1489 ReductionId);
1490 }
1491
Alexander Musman8dba6642014-04-22 13:09:42 +00001492 /// \brief Build a new OpenMP 'linear' clause.
1493 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001494 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001495 /// Subclasses may override this routine to provide different behavior.
1496 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1497 SourceLocation StartLoc,
1498 SourceLocation LParenLoc,
1499 SourceLocation ColonLoc,
1500 SourceLocation EndLoc) {
1501 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1502 ColonLoc, EndLoc);
1503 }
1504
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001505 /// \brief Build a new OpenMP 'aligned' clause.
1506 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001507 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001508 /// Subclasses may override this routine to provide different behavior.
1509 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1510 SourceLocation StartLoc,
1511 SourceLocation LParenLoc,
1512 SourceLocation ColonLoc,
1513 SourceLocation EndLoc) {
1514 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1515 LParenLoc, ColonLoc, EndLoc);
1516 }
1517
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001518 /// \brief Build a new OpenMP 'copyin' clause.
1519 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001520 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001521 /// Subclasses may override this routine to provide different behavior.
1522 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1523 SourceLocation StartLoc,
1524 SourceLocation LParenLoc,
1525 SourceLocation EndLoc) {
1526 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1527 EndLoc);
1528 }
1529
Alexey Bataevbae9a792014-06-27 10:37:06 +00001530 /// \brief Build a new OpenMP 'copyprivate' clause.
1531 ///
1532 /// By default, performs semantic analysis to build the new OpenMP clause.
1533 /// Subclasses may override this routine to provide different behavior.
1534 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1535 SourceLocation StartLoc,
1536 SourceLocation LParenLoc,
1537 SourceLocation EndLoc) {
1538 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1539 EndLoc);
1540 }
1541
Alexey Bataev6125da92014-07-21 11:26:11 +00001542 /// \brief Build a new OpenMP 'flush' pseudo clause.
1543 ///
1544 /// By default, performs semantic analysis to build the new OpenMP clause.
1545 /// Subclasses may override this routine to provide different behavior.
1546 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1547 SourceLocation StartLoc,
1548 SourceLocation LParenLoc,
1549 SourceLocation EndLoc) {
1550 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1551 EndLoc);
1552 }
1553
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001554 /// \brief Build a new OpenMP 'depend' pseudo clause.
1555 ///
1556 /// By default, performs semantic analysis to build the new OpenMP clause.
1557 /// Subclasses may override this routine to provide different behavior.
1558 OMPClause *
1559 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1560 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1561 SourceLocation StartLoc, SourceLocation LParenLoc,
1562 SourceLocation EndLoc) {
1563 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1564 StartLoc, LParenLoc, EndLoc);
1565 }
1566
James Dennett2a4d13c2012-06-15 07:13:21 +00001567 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001568 ///
1569 /// By default, performs semantic analysis to build the new statement.
1570 /// Subclasses may override this routine to provide different behavior.
1571 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1572 Expr *object) {
1573 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1574 }
1575
James Dennett2a4d13c2012-06-15 07:13:21 +00001576 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001577 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001578 /// By default, performs semantic analysis to build the new statement.
1579 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001580 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001581 Expr *Object, Stmt *Body) {
1582 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001583 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001584
James Dennett2a4d13c2012-06-15 07:13:21 +00001585 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001586 ///
1587 /// By default, performs semantic analysis to build the new statement.
1588 /// Subclasses may override this routine to provide different behavior.
1589 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1590 Stmt *Body) {
1591 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1592 }
John McCall53848232011-07-27 01:07:15 +00001593
Douglas Gregorf68a5082010-04-22 23:10:45 +00001594 /// \brief Build a new Objective-C fast enumeration statement.
1595 ///
1596 /// By default, performs semantic analysis to build the new statement.
1597 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001598 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001599 Stmt *Element,
1600 Expr *Collection,
1601 SourceLocation RParenLoc,
1602 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001603 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001604 Element,
John McCallb268a282010-08-23 23:25:46 +00001605 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001606 RParenLoc);
1607 if (ForEachStmt.isInvalid())
1608 return StmtError();
1609
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001610 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001611 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001612
Douglas Gregorebe10102009-08-20 07:17:43 +00001613 /// \brief Build a new C++ exception declaration.
1614 ///
1615 /// By default, performs semantic analysis to build the new decaration.
1616 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001617 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001618 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001619 SourceLocation StartLoc,
1620 SourceLocation IdLoc,
1621 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001622 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001623 StartLoc, IdLoc, Id);
1624 if (Var)
1625 getSema().CurContext->addDecl(Var);
1626 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001627 }
1628
1629 /// \brief Build a new C++ catch statement.
1630 ///
1631 /// By default, performs semantic analysis to build the new statement.
1632 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001633 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001634 VarDecl *ExceptionDecl,
1635 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001636 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1637 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001638 }
Mike Stump11289f42009-09-09 15:08:12 +00001639
Douglas Gregorebe10102009-08-20 07:17:43 +00001640 /// \brief Build a new C++ try statement.
1641 ///
1642 /// By default, performs semantic analysis to build the new statement.
1643 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001644 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1645 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001646 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001647 }
Mike Stump11289f42009-09-09 15:08:12 +00001648
Richard Smith02e85f32011-04-14 22:09:26 +00001649 /// \brief Build a new C++0x range-based for statement.
1650 ///
1651 /// By default, performs semantic analysis to build the new statement.
1652 /// Subclasses may override this routine to provide different behavior.
1653 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1654 SourceLocation ColonLoc,
1655 Stmt *Range, Stmt *BeginEnd,
1656 Expr *Cond, Expr *Inc,
1657 Stmt *LoopVar,
1658 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001659 // If we've just learned that the range is actually an Objective-C
1660 // collection, treat this as an Objective-C fast enumeration loop.
1661 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1662 if (RangeStmt->isSingleDecl()) {
1663 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001664 if (RangeVar->isInvalidDecl())
1665 return StmtError();
1666
Douglas Gregorf7106af2013-04-08 18:40:13 +00001667 Expr *RangeExpr = RangeVar->getInit();
1668 if (!RangeExpr->isTypeDependent() &&
1669 RangeExpr->getType()->isObjCObjectPointerType())
1670 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1671 RParenLoc);
1672 }
1673 }
1674 }
1675
Richard Smith02e85f32011-04-14 22:09:26 +00001676 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001677 Cond, Inc, LoopVar, RParenLoc,
1678 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001679 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001680
1681 /// \brief Build a new C++0x range-based for statement.
1682 ///
1683 /// By default, performs semantic analysis to build the new statement.
1684 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001685 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001686 bool IsIfExists,
1687 NestedNameSpecifierLoc QualifierLoc,
1688 DeclarationNameInfo NameInfo,
1689 Stmt *Nested) {
1690 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1691 QualifierLoc, NameInfo, Nested);
1692 }
1693
Richard Smith02e85f32011-04-14 22:09:26 +00001694 /// \brief Attach body to a C++0x range-based for statement.
1695 ///
1696 /// By default, performs semantic analysis to finish the new statement.
1697 /// Subclasses may override this routine to provide different behavior.
1698 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1699 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1700 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001701
David Majnemerfad8f482013-10-15 09:33:02 +00001702 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001703 Stmt *TryBlock, Stmt *Handler) {
1704 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001705 }
1706
David Majnemerfad8f482013-10-15 09:33:02 +00001707 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001708 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001709 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001710 }
1711
David Majnemerfad8f482013-10-15 09:33:02 +00001712 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001713 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001714 }
1715
Alexey Bataevec474782014-10-09 08:45:04 +00001716 /// \brief Build a new predefined expression.
1717 ///
1718 /// By default, performs semantic analysis to build the new expression.
1719 /// Subclasses may override this routine to provide different behavior.
1720 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1721 PredefinedExpr::IdentType IT) {
1722 return getSema().BuildPredefinedExpr(Loc, IT);
1723 }
1724
Douglas Gregora16548e2009-08-11 05:31:07 +00001725 /// \brief Build a new expression that references a declaration.
1726 ///
1727 /// By default, performs semantic analysis to build the new expression.
1728 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001729 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001730 LookupResult &R,
1731 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001732 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1733 }
1734
1735
1736 /// \brief Build a new expression that references a declaration.
1737 ///
1738 /// By default, performs semantic analysis to build the new expression.
1739 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001740 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001741 ValueDecl *VD,
1742 const DeclarationNameInfo &NameInfo,
1743 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001744 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001745 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001746
1747 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001748
1749 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001750 }
Mike Stump11289f42009-09-09 15:08:12 +00001751
Douglas Gregora16548e2009-08-11 05:31:07 +00001752 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001753 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001754 /// By default, performs semantic analysis to build the new expression.
1755 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001756 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001757 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001758 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001759 }
1760
Douglas Gregorad8a3362009-09-04 17:36:40 +00001761 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001762 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001763 /// By default, performs semantic analysis to build the new expression.
1764 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001765 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001766 SourceLocation OperatorLoc,
1767 bool isArrow,
1768 CXXScopeSpec &SS,
1769 TypeSourceInfo *ScopeType,
1770 SourceLocation CCLoc,
1771 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001772 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001773
Douglas Gregora16548e2009-08-11 05:31:07 +00001774 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001775 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001776 /// By default, performs semantic analysis to build the new expression.
1777 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001778 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001779 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001780 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001781 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001782 }
Mike Stump11289f42009-09-09 15:08:12 +00001783
Douglas Gregor882211c2010-04-28 22:16:22 +00001784 /// \brief Build a new builtin offsetof expression.
1785 ///
1786 /// By default, performs semantic analysis to build the new expression.
1787 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001788 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001789 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001790 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001791 unsigned NumComponents,
1792 SourceLocation RParenLoc) {
1793 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1794 NumComponents, RParenLoc);
1795 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001796
1797 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001798 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001799 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001800 /// By default, performs semantic analysis to build the new expression.
1801 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001802 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1803 SourceLocation OpLoc,
1804 UnaryExprOrTypeTrait ExprKind,
1805 SourceRange R) {
1806 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001807 }
1808
Peter Collingbournee190dee2011-03-11 19:24:49 +00001809 /// \brief Build a new sizeof, alignof or vec step expression with an
1810 /// expression argument.
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.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001814 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1815 UnaryExprOrTypeTrait ExprKind,
1816 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001817 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001818 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001819 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001820 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001821
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001822 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001823 }
Mike Stump11289f42009-09-09 15:08:12 +00001824
Douglas Gregora16548e2009-08-11 05:31:07 +00001825 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001826 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001827 /// By default, performs semantic analysis to build the new expression.
1828 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001829 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001830 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001831 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001832 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001833 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001834 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001835 RBracketLoc);
1836 }
1837
1838 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001839 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001840 /// By default, performs semantic analysis to build the new expression.
1841 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001842 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001843 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001844 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001845 Expr *ExecConfig = nullptr) {
1846 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001847 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001848 }
1849
1850 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001851 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001852 /// By default, performs semantic analysis to build the new expression.
1853 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001854 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001855 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001856 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001857 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001858 const DeclarationNameInfo &MemberNameInfo,
1859 ValueDecl *Member,
1860 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001861 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001862 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001863 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1864 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001865 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001866 // We have a reference to an unnamed field. This is always the
1867 // base of an anonymous struct/union member access, i.e. the
1868 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001869 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001870 assert(Member->getType()->isRecordType() &&
1871 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001872
Richard Smithcab9a7d2011-10-26 19:06:56 +00001873 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001874 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001875 QualifierLoc.getNestedNameSpecifier(),
1876 FoundDecl, Member);
1877 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001878 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001879 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001880 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00001881 MemberExpr *ME = new (getSema().Context)
1882 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
1883 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001884 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001885 }
Mike Stump11289f42009-09-09 15:08:12 +00001886
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001887 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001888 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001889
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001890 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001891 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001892
John McCall16df1e52010-03-30 21:47:33 +00001893 // FIXME: this involves duplicating earlier analysis in a lot of
1894 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001895 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001896 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001897 R.resolveKind();
1898
John McCallb268a282010-08-23 23:25:46 +00001899 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001900 SS, TemplateKWLoc,
1901 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001902 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001903 }
Mike Stump11289f42009-09-09 15:08:12 +00001904
Douglas Gregora16548e2009-08-11 05:31:07 +00001905 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001906 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001907 /// By default, performs semantic analysis to build the new expression.
1908 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001909 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001910 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001911 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001912 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 }
1914
1915 /// \brief Build a new conditional operator 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 RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001920 SourceLocation QuestionLoc,
1921 Expr *LHS,
1922 SourceLocation ColonLoc,
1923 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001924 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1925 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 }
1927
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001929 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 /// By default, performs semantic analysis to build the new expression.
1931 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001932 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001933 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001934 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001935 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001936 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001937 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001938 }
Mike Stump11289f42009-09-09 15:08:12 +00001939
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001941 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 /// By default, performs semantic analysis to build the new expression.
1943 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001944 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001945 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001947 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001948 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001949 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001950 }
Mike Stump11289f42009-09-09 15:08:12 +00001951
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001953 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 /// By default, performs semantic analysis to build the new expression.
1955 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001956 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 SourceLocation OpLoc,
1958 SourceLocation AccessorLoc,
1959 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001960
John McCall10eae182009-11-30 22:42:35 +00001961 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001962 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001963 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001964 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001965 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001966 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001967 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001968 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 }
Mike Stump11289f42009-09-09 15:08:12 +00001970
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001972 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 /// By default, performs semantic analysis to build the new expression.
1974 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001975 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001976 MultiExprArg Inits,
1977 SourceLocation RBraceLoc,
1978 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001979 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001980 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001981 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001982 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001983
Douglas Gregord3d93062009-11-09 17:16:50 +00001984 // Patch in the result type we were given, which may have been computed
1985 // when the initial InitListExpr was built.
1986 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1987 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001988 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001989 }
Mike Stump11289f42009-09-09 15:08:12 +00001990
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001992 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 /// By default, performs semantic analysis to build the new expression.
1994 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001995 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001996 MultiExprArg ArrayExprs,
1997 SourceLocation EqualOrColonLoc,
1998 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001999 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002000 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002001 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002002 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002004 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002005
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002006 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002007 }
Mike Stump11289f42009-09-09 15:08:12 +00002008
Douglas Gregora16548e2009-08-11 05:31:07 +00002009 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002010 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002011 /// By default, builds the implicit value initialization without performing
2012 /// any semantic analysis. Subclasses may override this routine to provide
2013 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002014 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002015 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002016 }
Mike Stump11289f42009-09-09 15:08:12 +00002017
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002019 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002020 /// By default, performs semantic analysis to build the new expression.
2021 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002022 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002023 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002024 SourceLocation RParenLoc) {
2025 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002026 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002027 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002028 }
2029
2030 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002031 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002032 /// By default, performs semantic analysis to build the new expression.
2033 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002034 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002035 MultiExprArg SubExprs,
2036 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002037 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002038 }
Mike Stump11289f42009-09-09 15:08:12 +00002039
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002041 ///
2042 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 /// rather than attempting to map the label statement itself.
2044 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002045 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002046 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002047 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002048 }
Mike Stump11289f42009-09-09 15:08:12 +00002049
Douglas Gregora16548e2009-08-11 05:31:07 +00002050 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002051 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002052 /// By default, performs semantic analysis to build the new expression.
2053 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002054 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002055 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002056 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002057 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002058 }
Mike Stump11289f42009-09-09 15:08:12 +00002059
Douglas Gregora16548e2009-08-11 05:31:07 +00002060 /// \brief Build a new __builtin_choose_expr expression.
2061 ///
2062 /// By default, performs semantic analysis to build the new expression.
2063 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002064 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002065 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002066 SourceLocation RParenLoc) {
2067 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002068 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002069 RParenLoc);
2070 }
Mike Stump11289f42009-09-09 15:08:12 +00002071
Peter Collingbourne91147592011-04-15 00:35:48 +00002072 /// \brief Build a new generic selection expression.
2073 ///
2074 /// By default, performs semantic analysis to build the new expression.
2075 /// Subclasses may override this routine to provide different behavior.
2076 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2077 SourceLocation DefaultLoc,
2078 SourceLocation RParenLoc,
2079 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002080 ArrayRef<TypeSourceInfo *> Types,
2081 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002082 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002083 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002084 }
2085
Douglas Gregora16548e2009-08-11 05:31:07 +00002086 /// \brief Build a new overloaded operator call expression.
2087 ///
2088 /// By default, performs semantic analysis to build the new expression.
2089 /// The semantic analysis provides the behavior of template instantiation,
2090 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002091 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002092 /// argument-dependent lookup, etc. Subclasses may override this routine to
2093 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002094 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002095 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002096 Expr *Callee,
2097 Expr *First,
2098 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002099
2100 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002101 /// reinterpret_cast.
2102 ///
2103 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002104 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002105 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002106 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002107 Stmt::StmtClass Class,
2108 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002109 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002110 SourceLocation RAngleLoc,
2111 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002112 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002113 SourceLocation RParenLoc) {
2114 switch (Class) {
2115 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002116 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002117 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002118 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002119
2120 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002121 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002122 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002123 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002124
Douglas Gregora16548e2009-08-11 05:31:07 +00002125 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002126 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002127 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002128 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002129 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002130
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002132 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002133 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002134 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002135
Douglas Gregora16548e2009-08-11 05:31:07 +00002136 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002137 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002139 }
Mike Stump11289f42009-09-09 15:08:12 +00002140
Douglas Gregora16548e2009-08-11 05:31:07 +00002141 /// \brief Build a new C++ static_cast expression.
2142 ///
2143 /// By default, performs semantic analysis to build the new expression.
2144 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002145 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002146 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002147 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002148 SourceLocation RAngleLoc,
2149 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002150 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002151 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002152 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002153 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002154 SourceRange(LAngleLoc, RAngleLoc),
2155 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002156 }
2157
2158 /// \brief Build a new C++ dynamic_cast expression.
2159 ///
2160 /// By default, performs semantic analysis to build the new expression.
2161 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002162 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002163 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002164 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002165 SourceLocation RAngleLoc,
2166 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002167 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002168 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002169 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002170 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002171 SourceRange(LAngleLoc, RAngleLoc),
2172 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 }
2174
2175 /// \brief Build a new C++ reinterpret_cast expression.
2176 ///
2177 /// By default, performs semantic analysis to build the new expression.
2178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002179 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002180 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002181 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002182 SourceLocation RAngleLoc,
2183 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002184 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002185 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002186 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002187 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002188 SourceRange(LAngleLoc, RAngleLoc),
2189 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002190 }
2191
2192 /// \brief Build a new C++ const_cast expression.
2193 ///
2194 /// By default, performs semantic analysis to build the new expression.
2195 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002196 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002197 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002198 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002199 SourceLocation RAngleLoc,
2200 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002201 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002202 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002203 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002204 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002205 SourceRange(LAngleLoc, RAngleLoc),
2206 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002207 }
Mike Stump11289f42009-09-09 15:08:12 +00002208
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 /// \brief Build a new C++ functional-style cast expression.
2210 ///
2211 /// By default, performs semantic analysis to build the new expression.
2212 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002213 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2214 SourceLocation LParenLoc,
2215 Expr *Sub,
2216 SourceLocation RParenLoc) {
2217 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002218 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002219 RParenLoc);
2220 }
Mike Stump11289f42009-09-09 15:08:12 +00002221
Douglas Gregora16548e2009-08-11 05:31:07 +00002222 /// \brief Build a new C++ typeid(type) 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,
2228 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002229 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002230 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002231 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002232 }
Mike Stump11289f42009-09-09 15:08:12 +00002233
Francois Pichet9f4f2072010-09-08 12:20:18 +00002234
Douglas Gregora16548e2009-08-11 05:31:07 +00002235 /// \brief Build a new C++ typeid(expr) expression.
2236 ///
2237 /// By default, performs semantic analysis to build the new expression.
2238 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002239 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002240 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002241 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002242 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002243 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002244 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002245 }
2246
Francois Pichet9f4f2072010-09-08 12:20:18 +00002247 /// \brief Build a new C++ __uuidof(type) expression.
2248 ///
2249 /// By default, performs semantic analysis to build the new expression.
2250 /// Subclasses may override this routine to provide different behavior.
2251 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2252 SourceLocation TypeidLoc,
2253 TypeSourceInfo *Operand,
2254 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002255 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002256 RParenLoc);
2257 }
2258
2259 /// \brief Build a new C++ __uuidof(expr) expression.
2260 ///
2261 /// By default, performs semantic analysis to build the new expression.
2262 /// Subclasses may override this routine to provide different behavior.
2263 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2264 SourceLocation TypeidLoc,
2265 Expr *Operand,
2266 SourceLocation RParenLoc) {
2267 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2268 RParenLoc);
2269 }
2270
Douglas Gregora16548e2009-08-11 05:31:07 +00002271 /// \brief Build a new C++ "this" expression.
2272 ///
2273 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002274 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002275 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002276 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002277 QualType ThisType,
2278 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002279 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002280 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002281 }
2282
2283 /// \brief Build a new C++ throw expression.
2284 ///
2285 /// By default, performs semantic analysis to build the new expression.
2286 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002287 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2288 bool IsThrownVariableInScope) {
2289 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002290 }
2291
2292 /// \brief Build a new C++ default-argument expression.
2293 ///
2294 /// By default, builds a new default-argument expression, which does not
2295 /// require any semantic analysis. Subclasses may override this routine to
2296 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002297 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002298 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002299 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002300 }
2301
Richard Smith852c9db2013-04-20 22:23:05 +00002302 /// \brief Build a new C++11 default-initialization expression.
2303 ///
2304 /// By default, builds a new default field initialization expression, which
2305 /// does not require any semantic analysis. Subclasses may override this
2306 /// routine to provide different behavior.
2307 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2308 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002309 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002310 }
2311
Douglas Gregora16548e2009-08-11 05:31:07 +00002312 /// \brief Build a new C++ zero-initialization expression.
2313 ///
2314 /// By default, performs semantic analysis to build the new expression.
2315 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002316 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2317 SourceLocation LParenLoc,
2318 SourceLocation RParenLoc) {
2319 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002320 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002321 }
Mike Stump11289f42009-09-09 15:08:12 +00002322
Douglas Gregora16548e2009-08-11 05:31:07 +00002323 /// \brief Build a new C++ "new" expression.
2324 ///
2325 /// By default, performs semantic analysis to build the new expression.
2326 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002327 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002328 bool UseGlobal,
2329 SourceLocation PlacementLParen,
2330 MultiExprArg PlacementArgs,
2331 SourceLocation PlacementRParen,
2332 SourceRange TypeIdParens,
2333 QualType AllocatedType,
2334 TypeSourceInfo *AllocatedTypeInfo,
2335 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002336 SourceRange DirectInitRange,
2337 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002338 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002339 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002340 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002341 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002342 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002343 AllocatedType,
2344 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002345 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002346 DirectInitRange,
2347 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002348 }
Mike Stump11289f42009-09-09 15:08:12 +00002349
Douglas Gregora16548e2009-08-11 05:31:07 +00002350 /// \brief Build a new C++ "delete" expression.
2351 ///
2352 /// By default, performs semantic analysis to build the new expression.
2353 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002354 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002355 bool IsGlobalDelete,
2356 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002357 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002358 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002359 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002360 }
Mike Stump11289f42009-09-09 15:08:12 +00002361
Douglas Gregor29c42f22012-02-24 07:38:34 +00002362 /// \brief Build a new type trait expression.
2363 ///
2364 /// By default, performs semantic analysis to build the new expression.
2365 /// Subclasses may override this routine to provide different behavior.
2366 ExprResult RebuildTypeTrait(TypeTrait Trait,
2367 SourceLocation StartLoc,
2368 ArrayRef<TypeSourceInfo *> Args,
2369 SourceLocation RParenLoc) {
2370 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2371 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002372
John Wiegley6242b6a2011-04-28 00:16:57 +00002373 /// \brief Build a new array type trait expression.
2374 ///
2375 /// By default, performs semantic analysis to build the new expression.
2376 /// Subclasses may override this routine to provide different behavior.
2377 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2378 SourceLocation StartLoc,
2379 TypeSourceInfo *TSInfo,
2380 Expr *DimExpr,
2381 SourceLocation RParenLoc) {
2382 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2383 }
2384
John Wiegleyf9f65842011-04-25 06:54:41 +00002385 /// \brief Build a new expression trait expression.
2386 ///
2387 /// By default, performs semantic analysis to build the new expression.
2388 /// Subclasses may override this routine to provide different behavior.
2389 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2390 SourceLocation StartLoc,
2391 Expr *Queried,
2392 SourceLocation RParenLoc) {
2393 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2394 }
2395
Mike Stump11289f42009-09-09 15:08:12 +00002396 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002397 /// expression.
2398 ///
2399 /// By default, performs semantic analysis to build the new expression.
2400 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002401 ExprResult RebuildDependentScopeDeclRefExpr(
2402 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002403 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002404 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002405 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002406 bool IsAddressOfOperand,
2407 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002408 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002409 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002410
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002411 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002412 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2413 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002414
Reid Kleckner32506ed2014-06-12 23:03:48 +00002415 return getSema().BuildQualifiedDeclarationNameExpr(
2416 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002417 }
2418
2419 /// \brief Build a new template-id 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 RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002424 SourceLocation TemplateKWLoc,
2425 LookupResult &R,
2426 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002427 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002428 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2429 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002430 }
2431
2432 /// \brief Build a new object-construction expression.
2433 ///
2434 /// By default, performs semantic analysis to build the new expression.
2435 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002436 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002437 SourceLocation Loc,
2438 CXXConstructorDecl *Constructor,
2439 bool IsElidable,
2440 MultiExprArg Args,
2441 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002442 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002443 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002444 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002445 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002446 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002447 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002448 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002449 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002450 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002451
Douglas Gregordb121ba2009-12-14 16:27:04 +00002452 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002453 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002454 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002455 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002456 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002457 RequiresZeroInit, ConstructKind,
2458 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002459 }
2460
2461 /// \brief Build a new object-construction expression.
2462 ///
2463 /// By default, performs semantic analysis to build the new expression.
2464 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002465 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2466 SourceLocation LParenLoc,
2467 MultiExprArg Args,
2468 SourceLocation RParenLoc) {
2469 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002470 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002471 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002472 RParenLoc);
2473 }
2474
2475 /// \brief Build a new object-construction expression.
2476 ///
2477 /// By default, performs semantic analysis to build the new expression.
2478 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002479 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2480 SourceLocation LParenLoc,
2481 MultiExprArg Args,
2482 SourceLocation RParenLoc) {
2483 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002484 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002485 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002486 RParenLoc);
2487 }
Mike Stump11289f42009-09-09 15:08:12 +00002488
Douglas Gregora16548e2009-08-11 05:31:07 +00002489 /// \brief Build a new member reference expression.
2490 ///
2491 /// By default, performs semantic analysis to build the new expression.
2492 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002493 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002494 QualType BaseType,
2495 bool IsArrow,
2496 SourceLocation OperatorLoc,
2497 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002498 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002499 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002500 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002501 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002502 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002503 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002504
John McCallb268a282010-08-23 23:25:46 +00002505 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002506 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002507 SS, TemplateKWLoc,
2508 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002509 MemberNameInfo,
2510 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002511 }
2512
John McCall10eae182009-11-30 22:42:35 +00002513 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002514 ///
2515 /// By default, performs semantic analysis to build the new expression.
2516 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002517 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2518 SourceLocation OperatorLoc,
2519 bool IsArrow,
2520 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002521 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002522 NamedDecl *FirstQualifierInScope,
2523 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002524 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002525 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002526 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002527
John McCallb268a282010-08-23 23:25:46 +00002528 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002529 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002530 SS, TemplateKWLoc,
2531 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002532 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002533 }
Mike Stump11289f42009-09-09 15:08:12 +00002534
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002535 /// \brief Build a new noexcept expression.
2536 ///
2537 /// By default, performs semantic analysis to build the new expression.
2538 /// Subclasses may override this routine to provide different behavior.
2539 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2540 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2541 }
2542
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002543 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002544 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2545 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002546 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002547 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002548 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002549 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2550 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002551 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002552
2553 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2554 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002555 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002556 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002557
Patrick Beard0caa3942012-04-19 00:25:12 +00002558 /// \brief Build a new Objective-C boxed expression.
2559 ///
2560 /// By default, performs semantic analysis to build the new expression.
2561 /// Subclasses may override this routine to provide different behavior.
2562 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2563 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2564 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002565
Ted Kremeneke65b0862012-03-06 20:05:56 +00002566 /// \brief Build a new Objective-C array literal.
2567 ///
2568 /// By default, performs semantic analysis to build the new expression.
2569 /// Subclasses may override this routine to provide different behavior.
2570 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2571 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002572 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002573 MultiExprArg(Elements, NumElements));
2574 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002575
2576 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002577 Expr *Base, Expr *Key,
2578 ObjCMethodDecl *getterMethod,
2579 ObjCMethodDecl *setterMethod) {
2580 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2581 getterMethod, setterMethod);
2582 }
2583
2584 /// \brief Build a new Objective-C dictionary literal.
2585 ///
2586 /// By default, performs semantic analysis to build the new expression.
2587 /// Subclasses may override this routine to provide different behavior.
2588 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2589 ObjCDictionaryElement *Elements,
2590 unsigned NumElements) {
2591 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2592 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002593
James Dennett2a4d13c2012-06-15 07:13:21 +00002594 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002595 ///
2596 /// By default, performs semantic analysis to build the new expression.
2597 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002598 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002599 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002600 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002601 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002602 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002603
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002604 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002605 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002606 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002607 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002608 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002609 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002610 MultiExprArg Args,
2611 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002612 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2613 ReceiverTypeInfo->getType(),
2614 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002615 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002616 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002617 }
2618
2619 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002620 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002621 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002622 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002623 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002624 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002625 MultiExprArg Args,
2626 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002627 return SemaRef.BuildInstanceMessage(Receiver,
2628 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002629 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002630 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002631 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002632 }
2633
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002634 /// \brief Build a new Objective-C instance/class message to 'super'.
2635 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2636 Selector Sel,
2637 ArrayRef<SourceLocation> SelectorLocs,
2638 ObjCMethodDecl *Method,
2639 SourceLocation LBracLoc,
2640 MultiExprArg Args,
2641 SourceLocation RBracLoc) {
2642 ObjCInterfaceDecl *Class = Method->getClassInterface();
2643 QualType ReceiverTy = SemaRef.Context.getObjCInterfaceType(Class);
2644
2645 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
2646 ReceiverTy,
2647 SuperLoc,
2648 Sel, Method, LBracLoc, SelectorLocs,
2649 RBracLoc, Args)
2650 : SemaRef.BuildClassMessage(nullptr,
2651 ReceiverTy,
2652 SuperLoc,
2653 Sel, Method, LBracLoc, SelectorLocs,
2654 RBracLoc, Args);
2655
2656
2657 }
2658
Douglas Gregord51d90d2010-04-26 20:11:03 +00002659 /// \brief Build a new Objective-C ivar reference expression.
2660 ///
2661 /// By default, performs semantic analysis to build the new expression.
2662 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002663 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002664 SourceLocation IvarLoc,
2665 bool IsArrow, bool IsFreeIvar) {
2666 // FIXME: We lose track of the IsFreeIvar bit.
2667 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002668 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2669 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002670 /*FIXME:*/IvarLoc, IsArrow,
2671 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002672 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002673 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002674 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002675 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002676
2677 /// \brief Build a new Objective-C property reference expression.
2678 ///
2679 /// By default, performs semantic analysis to build the new expression.
2680 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002681 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002682 ObjCPropertyDecl *Property,
2683 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002684 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002685 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2686 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2687 /*FIXME:*/PropertyLoc,
2688 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002689 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002690 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002691 NameInfo,
2692 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002693 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002694
John McCallb7bd14f2010-12-02 01:19:52 +00002695 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002696 ///
2697 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002698 /// Subclasses may override this routine to provide different behavior.
2699 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2700 ObjCMethodDecl *Getter,
2701 ObjCMethodDecl *Setter,
2702 SourceLocation PropertyLoc) {
2703 // Since these expressions can only be value-dependent, we do not
2704 // need to perform semantic analysis again.
2705 return Owned(
2706 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2707 VK_LValue, OK_ObjCProperty,
2708 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002709 }
2710
Douglas Gregord51d90d2010-04-26 20:11:03 +00002711 /// \brief Build a new Objective-C "isa" expression.
2712 ///
2713 /// By default, performs semantic analysis to build the new expression.
2714 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002715 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002716 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002717 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002718 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2719 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002720 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002721 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002722 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002723 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002724 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002725 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002726
Douglas Gregora16548e2009-08-11 05:31:07 +00002727 /// \brief Build a new shuffle vector expression.
2728 ///
2729 /// By default, performs semantic analysis to build the new expression.
2730 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002731 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002732 MultiExprArg SubExprs,
2733 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002734 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002735 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002736 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2737 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2738 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002739 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002740
Douglas Gregora16548e2009-08-11 05:31:07 +00002741 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002742 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002743 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2744 SemaRef.Context.BuiltinFnTy,
2745 VK_RValue, BuiltinLoc);
2746 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2747 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002748 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002749
2750 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002751 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002752 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002753 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002754
Douglas Gregora16548e2009-08-11 05:31:07 +00002755 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002756 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002757 }
John McCall31f82722010-11-12 08:19:04 +00002758
Hal Finkelc4d7c822013-09-18 03:29:45 +00002759 /// \brief Build a new convert vector expression.
2760 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2761 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2762 SourceLocation RParenLoc) {
2763 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2764 BuiltinLoc, RParenLoc);
2765 }
2766
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002767 /// \brief Build a new template argument pack expansion.
2768 ///
2769 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002770 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002771 /// different behavior.
2772 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002773 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002774 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002775 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002776 case TemplateArgument::Expression: {
2777 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002778 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2779 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002780 if (Result.isInvalid())
2781 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002782
Douglas Gregor98318c22011-01-03 21:37:45 +00002783 return TemplateArgumentLoc(Result.get(), Result.get());
2784 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002785
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002786 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002787 return TemplateArgumentLoc(TemplateArgument(
2788 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002789 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002790 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002791 Pattern.getTemplateNameLoc(),
2792 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002793
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002794 case TemplateArgument::Null:
2795 case TemplateArgument::Integral:
2796 case TemplateArgument::Declaration:
2797 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002798 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002799 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002800 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002801
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002802 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002803 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002804 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002805 EllipsisLoc,
2806 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002807 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2808 Expansion);
2809 break;
2810 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002811
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002812 return TemplateArgumentLoc();
2813 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002814
Douglas Gregor968f23a2011-01-03 19:31:53 +00002815 /// \brief Build a new expression pack expansion.
2816 ///
2817 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002818 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002819 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002820 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002821 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002822 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002823 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002824
Richard Smith0f0af192014-11-08 05:07:16 +00002825 /// \brief Build a new C++1z fold-expression.
2826 ///
2827 /// By default, performs semantic analysis in order to build a new fold
2828 /// expression.
2829 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
2830 BinaryOperatorKind Operator,
2831 SourceLocation EllipsisLoc, Expr *RHS,
2832 SourceLocation RParenLoc) {
2833 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
2834 RHS, RParenLoc);
2835 }
2836
2837 /// \brief Build an empty C++1z fold-expression with the given operator.
2838 ///
2839 /// By default, produces the fallback value for the fold-expression, or
2840 /// produce an error if there is no fallback value.
2841 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
2842 BinaryOperatorKind Operator) {
2843 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
2844 }
2845
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002846 /// \brief Build a new atomic operation expression.
2847 ///
2848 /// By default, performs semantic analysis to build the new expression.
2849 /// Subclasses may override this routine to provide different behavior.
2850 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2851 MultiExprArg SubExprs,
2852 QualType RetTy,
2853 AtomicExpr::AtomicOp Op,
2854 SourceLocation RParenLoc) {
2855 // Just create the expression; there is not any interesting semantic
2856 // analysis here because we can't actually build an AtomicExpr until
2857 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002858 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002859 RParenLoc);
2860 }
2861
John McCall31f82722010-11-12 08:19:04 +00002862private:
Douglas Gregor14454802011-02-25 02:25:35 +00002863 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2864 QualType ObjectType,
2865 NamedDecl *FirstQualifierInScope,
2866 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002867
2868 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2869 QualType ObjectType,
2870 NamedDecl *FirstQualifierInScope,
2871 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002872
2873 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2874 NamedDecl *FirstQualifierInScope,
2875 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002876};
Douglas Gregora16548e2009-08-11 05:31:07 +00002877
Douglas Gregorebe10102009-08-20 07:17:43 +00002878template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002879StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002880 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002881 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002882
Douglas Gregorebe10102009-08-20 07:17:43 +00002883 switch (S->getStmtClass()) {
2884 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002885
Douglas Gregorebe10102009-08-20 07:17:43 +00002886 // Transform individual statement nodes
2887#define STMT(Node, Parent) \
2888 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002889#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002890#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002891#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002892
Douglas Gregorebe10102009-08-20 07:17:43 +00002893 // Transform expressions by calling TransformExpr.
2894#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002895#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002896#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002897#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002898 {
John McCalldadc5752010-08-24 06:29:42 +00002899 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002900 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002901 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002902
Richard Smith945f8d32013-01-14 22:39:08 +00002903 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002904 }
Mike Stump11289f42009-09-09 15:08:12 +00002905 }
2906
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002907 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002908}
Mike Stump11289f42009-09-09 15:08:12 +00002909
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002910template<typename Derived>
2911OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2912 if (!S)
2913 return S;
2914
2915 switch (S->getClauseKind()) {
2916 default: break;
2917 // Transform individual clause nodes
2918#define OPENMP_CLAUSE(Name, Class) \
2919 case OMPC_ ## Name : \
2920 return getDerived().Transform ## Class(cast<Class>(S));
2921#include "clang/Basic/OpenMPKinds.def"
2922 }
2923
2924 return S;
2925}
2926
Mike Stump11289f42009-09-09 15:08:12 +00002927
Douglas Gregore922c772009-08-04 22:27:00 +00002928template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002929ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002930 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002931 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002932
2933 switch (E->getStmtClass()) {
2934 case Stmt::NoStmtClass: break;
2935#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002936#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002937#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002938 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002939#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002940 }
2941
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002942 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002943}
2944
2945template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002946ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00002947 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00002948 // Initializers are instantiated like expressions, except that various outer
2949 // layers are stripped.
2950 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002951 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002952
2953 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2954 Init = ExprTemp->getSubExpr();
2955
Richard Smithe6ca4752013-05-30 22:40:16 +00002956 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2957 Init = MTE->GetTemporaryExpr();
2958
Richard Smithd59b8322012-12-19 01:39:02 +00002959 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2960 Init = Binder->getSubExpr();
2961
2962 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2963 Init = ICE->getSubExprAsWritten();
2964
Richard Smithcc1b96d2013-06-12 22:31:48 +00002965 if (CXXStdInitializerListExpr *ILE =
2966 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00002967 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00002968
Richard Smithc6abd962014-07-25 01:12:44 +00002969 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00002970 // InitListExprs. Other forms of copy-initialization will be a no-op if
2971 // the initializer is already the right type.
2972 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00002973 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00002974 return getDerived().TransformExpr(Init);
2975
2976 // Revert value-initialization back to empty parens.
2977 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2978 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002979 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002980 Parens.getEnd());
2981 }
2982
2983 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2984 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002985 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002986 SourceLocation());
2987
2988 // Revert initialization by constructor back to a parenthesized or braced list
2989 // of expressions. Any other form of initializer can just be reused directly.
2990 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002991 return getDerived().TransformExpr(Init);
2992
Richard Smithf8adcdc2014-07-17 05:12:35 +00002993 // If the initialization implicitly converted an initializer list to a
2994 // std::initializer_list object, unwrap the std::initializer_list too.
2995 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00002996 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00002997
Richard Smithd59b8322012-12-19 01:39:02 +00002998 SmallVector<Expr*, 8> NewArgs;
2999 bool ArgChanged = false;
3000 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003001 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003002 return ExprError();
3003
3004 // If this was list initialization, revert to list form.
3005 if (Construct->isListInitialization())
3006 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3007 Construct->getLocEnd(),
3008 Construct->getType());
3009
Richard Smithd59b8322012-12-19 01:39:02 +00003010 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003011 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003012 if (Parens.isInvalid()) {
3013 // This was a variable declaration's initialization for which no initializer
3014 // was specified.
3015 assert(NewArgs.empty() &&
3016 "no parens or braces but have direct init with arguments?");
3017 return ExprEmpty();
3018 }
Richard Smithd59b8322012-12-19 01:39:02 +00003019 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3020 Parens.getEnd());
3021}
3022
3023template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00003024bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
3025 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003026 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003027 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003028 bool *ArgChanged) {
3029 for (unsigned I = 0; I != NumInputs; ++I) {
3030 // If requested, drop call arguments that need to be dropped.
3031 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3032 if (ArgChanged)
3033 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003034
Douglas Gregora3efea12011-01-03 19:04:46 +00003035 break;
3036 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003037
Douglas Gregor968f23a2011-01-03 19:31:53 +00003038 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3039 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003040
Chris Lattner01cf8db2011-07-20 06:58:45 +00003041 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003042 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3043 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003044
Douglas Gregor968f23a2011-01-03 19:31:53 +00003045 // Determine whether the set of unexpanded parameter packs can and should
3046 // be expanded.
3047 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003048 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003049 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3050 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003051 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3052 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003053 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003054 Expand, RetainExpansion,
3055 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003056 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003057
Douglas Gregor968f23a2011-01-03 19:31:53 +00003058 if (!Expand) {
3059 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003060 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003061 // expansion.
3062 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3063 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3064 if (OutPattern.isInvalid())
3065 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003066
3067 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003068 Expansion->getEllipsisLoc(),
3069 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003070 if (Out.isInvalid())
3071 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003072
Douglas Gregor968f23a2011-01-03 19:31:53 +00003073 if (ArgChanged)
3074 *ArgChanged = true;
3075 Outputs.push_back(Out.get());
3076 continue;
3077 }
John McCall542e7c62011-07-06 07:30:07 +00003078
3079 // Record right away that the argument was changed. This needs
3080 // to happen even if the array expands to nothing.
3081 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003082
Douglas Gregor968f23a2011-01-03 19:31:53 +00003083 // The transform has determined that we should perform an elementwise
3084 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003085 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003086 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3087 ExprResult Out = getDerived().TransformExpr(Pattern);
3088 if (Out.isInvalid())
3089 return true;
3090
Richard Smith9467be42014-06-06 17:33:35 +00003091 // FIXME: Can this happen? We should not try to expand the pack
3092 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003093 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003094 Out = getDerived().RebuildPackExpansion(
3095 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003096 if (Out.isInvalid())
3097 return true;
3098 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003099
Douglas Gregor968f23a2011-01-03 19:31:53 +00003100 Outputs.push_back(Out.get());
3101 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003102
Richard Smith9467be42014-06-06 17:33:35 +00003103 // If we're supposed to retain a pack expansion, do so by temporarily
3104 // forgetting the partially-substituted parameter pack.
3105 if (RetainExpansion) {
3106 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3107
3108 ExprResult Out = getDerived().TransformExpr(Pattern);
3109 if (Out.isInvalid())
3110 return true;
3111
3112 Out = getDerived().RebuildPackExpansion(
3113 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3114 if (Out.isInvalid())
3115 return true;
3116
3117 Outputs.push_back(Out.get());
3118 }
3119
Douglas Gregor968f23a2011-01-03 19:31:53 +00003120 continue;
3121 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003122
Richard Smithd59b8322012-12-19 01:39:02 +00003123 ExprResult Result =
3124 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3125 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003126 if (Result.isInvalid())
3127 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003128
Douglas Gregora3efea12011-01-03 19:04:46 +00003129 if (Result.get() != Inputs[I] && ArgChanged)
3130 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003131
3132 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003133 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003134
Douglas Gregora3efea12011-01-03 19:04:46 +00003135 return false;
3136}
3137
3138template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003139NestedNameSpecifierLoc
3140TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3141 NestedNameSpecifierLoc NNS,
3142 QualType ObjectType,
3143 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003144 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003145 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003146 Qualifier = Qualifier.getPrefix())
3147 Qualifiers.push_back(Qualifier);
3148
3149 CXXScopeSpec SS;
3150 while (!Qualifiers.empty()) {
3151 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3152 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003153
Douglas Gregor14454802011-02-25 02:25:35 +00003154 switch (QNNS->getKind()) {
3155 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003156 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003157 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003158 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003159 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003160 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003161 FirstQualifierInScope, false))
3162 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003163
Douglas Gregor14454802011-02-25 02:25:35 +00003164 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003165
Douglas Gregor14454802011-02-25 02:25:35 +00003166 case NestedNameSpecifier::Namespace: {
3167 NamespaceDecl *NS
3168 = cast_or_null<NamespaceDecl>(
3169 getDerived().TransformDecl(
3170 Q.getLocalBeginLoc(),
3171 QNNS->getAsNamespace()));
3172 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3173 break;
3174 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003175
Douglas Gregor14454802011-02-25 02:25:35 +00003176 case NestedNameSpecifier::NamespaceAlias: {
3177 NamespaceAliasDecl *Alias
3178 = cast_or_null<NamespaceAliasDecl>(
3179 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3180 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003181 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003182 Q.getLocalEndLoc());
3183 break;
3184 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003185
Douglas Gregor14454802011-02-25 02:25:35 +00003186 case NestedNameSpecifier::Global:
3187 // There is no meaningful transformation that one could perform on the
3188 // global scope.
3189 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3190 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003191
Nikola Smiljanic67860242014-09-26 00:28:20 +00003192 case NestedNameSpecifier::Super: {
3193 CXXRecordDecl *RD =
3194 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3195 SourceLocation(), QNNS->getAsRecordDecl()));
3196 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3197 break;
3198 }
3199
Douglas Gregor14454802011-02-25 02:25:35 +00003200 case NestedNameSpecifier::TypeSpecWithTemplate:
3201 case NestedNameSpecifier::TypeSpec: {
3202 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3203 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003204
Douglas Gregor14454802011-02-25 02:25:35 +00003205 if (!TL)
3206 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003207
Douglas Gregor14454802011-02-25 02:25:35 +00003208 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003209 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003210 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003211 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003212 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003213 if (TL.getType()->isEnumeralType())
3214 SemaRef.Diag(TL.getBeginLoc(),
3215 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003216 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3217 Q.getLocalEndLoc());
3218 break;
3219 }
Richard Trieude756fb2011-05-07 01:36:37 +00003220 // If the nested-name-specifier is an invalid type def, don't emit an
3221 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003222 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3223 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003224 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003225 << TL.getType() << SS.getRange();
3226 }
Douglas Gregor14454802011-02-25 02:25:35 +00003227 return NestedNameSpecifierLoc();
3228 }
Douglas Gregore16af532011-02-28 18:50:33 +00003229 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003230
Douglas Gregore16af532011-02-28 18:50:33 +00003231 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003232 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003233 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003234 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003235
Douglas Gregor14454802011-02-25 02:25:35 +00003236 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003237 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003238 !getDerived().AlwaysRebuild())
3239 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003240
3241 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003242 // nested-name-specifier, do so.
3243 if (SS.location_size() == NNS.getDataLength() &&
3244 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3245 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3246
3247 // Allocate new nested-name-specifier location information.
3248 return SS.getWithLocInContext(SemaRef.Context);
3249}
3250
3251template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003252DeclarationNameInfo
3253TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003254::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003255 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003256 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003257 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003258
3259 switch (Name.getNameKind()) {
3260 case DeclarationName::Identifier:
3261 case DeclarationName::ObjCZeroArgSelector:
3262 case DeclarationName::ObjCOneArgSelector:
3263 case DeclarationName::ObjCMultiArgSelector:
3264 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003265 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003266 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003267 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003268
Douglas Gregorf816bd72009-09-03 22:13:48 +00003269 case DeclarationName::CXXConstructorName:
3270 case DeclarationName::CXXDestructorName:
3271 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003272 TypeSourceInfo *NewTInfo;
3273 CanQualType NewCanTy;
3274 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003275 NewTInfo = getDerived().TransformType(OldTInfo);
3276 if (!NewTInfo)
3277 return DeclarationNameInfo();
3278 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003279 }
3280 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003281 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003282 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003283 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003284 if (NewT.isNull())
3285 return DeclarationNameInfo();
3286 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3287 }
Mike Stump11289f42009-09-09 15:08:12 +00003288
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003289 DeclarationName NewName
3290 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3291 NewCanTy);
3292 DeclarationNameInfo NewNameInfo(NameInfo);
3293 NewNameInfo.setName(NewName);
3294 NewNameInfo.setNamedTypeInfo(NewTInfo);
3295 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003296 }
Mike Stump11289f42009-09-09 15:08:12 +00003297 }
3298
David Blaikie83d382b2011-09-23 05:06:16 +00003299 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003300}
3301
3302template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003303TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003304TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3305 TemplateName Name,
3306 SourceLocation NameLoc,
3307 QualType ObjectType,
3308 NamedDecl *FirstQualifierInScope) {
3309 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3310 TemplateDecl *Template = QTN->getTemplateDecl();
3311 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003312
Douglas Gregor9db53502011-03-02 18:07:45 +00003313 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003314 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003315 Template));
3316 if (!TransTemplate)
3317 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003318
Douglas Gregor9db53502011-03-02 18:07:45 +00003319 if (!getDerived().AlwaysRebuild() &&
3320 SS.getScopeRep() == QTN->getQualifier() &&
3321 TransTemplate == Template)
3322 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003323
Douglas Gregor9db53502011-03-02 18:07:45 +00003324 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3325 TransTemplate);
3326 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003327
Douglas Gregor9db53502011-03-02 18:07:45 +00003328 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3329 if (SS.getScopeRep()) {
3330 // These apply to the scope specifier, not the template.
3331 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003332 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003333 }
3334
Douglas Gregor9db53502011-03-02 18:07:45 +00003335 if (!getDerived().AlwaysRebuild() &&
3336 SS.getScopeRep() == DTN->getQualifier() &&
3337 ObjectType.isNull())
3338 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003339
Douglas Gregor9db53502011-03-02 18:07:45 +00003340 if (DTN->isIdentifier()) {
3341 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003342 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003343 NameLoc,
3344 ObjectType,
3345 FirstQualifierInScope);
3346 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003347
Douglas Gregor9db53502011-03-02 18:07:45 +00003348 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3349 ObjectType);
3350 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003351
Douglas Gregor9db53502011-03-02 18:07:45 +00003352 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3353 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003354 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003355 Template));
3356 if (!TransTemplate)
3357 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003358
Douglas Gregor9db53502011-03-02 18:07:45 +00003359 if (!getDerived().AlwaysRebuild() &&
3360 TransTemplate == Template)
3361 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003362
Douglas Gregor9db53502011-03-02 18:07:45 +00003363 return TemplateName(TransTemplate);
3364 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003365
Douglas Gregor9db53502011-03-02 18:07:45 +00003366 if (SubstTemplateTemplateParmPackStorage *SubstPack
3367 = Name.getAsSubstTemplateTemplateParmPack()) {
3368 TemplateTemplateParmDecl *TransParam
3369 = cast_or_null<TemplateTemplateParmDecl>(
3370 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3371 if (!TransParam)
3372 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003373
Douglas Gregor9db53502011-03-02 18:07:45 +00003374 if (!getDerived().AlwaysRebuild() &&
3375 TransParam == SubstPack->getParameterPack())
3376 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003377
3378 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003379 SubstPack->getArgumentPack());
3380 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003381
Douglas Gregor9db53502011-03-02 18:07:45 +00003382 // These should be getting filtered out before they reach the AST.
3383 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003384}
3385
3386template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003387void TreeTransform<Derived>::InventTemplateArgumentLoc(
3388 const TemplateArgument &Arg,
3389 TemplateArgumentLoc &Output) {
3390 SourceLocation Loc = getDerived().getBaseLocation();
3391 switch (Arg.getKind()) {
3392 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003393 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003394 break;
3395
3396 case TemplateArgument::Type:
3397 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003398 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003399
John McCall0ad16662009-10-29 08:12:44 +00003400 break;
3401
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003402 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003403 case TemplateArgument::TemplateExpansion: {
3404 NestedNameSpecifierLocBuilder Builder;
3405 TemplateName Template = Arg.getAsTemplate();
3406 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3407 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3408 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3409 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003410
Douglas Gregor9d802122011-03-02 17:09:35 +00003411 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003412 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003413 Builder.getWithLocInContext(SemaRef.Context),
3414 Loc);
3415 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003416 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003417 Builder.getWithLocInContext(SemaRef.Context),
3418 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003419
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003420 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003421 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003422
John McCall0ad16662009-10-29 08:12:44 +00003423 case TemplateArgument::Expression:
3424 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3425 break;
3426
3427 case TemplateArgument::Declaration:
3428 case TemplateArgument::Integral:
3429 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003430 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003431 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003432 break;
3433 }
3434}
3435
3436template<typename Derived>
3437bool TreeTransform<Derived>::TransformTemplateArgument(
3438 const TemplateArgumentLoc &Input,
3439 TemplateArgumentLoc &Output) {
3440 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003441 switch (Arg.getKind()) {
3442 case TemplateArgument::Null:
3443 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003444 case TemplateArgument::Pack:
3445 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003446 case TemplateArgument::NullPtr:
3447 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003448
Douglas Gregore922c772009-08-04 22:27:00 +00003449 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003450 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003451 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003452 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003453
3454 DI = getDerived().TransformType(DI);
3455 if (!DI) return true;
3456
3457 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3458 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003459 }
Mike Stump11289f42009-09-09 15:08:12 +00003460
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003461 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003462 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3463 if (QualifierLoc) {
3464 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3465 if (!QualifierLoc)
3466 return true;
3467 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003468
Douglas Gregordf846d12011-03-02 18:46:51 +00003469 CXXScopeSpec SS;
3470 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003471 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003472 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3473 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003474 if (Template.isNull())
3475 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003476
Douglas Gregor9d802122011-03-02 17:09:35 +00003477 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003478 Input.getTemplateNameLoc());
3479 return false;
3480 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003481
3482 case TemplateArgument::TemplateExpansion:
3483 llvm_unreachable("Caller should expand pack expansions");
3484
Douglas Gregore922c772009-08-04 22:27:00 +00003485 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003486 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003487 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003488 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003489
John McCall0ad16662009-10-29 08:12:44 +00003490 Expr *InputExpr = Input.getSourceExpression();
3491 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3492
Chris Lattnercdb591a2011-04-25 20:37:58 +00003493 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003494 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003495 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003496 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003497 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003498 }
Douglas Gregore922c772009-08-04 22:27:00 +00003499 }
Mike Stump11289f42009-09-09 15:08:12 +00003500
Douglas Gregore922c772009-08-04 22:27:00 +00003501 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003502 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003503}
3504
Douglas Gregorfe921a72010-12-20 23:36:19 +00003505/// \brief Iterator adaptor that invents template argument location information
3506/// for each of the template arguments in its underlying iterator.
3507template<typename Derived, typename InputIterator>
3508class TemplateArgumentLocInventIterator {
3509 TreeTransform<Derived> &Self;
3510 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003511
Douglas Gregorfe921a72010-12-20 23:36:19 +00003512public:
3513 typedef TemplateArgumentLoc value_type;
3514 typedef TemplateArgumentLoc reference;
3515 typedef typename std::iterator_traits<InputIterator>::difference_type
3516 difference_type;
3517 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003518
Douglas Gregorfe921a72010-12-20 23:36:19 +00003519 class pointer {
3520 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003521
Douglas Gregorfe921a72010-12-20 23:36:19 +00003522 public:
3523 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003524
Douglas Gregorfe921a72010-12-20 23:36:19 +00003525 const TemplateArgumentLoc *operator->() const { return &Arg; }
3526 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003527
Douglas Gregorfe921a72010-12-20 23:36:19 +00003528 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003529
Douglas Gregorfe921a72010-12-20 23:36:19 +00003530 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3531 InputIterator Iter)
3532 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003533
Douglas Gregorfe921a72010-12-20 23:36:19 +00003534 TemplateArgumentLocInventIterator &operator++() {
3535 ++Iter;
3536 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003537 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003538
Douglas Gregorfe921a72010-12-20 23:36:19 +00003539 TemplateArgumentLocInventIterator operator++(int) {
3540 TemplateArgumentLocInventIterator Old(*this);
3541 ++(*this);
3542 return Old;
3543 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003544
Douglas Gregorfe921a72010-12-20 23:36:19 +00003545 reference operator*() const {
3546 TemplateArgumentLoc Result;
3547 Self.InventTemplateArgumentLoc(*Iter, Result);
3548 return Result;
3549 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003550
Douglas Gregorfe921a72010-12-20 23:36:19 +00003551 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003552
Douglas Gregorfe921a72010-12-20 23:36:19 +00003553 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3554 const TemplateArgumentLocInventIterator &Y) {
3555 return X.Iter == Y.Iter;
3556 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003557
Douglas Gregorfe921a72010-12-20 23:36:19 +00003558 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3559 const TemplateArgumentLocInventIterator &Y) {
3560 return X.Iter != Y.Iter;
3561 }
3562};
Chad Rosier1dcde962012-08-08 18:46:20 +00003563
Douglas Gregor42cafa82010-12-20 17:42:22 +00003564template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003565template<typename InputIterator>
3566bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3567 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003568 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003569 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003570 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003571 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003572
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003573 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3574 // Unpack argument packs, which we translate them into separate
3575 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003576 // FIXME: We could do much better if we could guarantee that the
3577 // TemplateArgumentLocInfo for the pack expansion would be usable for
3578 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003579 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003580 TemplateArgument::pack_iterator>
3581 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003582 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003583 In.getArgument().pack_begin()),
3584 PackLocIterator(*this,
3585 In.getArgument().pack_end()),
3586 Outputs))
3587 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003588
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003589 continue;
3590 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003591
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003592 if (In.getArgument().isPackExpansion()) {
3593 // We have a pack expansion, for which we will be substituting into
3594 // the pattern.
3595 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003596 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003597 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003598 = getSema().getTemplateArgumentPackExpansionPattern(
3599 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003600
Chris Lattner01cf8db2011-07-20 06:58:45 +00003601 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003602 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3603 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003604
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003605 // Determine whether the set of unexpanded parameter packs can and should
3606 // be expanded.
3607 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003608 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003609 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003610 if (getDerived().TryExpandParameterPacks(Ellipsis,
3611 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003612 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003613 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003614 RetainExpansion,
3615 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003616 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003617
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003618 if (!Expand) {
3619 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003620 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003621 // expansion.
3622 TemplateArgumentLoc OutPattern;
3623 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3624 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3625 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003626
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003627 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3628 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003629 if (Out.getArgument().isNull())
3630 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003631
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003632 Outputs.addArgument(Out);
3633 continue;
3634 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003635
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003636 // The transform has determined that we should perform an elementwise
3637 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003638 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003639 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3640
3641 if (getDerived().TransformTemplateArgument(Pattern, Out))
3642 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003643
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003644 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003645 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3646 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003647 if (Out.getArgument().isNull())
3648 return true;
3649 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003650
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003651 Outputs.addArgument(Out);
3652 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003653
Douglas Gregor48d24112011-01-10 20:53:55 +00003654 // If we're supposed to retain a pack expansion, do so by temporarily
3655 // forgetting the partially-substituted parameter pack.
3656 if (RetainExpansion) {
3657 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003658
Douglas Gregor48d24112011-01-10 20:53:55 +00003659 if (getDerived().TransformTemplateArgument(Pattern, Out))
3660 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003661
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003662 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3663 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003664 if (Out.getArgument().isNull())
3665 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003666
Douglas Gregor48d24112011-01-10 20:53:55 +00003667 Outputs.addArgument(Out);
3668 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003669
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003670 continue;
3671 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003672
3673 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003674 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003675 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003676
Douglas Gregor42cafa82010-12-20 17:42:22 +00003677 Outputs.addArgument(Out);
3678 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003679
Douglas Gregor42cafa82010-12-20 17:42:22 +00003680 return false;
3681
3682}
3683
Douglas Gregord6ff3322009-08-04 16:50:30 +00003684//===----------------------------------------------------------------------===//
3685// Type transformation
3686//===----------------------------------------------------------------------===//
3687
3688template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003689QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003690 if (getDerived().AlreadyTransformed(T))
3691 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003692
John McCall550e0c22009-10-21 00:40:46 +00003693 // Temporary workaround. All of these transformations should
3694 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003695 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3696 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003697
John McCall31f82722010-11-12 08:19:04 +00003698 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003699
John McCall550e0c22009-10-21 00:40:46 +00003700 if (!NewDI)
3701 return QualType();
3702
3703 return NewDI->getType();
3704}
3705
3706template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003707TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003708 // Refine the base location to the type's location.
3709 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3710 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003711 if (getDerived().AlreadyTransformed(DI->getType()))
3712 return DI;
3713
3714 TypeLocBuilder TLB;
3715
3716 TypeLoc TL = DI->getTypeLoc();
3717 TLB.reserve(TL.getFullDataSize());
3718
John McCall31f82722010-11-12 08:19:04 +00003719 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003720 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003721 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003722
John McCallbcd03502009-12-07 02:54:59 +00003723 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003724}
3725
3726template<typename Derived>
3727QualType
John McCall31f82722010-11-12 08:19:04 +00003728TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003729 switch (T.getTypeLocClass()) {
3730#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003731#define TYPELOC(CLASS, PARENT) \
3732 case TypeLoc::CLASS: \
3733 return getDerived().Transform##CLASS##Type(TLB, \
3734 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003735#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003736 }
Mike Stump11289f42009-09-09 15:08:12 +00003737
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003738 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003739}
3740
3741/// FIXME: By default, this routine adds type qualifiers only to types
3742/// that can have qualifiers, and silently suppresses those qualifiers
3743/// that are not permitted (e.g., qualifiers on reference or function
3744/// types). This is the right thing for template instantiation, but
3745/// probably not for other clients.
3746template<typename Derived>
3747QualType
3748TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003749 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003750 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003751
John McCall31f82722010-11-12 08:19:04 +00003752 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003753 if (Result.isNull())
3754 return QualType();
3755
3756 // Silently suppress qualifiers if the result type can't be qualified.
3757 // FIXME: this is the right thing for template instantiation, but
3758 // probably not for other clients.
3759 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003760 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003761
John McCall31168b02011-06-15 23:02:42 +00003762 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003763 // resulting type.
3764 if (Quals.hasObjCLifetime()) {
3765 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3766 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003767 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003768 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003769 // A lifetime qualifier applied to a substituted template parameter
3770 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003771 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003772 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003773 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3774 QualType Replacement = SubstTypeParam->getReplacementType();
3775 Qualifiers Qs = Replacement.getQualifiers();
3776 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003777 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003778 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3779 Qs);
3780 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003781 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003782 Replacement);
3783 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003784 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3785 // 'auto' types behave the same way as template parameters.
3786 QualType Deduced = AutoTy->getDeducedType();
3787 Qualifiers Qs = Deduced.getQualifiers();
3788 Qs.removeObjCLifetime();
3789 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3790 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003791 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3792 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003793 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003794 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003795 // Otherwise, complain about the addition of a qualifier to an
3796 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003797 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003798 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003799 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003800
Douglas Gregore46db902011-06-17 22:11:49 +00003801 Quals.removeObjCLifetime();
3802 }
3803 }
3804 }
John McCallcb0f89a2010-06-05 06:41:15 +00003805 if (!Quals.empty()) {
3806 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003807 // BuildQualifiedType might not add qualifiers if they are invalid.
3808 if (Result.hasLocalQualifiers())
3809 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003810 // No location information to preserve.
3811 }
John McCall550e0c22009-10-21 00:40:46 +00003812
3813 return Result;
3814}
3815
Douglas Gregor14454802011-02-25 02:25:35 +00003816template<typename Derived>
3817TypeLoc
3818TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3819 QualType ObjectType,
3820 NamedDecl *UnqualLookup,
3821 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003822 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003823 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003824
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003825 TypeSourceInfo *TSI =
3826 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3827 if (TSI)
3828 return TSI->getTypeLoc();
3829 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003830}
3831
Douglas Gregor579c15f2011-03-02 18:32:08 +00003832template<typename Derived>
3833TypeSourceInfo *
3834TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3835 QualType ObjectType,
3836 NamedDecl *UnqualLookup,
3837 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003838 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003839 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003840
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003841 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3842 UnqualLookup, SS);
3843}
3844
3845template <typename Derived>
3846TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3847 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3848 CXXScopeSpec &SS) {
3849 QualType T = TL.getType();
3850 assert(!getDerived().AlreadyTransformed(T));
3851
Douglas Gregor579c15f2011-03-02 18:32:08 +00003852 TypeLocBuilder TLB;
3853 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003854
Douglas Gregor579c15f2011-03-02 18:32:08 +00003855 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003856 TemplateSpecializationTypeLoc SpecTL =
3857 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003858
Douglas Gregor579c15f2011-03-02 18:32:08 +00003859 TemplateName Template
3860 = getDerived().TransformTemplateName(SS,
3861 SpecTL.getTypePtr()->getTemplateName(),
3862 SpecTL.getTemplateNameLoc(),
3863 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003864 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003865 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003866
3867 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003868 Template);
3869 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003870 DependentTemplateSpecializationTypeLoc SpecTL =
3871 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003872
Douglas Gregor579c15f2011-03-02 18:32:08 +00003873 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003874 = getDerived().RebuildTemplateName(SS,
3875 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003876 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003877 ObjectType, UnqualLookup);
3878 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003879 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003880
3881 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003882 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003883 Template,
3884 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003885 } else {
3886 // Nothing special needs to be done for these.
3887 Result = getDerived().TransformType(TLB, TL);
3888 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003889
3890 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003891 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003892
Douglas Gregor579c15f2011-03-02 18:32:08 +00003893 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3894}
3895
John McCall550e0c22009-10-21 00:40:46 +00003896template <class TyLoc> static inline
3897QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3898 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3899 NewT.setNameLoc(T.getNameLoc());
3900 return T.getType();
3901}
3902
John McCall550e0c22009-10-21 00:40:46 +00003903template<typename Derived>
3904QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003905 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003906 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3907 NewT.setBuiltinLoc(T.getBuiltinLoc());
3908 if (T.needsExtraLocalData())
3909 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3910 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003911}
Mike Stump11289f42009-09-09 15:08:12 +00003912
Douglas Gregord6ff3322009-08-04 16:50:30 +00003913template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003914QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003915 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003916 // FIXME: recurse?
3917 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003918}
Mike Stump11289f42009-09-09 15:08:12 +00003919
Reid Kleckner0503a872013-12-05 01:23:43 +00003920template <typename Derived>
3921QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3922 AdjustedTypeLoc TL) {
3923 // Adjustments applied during transformation are handled elsewhere.
3924 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3925}
3926
Douglas Gregord6ff3322009-08-04 16:50:30 +00003927template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003928QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3929 DecayedTypeLoc TL) {
3930 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3931 if (OriginalType.isNull())
3932 return QualType();
3933
3934 QualType Result = TL.getType();
3935 if (getDerived().AlwaysRebuild() ||
3936 OriginalType != TL.getOriginalLoc().getType())
3937 Result = SemaRef.Context.getDecayedType(OriginalType);
3938 TLB.push<DecayedTypeLoc>(Result);
3939 // Nothing to set for DecayedTypeLoc.
3940 return Result;
3941}
3942
3943template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003944QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003945 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003946 QualType PointeeType
3947 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003948 if (PointeeType.isNull())
3949 return QualType();
3950
3951 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003952 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003953 // A dependent pointer type 'T *' has is being transformed such
3954 // that an Objective-C class type is being replaced for 'T'. The
3955 // resulting pointer type is an ObjCObjectPointerType, not a
3956 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003957 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003958
John McCall8b07ec22010-05-15 11:32:37 +00003959 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3960 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003961 return Result;
3962 }
John McCall31f82722010-11-12 08:19:04 +00003963
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003964 if (getDerived().AlwaysRebuild() ||
3965 PointeeType != TL.getPointeeLoc().getType()) {
3966 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3967 if (Result.isNull())
3968 return QualType();
3969 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003970
John McCall31168b02011-06-15 23:02:42 +00003971 // Objective-C ARC can add lifetime qualifiers to the type that we're
3972 // pointing to.
3973 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003974
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003975 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3976 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003977 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003978}
Mike Stump11289f42009-09-09 15:08:12 +00003979
3980template<typename Derived>
3981QualType
John McCall550e0c22009-10-21 00:40:46 +00003982TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003983 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003984 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003985 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3986 if (PointeeType.isNull())
3987 return QualType();
3988
3989 QualType Result = TL.getType();
3990 if (getDerived().AlwaysRebuild() ||
3991 PointeeType != TL.getPointeeLoc().getType()) {
3992 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003993 TL.getSigilLoc());
3994 if (Result.isNull())
3995 return QualType();
3996 }
3997
Douglas Gregor049211a2010-04-22 16:50:51 +00003998 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003999 NewT.setSigilLoc(TL.getSigilLoc());
4000 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004001}
4002
John McCall70dd5f62009-10-30 00:06:24 +00004003/// Transforms a reference type. Note that somewhat paradoxically we
4004/// don't care whether the type itself is an l-value type or an r-value
4005/// type; we only care if the type was *written* as an l-value type
4006/// or an r-value type.
4007template<typename Derived>
4008QualType
4009TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004010 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004011 const ReferenceType *T = TL.getTypePtr();
4012
4013 // Note that this works with the pointee-as-written.
4014 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4015 if (PointeeType.isNull())
4016 return QualType();
4017
4018 QualType Result = TL.getType();
4019 if (getDerived().AlwaysRebuild() ||
4020 PointeeType != T->getPointeeTypeAsWritten()) {
4021 Result = getDerived().RebuildReferenceType(PointeeType,
4022 T->isSpelledAsLValue(),
4023 TL.getSigilLoc());
4024 if (Result.isNull())
4025 return QualType();
4026 }
4027
John McCall31168b02011-06-15 23:02:42 +00004028 // Objective-C ARC can add lifetime qualifiers to the type that we're
4029 // referring to.
4030 TLB.TypeWasModifiedSafely(
4031 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4032
John McCall70dd5f62009-10-30 00:06:24 +00004033 // r-value references can be rebuilt as l-value references.
4034 ReferenceTypeLoc NewTL;
4035 if (isa<LValueReferenceType>(Result))
4036 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4037 else
4038 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4039 NewTL.setSigilLoc(TL.getSigilLoc());
4040
4041 return Result;
4042}
4043
Mike Stump11289f42009-09-09 15:08:12 +00004044template<typename Derived>
4045QualType
John McCall550e0c22009-10-21 00:40:46 +00004046TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004047 LValueReferenceTypeLoc TL) {
4048 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004049}
4050
Mike Stump11289f42009-09-09 15:08:12 +00004051template<typename Derived>
4052QualType
John McCall550e0c22009-10-21 00:40:46 +00004053TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004054 RValueReferenceTypeLoc TL) {
4055 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004056}
Mike Stump11289f42009-09-09 15:08:12 +00004057
Douglas Gregord6ff3322009-08-04 16:50:30 +00004058template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004059QualType
John McCall550e0c22009-10-21 00:40:46 +00004060TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004061 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004062 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004063 if (PointeeType.isNull())
4064 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004065
Abramo Bagnara509357842011-03-05 14:42:21 +00004066 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004067 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004068 if (OldClsTInfo) {
4069 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4070 if (!NewClsTInfo)
4071 return QualType();
4072 }
4073
4074 const MemberPointerType *T = TL.getTypePtr();
4075 QualType OldClsType = QualType(T->getClass(), 0);
4076 QualType NewClsType;
4077 if (NewClsTInfo)
4078 NewClsType = NewClsTInfo->getType();
4079 else {
4080 NewClsType = getDerived().TransformType(OldClsType);
4081 if (NewClsType.isNull())
4082 return QualType();
4083 }
Mike Stump11289f42009-09-09 15:08:12 +00004084
John McCall550e0c22009-10-21 00:40:46 +00004085 QualType Result = TL.getType();
4086 if (getDerived().AlwaysRebuild() ||
4087 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004088 NewClsType != OldClsType) {
4089 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004090 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004091 if (Result.isNull())
4092 return QualType();
4093 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004094
Reid Kleckner0503a872013-12-05 01:23:43 +00004095 // If we had to adjust the pointee type when building a member pointer, make
4096 // sure to push TypeLoc info for it.
4097 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4098 if (MPT && PointeeType != MPT->getPointeeType()) {
4099 assert(isa<AdjustedType>(MPT->getPointeeType()));
4100 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4101 }
4102
John McCall550e0c22009-10-21 00:40:46 +00004103 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4104 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004105 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004106
4107 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004108}
4109
Mike Stump11289f42009-09-09 15:08:12 +00004110template<typename Derived>
4111QualType
John McCall550e0c22009-10-21 00:40:46 +00004112TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004113 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004114 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004115 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004116 if (ElementType.isNull())
4117 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004118
John McCall550e0c22009-10-21 00:40:46 +00004119 QualType Result = TL.getType();
4120 if (getDerived().AlwaysRebuild() ||
4121 ElementType != T->getElementType()) {
4122 Result = getDerived().RebuildConstantArrayType(ElementType,
4123 T->getSizeModifier(),
4124 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004125 T->getIndexTypeCVRQualifiers(),
4126 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004127 if (Result.isNull())
4128 return QualType();
4129 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004130
4131 // We might have either a ConstantArrayType or a VariableArrayType now:
4132 // a ConstantArrayType is allowed to have an element type which is a
4133 // VariableArrayType if the type is dependent. Fortunately, all array
4134 // types have the same location layout.
4135 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004136 NewTL.setLBracketLoc(TL.getLBracketLoc());
4137 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004138
John McCall550e0c22009-10-21 00:40:46 +00004139 Expr *Size = TL.getSizeExpr();
4140 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004141 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4142 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004143 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4144 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004145 }
4146 NewTL.setSizeExpr(Size);
4147
4148 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004149}
Mike Stump11289f42009-09-09 15:08:12 +00004150
Douglas Gregord6ff3322009-08-04 16:50:30 +00004151template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004152QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004153 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004154 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004155 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004156 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004157 if (ElementType.isNull())
4158 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004159
John McCall550e0c22009-10-21 00:40:46 +00004160 QualType Result = TL.getType();
4161 if (getDerived().AlwaysRebuild() ||
4162 ElementType != T->getElementType()) {
4163 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004164 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004165 T->getIndexTypeCVRQualifiers(),
4166 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004167 if (Result.isNull())
4168 return QualType();
4169 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004170
John McCall550e0c22009-10-21 00:40:46 +00004171 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4172 NewTL.setLBracketLoc(TL.getLBracketLoc());
4173 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004174 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004175
4176 return Result;
4177}
4178
4179template<typename Derived>
4180QualType
4181TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004182 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004183 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004184 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4185 if (ElementType.isNull())
4186 return QualType();
4187
John McCalldadc5752010-08-24 06:29:42 +00004188 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004189 = getDerived().TransformExpr(T->getSizeExpr());
4190 if (SizeResult.isInvalid())
4191 return QualType();
4192
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004193 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004194
4195 QualType Result = TL.getType();
4196 if (getDerived().AlwaysRebuild() ||
4197 ElementType != T->getElementType() ||
4198 Size != T->getSizeExpr()) {
4199 Result = getDerived().RebuildVariableArrayType(ElementType,
4200 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004201 Size,
John McCall550e0c22009-10-21 00:40:46 +00004202 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004203 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004204 if (Result.isNull())
4205 return QualType();
4206 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004207
Serge Pavlov774c6d02014-02-06 03:49:11 +00004208 // We might have constant size array now, but fortunately it has the same
4209 // location layout.
4210 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004211 NewTL.setLBracketLoc(TL.getLBracketLoc());
4212 NewTL.setRBracketLoc(TL.getRBracketLoc());
4213 NewTL.setSizeExpr(Size);
4214
4215 return Result;
4216}
4217
4218template<typename Derived>
4219QualType
4220TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004221 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004222 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004223 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4224 if (ElementType.isNull())
4225 return QualType();
4226
Richard Smith764d2fe2011-12-20 02:08:33 +00004227 // Array bounds are constant expressions.
4228 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4229 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004230
John McCall33ddac02011-01-19 10:06:00 +00004231 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4232 Expr *origSize = TL.getSizeExpr();
4233 if (!origSize) origSize = T->getSizeExpr();
4234
4235 ExprResult sizeResult
4236 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004237 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004238 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004239 return QualType();
4240
John McCall33ddac02011-01-19 10:06:00 +00004241 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004242
4243 QualType Result = TL.getType();
4244 if (getDerived().AlwaysRebuild() ||
4245 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004246 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004247 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4248 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004249 size,
John McCall550e0c22009-10-21 00:40:46 +00004250 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004251 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004252 if (Result.isNull())
4253 return QualType();
4254 }
John McCall550e0c22009-10-21 00:40:46 +00004255
4256 // We might have any sort of array type now, but fortunately they
4257 // all have the same location layout.
4258 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4259 NewTL.setLBracketLoc(TL.getLBracketLoc());
4260 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004261 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004262
4263 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004264}
Mike Stump11289f42009-09-09 15:08:12 +00004265
4266template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004267QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004268 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004269 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004270 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004271
4272 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004273 QualType ElementType = getDerived().TransformType(T->getElementType());
4274 if (ElementType.isNull())
4275 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004276
Richard Smith764d2fe2011-12-20 02:08:33 +00004277 // Vector sizes are constant expressions.
4278 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4279 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004280
John McCalldadc5752010-08-24 06:29:42 +00004281 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004282 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004283 if (Size.isInvalid())
4284 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004285
John McCall550e0c22009-10-21 00:40:46 +00004286 QualType Result = TL.getType();
4287 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004288 ElementType != T->getElementType() ||
4289 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004290 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004291 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004292 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004293 if (Result.isNull())
4294 return QualType();
4295 }
John McCall550e0c22009-10-21 00:40:46 +00004296
4297 // Result might be dependent or not.
4298 if (isa<DependentSizedExtVectorType>(Result)) {
4299 DependentSizedExtVectorTypeLoc NewTL
4300 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4301 NewTL.setNameLoc(TL.getNameLoc());
4302 } else {
4303 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4304 NewTL.setNameLoc(TL.getNameLoc());
4305 }
4306
4307 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004308}
Mike Stump11289f42009-09-09 15:08:12 +00004309
4310template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004311QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004312 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004313 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004314 QualType ElementType = getDerived().TransformType(T->getElementType());
4315 if (ElementType.isNull())
4316 return QualType();
4317
John McCall550e0c22009-10-21 00:40:46 +00004318 QualType Result = TL.getType();
4319 if (getDerived().AlwaysRebuild() ||
4320 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004321 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004322 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004323 if (Result.isNull())
4324 return QualType();
4325 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004326
John McCall550e0c22009-10-21 00:40:46 +00004327 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4328 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004329
John McCall550e0c22009-10-21 00:40:46 +00004330 return Result;
4331}
4332
4333template<typename Derived>
4334QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004335 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004336 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004337 QualType ElementType = getDerived().TransformType(T->getElementType());
4338 if (ElementType.isNull())
4339 return QualType();
4340
4341 QualType Result = TL.getType();
4342 if (getDerived().AlwaysRebuild() ||
4343 ElementType != T->getElementType()) {
4344 Result = getDerived().RebuildExtVectorType(ElementType,
4345 T->getNumElements(),
4346 /*FIXME*/ SourceLocation());
4347 if (Result.isNull())
4348 return QualType();
4349 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004350
John McCall550e0c22009-10-21 00:40:46 +00004351 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4352 NewTL.setNameLoc(TL.getNameLoc());
4353
4354 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004355}
Mike Stump11289f42009-09-09 15:08:12 +00004356
David Blaikie05785d12013-02-20 22:23:23 +00004357template <typename Derived>
4358ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4359 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4360 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004361 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004362 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004363
Douglas Gregor715e4612011-01-14 22:40:04 +00004364 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004365 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004366 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004367 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004368 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004369
Douglas Gregor715e4612011-01-14 22:40:04 +00004370 TypeLocBuilder TLB;
4371 TypeLoc NewTL = OldDI->getTypeLoc();
4372 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004373
4374 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004375 OldExpansionTL.getPatternLoc());
4376 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004377 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004378
4379 Result = RebuildPackExpansionType(Result,
4380 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004381 OldExpansionTL.getEllipsisLoc(),
4382 NumExpansions);
4383 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004384 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004385
Douglas Gregor715e4612011-01-14 22:40:04 +00004386 PackExpansionTypeLoc NewExpansionTL
4387 = TLB.push<PackExpansionTypeLoc>(Result);
4388 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4389 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4390 } else
4391 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004392 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004393 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004394
John McCall8fb0d9d2011-05-01 22:35:37 +00004395 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004396 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004397
4398 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4399 OldParm->getDeclContext(),
4400 OldParm->getInnerLocStart(),
4401 OldParm->getLocation(),
4402 OldParm->getIdentifier(),
4403 NewDI->getType(),
4404 NewDI,
4405 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004406 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004407 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4408 OldParm->getFunctionScopeIndex() + indexAdjustment);
4409 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004410}
4411
4412template<typename Derived>
4413bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004414 TransformFunctionTypeParams(SourceLocation Loc,
4415 ParmVarDecl **Params, unsigned NumParams,
4416 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004417 SmallVectorImpl<QualType> &OutParamTypes,
4418 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004419 int indexAdjustment = 0;
4420
Douglas Gregordd472162011-01-07 00:20:55 +00004421 for (unsigned i = 0; i != NumParams; ++i) {
4422 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004423 assert(OldParm->getFunctionScopeIndex() == i);
4424
David Blaikie05785d12013-02-20 22:23:23 +00004425 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004426 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004427 if (OldParm->isParameterPack()) {
4428 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004429 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004430
Douglas Gregor5499af42011-01-05 23:12:31 +00004431 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004432 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004433 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004434 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4435 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004436 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4437
Douglas Gregor5499af42011-01-05 23:12:31 +00004438 // Determine whether we should expand the parameter packs.
4439 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004440 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004441 Optional<unsigned> OrigNumExpansions =
4442 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004443 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004444 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4445 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004446 Unexpanded,
4447 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004448 RetainExpansion,
4449 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004450 return true;
4451 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004452
Douglas Gregor5499af42011-01-05 23:12:31 +00004453 if (ShouldExpand) {
4454 // Expand the function parameter pack into multiple, separate
4455 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004456 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004457 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004458 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004459 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004460 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004461 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004462 OrigNumExpansions,
4463 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004464 if (!NewParm)
4465 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004466
Douglas Gregordd472162011-01-07 00:20:55 +00004467 OutParamTypes.push_back(NewParm->getType());
4468 if (PVars)
4469 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004470 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004471
4472 // If we're supposed to retain a pack expansion, do so by temporarily
4473 // forgetting the partially-substituted parameter pack.
4474 if (RetainExpansion) {
4475 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004476 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004477 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004478 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004479 OrigNumExpansions,
4480 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004481 if (!NewParm)
4482 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004483
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004484 OutParamTypes.push_back(NewParm->getType());
4485 if (PVars)
4486 PVars->push_back(NewParm);
4487 }
4488
John McCall8fb0d9d2011-05-01 22:35:37 +00004489 // The next parameter should have the same adjustment as the
4490 // last thing we pushed, but we post-incremented indexAdjustment
4491 // on every push. Also, if we push nothing, the adjustment should
4492 // go down by one.
4493 indexAdjustment--;
4494
Douglas Gregor5499af42011-01-05 23:12:31 +00004495 // We're done with the pack expansion.
4496 continue;
4497 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004498
4499 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004500 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004501 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4502 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004503 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004504 NumExpansions,
4505 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004506 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004507 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004508 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004509 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004510
John McCall58f10c32010-03-11 09:03:00 +00004511 if (!NewParm)
4512 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004513
Douglas Gregordd472162011-01-07 00:20:55 +00004514 OutParamTypes.push_back(NewParm->getType());
4515 if (PVars)
4516 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004517 continue;
4518 }
John McCall58f10c32010-03-11 09:03:00 +00004519
4520 // Deal with the possibility that we don't have a parameter
4521 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004522 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004523 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004524 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004525 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004526 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004527 = dyn_cast<PackExpansionType>(OldType)) {
4528 // We have a function parameter pack that may need to be expanded.
4529 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004530 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004531 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004532
Douglas Gregor5499af42011-01-05 23:12:31 +00004533 // Determine whether we should expand the parameter packs.
4534 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004535 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004536 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004537 Unexpanded,
4538 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004539 RetainExpansion,
4540 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004541 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004542 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004543
Douglas Gregor5499af42011-01-05 23:12:31 +00004544 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004545 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004546 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004547 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004548 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4549 QualType NewType = getDerived().TransformType(Pattern);
4550 if (NewType.isNull())
4551 return true;
John McCall58f10c32010-03-11 09:03:00 +00004552
Douglas Gregordd472162011-01-07 00:20:55 +00004553 OutParamTypes.push_back(NewType);
4554 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004555 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004556 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004557
Douglas Gregor5499af42011-01-05 23:12:31 +00004558 // We're done with the pack expansion.
4559 continue;
4560 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004561
Douglas Gregor48d24112011-01-10 20:53:55 +00004562 // If we're supposed to retain a pack expansion, do so by temporarily
4563 // forgetting the partially-substituted parameter pack.
4564 if (RetainExpansion) {
4565 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4566 QualType NewType = getDerived().TransformType(Pattern);
4567 if (NewType.isNull())
4568 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004569
Douglas Gregor48d24112011-01-10 20:53:55 +00004570 OutParamTypes.push_back(NewType);
4571 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004572 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004573 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004574
Chad Rosier1dcde962012-08-08 18:46:20 +00004575 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004576 // expansion.
4577 OldType = Expansion->getPattern();
4578 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004579 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4580 NewType = getDerived().TransformType(OldType);
4581 } else {
4582 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004583 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004584
Douglas Gregor5499af42011-01-05 23:12:31 +00004585 if (NewType.isNull())
4586 return true;
4587
4588 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004589 NewType = getSema().Context.getPackExpansionType(NewType,
4590 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004591
Douglas Gregordd472162011-01-07 00:20:55 +00004592 OutParamTypes.push_back(NewType);
4593 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004594 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004595 }
4596
John McCall8fb0d9d2011-05-01 22:35:37 +00004597#ifndef NDEBUG
4598 if (PVars) {
4599 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4600 if (ParmVarDecl *parm = (*PVars)[i])
4601 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004602 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004603#endif
4604
4605 return false;
4606}
John McCall58f10c32010-03-11 09:03:00 +00004607
4608template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004609QualType
John McCall550e0c22009-10-21 00:40:46 +00004610TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004611 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004612 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004613 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004614 return getDerived().TransformFunctionProtoType(
4615 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004616 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4617 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4618 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004619 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004620}
4621
Richard Smith2e321552014-11-12 02:00:47 +00004622template<typename Derived> template<typename Fn>
4623QualType TreeTransform<Derived>::TransformFunctionProtoType(
4624 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4625 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004626 // Transform the parameters and return type.
4627 //
Richard Smithf623c962012-04-17 00:58:00 +00004628 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004629 // When the function has a trailing return type, we instantiate the
4630 // parameters before the return type, since the return type can then refer
4631 // to the parameters themselves (via decltype, sizeof, etc.).
4632 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004633 SmallVector<QualType, 4> ParamTypes;
4634 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004635 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004636
Douglas Gregor7fb25412010-10-01 18:44:50 +00004637 QualType ResultType;
4638
Richard Smith1226c602012-08-14 22:51:13 +00004639 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004640 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004641 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004642 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004643 return QualType();
4644
Douglas Gregor3024f072012-04-16 07:05:22 +00004645 {
4646 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004647 // If a declaration declares a member function or member function
4648 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004649 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004650 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004651 // declarator.
4652 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004653
Alp Toker42a16a62014-01-25 23:51:36 +00004654 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004655 if (ResultType.isNull())
4656 return QualType();
4657 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004658 }
4659 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004660 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004661 if (ResultType.isNull())
4662 return QualType();
4663
Alp Toker9cacbab2014-01-20 20:26:09 +00004664 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004665 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004666 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004667 return QualType();
4668 }
4669
Richard Smith2e321552014-11-12 02:00:47 +00004670 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4671
4672 bool EPIChanged = false;
4673 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4674 return QualType();
4675
4676 // FIXME: Need to transform ConsumedParameters for variadic template
4677 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004678
John McCall550e0c22009-10-21 00:40:46 +00004679 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004680 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004681 T->getNumParams() != ParamTypes.size() ||
4682 !std::equal(T->param_type_begin(), T->param_type_end(),
Richard Smith2e321552014-11-12 02:00:47 +00004683 ParamTypes.begin()) || EPIChanged) {
4684 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004685 if (Result.isNull())
4686 return QualType();
4687 }
Mike Stump11289f42009-09-09 15:08:12 +00004688
John McCall550e0c22009-10-21 00:40:46 +00004689 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004690 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004691 NewTL.setLParenLoc(TL.getLParenLoc());
4692 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004693 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004694 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4695 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004696
4697 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004698}
Mike Stump11289f42009-09-09 15:08:12 +00004699
Douglas Gregord6ff3322009-08-04 16:50:30 +00004700template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004701bool TreeTransform<Derived>::TransformExceptionSpec(
4702 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4703 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4704 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4705
4706 // Instantiate a dynamic noexcept expression, if any.
4707 if (ESI.Type == EST_ComputedNoexcept) {
4708 EnterExpressionEvaluationContext Unevaluated(getSema(),
4709 Sema::ConstantEvaluated);
4710 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4711 if (NoexceptExpr.isInvalid())
4712 return true;
4713
4714 NoexceptExpr = getSema().CheckBooleanCondition(
4715 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4716 if (NoexceptExpr.isInvalid())
4717 return true;
4718
4719 if (!NoexceptExpr.get()->isValueDependent()) {
4720 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4721 NoexceptExpr.get(), nullptr,
4722 diag::err_noexcept_needs_constant_expression,
4723 /*AllowFold*/false);
4724 if (NoexceptExpr.isInvalid())
4725 return true;
4726 }
4727
4728 if (ESI.NoexceptExpr != NoexceptExpr.get())
4729 Changed = true;
4730 ESI.NoexceptExpr = NoexceptExpr.get();
4731 }
4732
4733 if (ESI.Type != EST_Dynamic)
4734 return false;
4735
4736 // Instantiate a dynamic exception specification's type.
4737 for (QualType T : ESI.Exceptions) {
4738 if (const PackExpansionType *PackExpansion =
4739 T->getAs<PackExpansionType>()) {
4740 Changed = true;
4741
4742 // We have a pack expansion. Instantiate it.
4743 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4744 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4745 Unexpanded);
4746 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4747
4748 // Determine whether the set of unexpanded parameter packs can and
4749 // should
4750 // be expanded.
4751 bool Expand = false;
4752 bool RetainExpansion = false;
4753 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4754 // FIXME: Track the location of the ellipsis (and track source location
4755 // information for the types in the exception specification in general).
4756 if (getDerived().TryExpandParameterPacks(
4757 Loc, SourceRange(), Unexpanded, Expand,
4758 RetainExpansion, NumExpansions))
4759 return true;
4760
4761 if (!Expand) {
4762 // We can't expand this pack expansion into separate arguments yet;
4763 // just substitute into the pattern and create a new pack expansion
4764 // type.
4765 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4766 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4767 if (U.isNull())
4768 return true;
4769
4770 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4771 Exceptions.push_back(U);
4772 continue;
4773 }
4774
4775 // Substitute into the pack expansion pattern for each slice of the
4776 // pack.
4777 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4778 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4779
4780 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4781 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4782 return true;
4783
4784 Exceptions.push_back(U);
4785 }
4786 } else {
4787 QualType U = getDerived().TransformType(T);
4788 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4789 return true;
4790 if (T != U)
4791 Changed = true;
4792
4793 Exceptions.push_back(U);
4794 }
4795 }
4796
4797 ESI.Exceptions = Exceptions;
4798 return false;
4799}
4800
4801template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004802QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004803 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004804 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004805 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004806 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004807 if (ResultType.isNull())
4808 return QualType();
4809
4810 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004811 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004812 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4813
4814 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004815 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004816 NewTL.setLParenLoc(TL.getLParenLoc());
4817 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004818 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004819
4820 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004821}
Mike Stump11289f42009-09-09 15:08:12 +00004822
John McCallb96ec562009-12-04 22:46:56 +00004823template<typename Derived> QualType
4824TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004825 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004826 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004827 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004828 if (!D)
4829 return QualType();
4830
4831 QualType Result = TL.getType();
4832 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4833 Result = getDerived().RebuildUnresolvedUsingType(D);
4834 if (Result.isNull())
4835 return QualType();
4836 }
4837
4838 // We might get an arbitrary type spec type back. We should at
4839 // least always get a type spec type, though.
4840 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4841 NewTL.setNameLoc(TL.getNameLoc());
4842
4843 return Result;
4844}
4845
Douglas Gregord6ff3322009-08-04 16:50:30 +00004846template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004847QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004848 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004849 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004850 TypedefNameDecl *Typedef
4851 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4852 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004853 if (!Typedef)
4854 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004855
John McCall550e0c22009-10-21 00:40:46 +00004856 QualType Result = TL.getType();
4857 if (getDerived().AlwaysRebuild() ||
4858 Typedef != T->getDecl()) {
4859 Result = getDerived().RebuildTypedefType(Typedef);
4860 if (Result.isNull())
4861 return QualType();
4862 }
Mike Stump11289f42009-09-09 15:08:12 +00004863
John McCall550e0c22009-10-21 00:40:46 +00004864 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4865 NewTL.setNameLoc(TL.getNameLoc());
4866
4867 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004868}
Mike Stump11289f42009-09-09 15:08:12 +00004869
Douglas Gregord6ff3322009-08-04 16:50:30 +00004870template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004871QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004872 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004873 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004874 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4875 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004876
John McCalldadc5752010-08-24 06:29:42 +00004877 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004878 if (E.isInvalid())
4879 return QualType();
4880
Eli Friedmane4f22df2012-02-29 04:03:55 +00004881 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4882 if (E.isInvalid())
4883 return QualType();
4884
John McCall550e0c22009-10-21 00:40:46 +00004885 QualType Result = TL.getType();
4886 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004887 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004888 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004889 if (Result.isNull())
4890 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004891 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004892 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004893
John McCall550e0c22009-10-21 00:40:46 +00004894 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004895 NewTL.setTypeofLoc(TL.getTypeofLoc());
4896 NewTL.setLParenLoc(TL.getLParenLoc());
4897 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004898
4899 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004900}
Mike Stump11289f42009-09-09 15:08:12 +00004901
4902template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004903QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004904 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004905 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4906 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4907 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004908 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004909
John McCall550e0c22009-10-21 00:40:46 +00004910 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004911 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4912 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004913 if (Result.isNull())
4914 return QualType();
4915 }
Mike Stump11289f42009-09-09 15:08:12 +00004916
John McCall550e0c22009-10-21 00:40:46 +00004917 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004918 NewTL.setTypeofLoc(TL.getTypeofLoc());
4919 NewTL.setLParenLoc(TL.getLParenLoc());
4920 NewTL.setRParenLoc(TL.getRParenLoc());
4921 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004922
4923 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004924}
Mike Stump11289f42009-09-09 15:08:12 +00004925
4926template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004927QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004928 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004929 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004930
Douglas Gregore922c772009-08-04 22:27:00 +00004931 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004932 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4933 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004934
John McCalldadc5752010-08-24 06:29:42 +00004935 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004936 if (E.isInvalid())
4937 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004938
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004939 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004940 if (E.isInvalid())
4941 return QualType();
4942
John McCall550e0c22009-10-21 00:40:46 +00004943 QualType Result = TL.getType();
4944 if (getDerived().AlwaysRebuild() ||
4945 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004946 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004947 if (Result.isNull())
4948 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004949 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004950 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004951
John McCall550e0c22009-10-21 00:40:46 +00004952 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4953 NewTL.setNameLoc(TL.getNameLoc());
4954
4955 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004956}
4957
4958template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004959QualType TreeTransform<Derived>::TransformUnaryTransformType(
4960 TypeLocBuilder &TLB,
4961 UnaryTransformTypeLoc TL) {
4962 QualType Result = TL.getType();
4963 if (Result->isDependentType()) {
4964 const UnaryTransformType *T = TL.getTypePtr();
4965 QualType NewBase =
4966 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4967 Result = getDerived().RebuildUnaryTransformType(NewBase,
4968 T->getUTTKind(),
4969 TL.getKWLoc());
4970 if (Result.isNull())
4971 return QualType();
4972 }
4973
4974 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4975 NewTL.setKWLoc(TL.getKWLoc());
4976 NewTL.setParensRange(TL.getParensRange());
4977 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4978 return Result;
4979}
4980
4981template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004982QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4983 AutoTypeLoc TL) {
4984 const AutoType *T = TL.getTypePtr();
4985 QualType OldDeduced = T->getDeducedType();
4986 QualType NewDeduced;
4987 if (!OldDeduced.isNull()) {
4988 NewDeduced = getDerived().TransformType(OldDeduced);
4989 if (NewDeduced.isNull())
4990 return QualType();
4991 }
4992
4993 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004994 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4995 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004996 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004997 if (Result.isNull())
4998 return QualType();
4999 }
5000
5001 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5002 NewTL.setNameLoc(TL.getNameLoc());
5003
5004 return Result;
5005}
5006
5007template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005008QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005009 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005010 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005011 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005012 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5013 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005014 if (!Record)
5015 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005016
John McCall550e0c22009-10-21 00:40:46 +00005017 QualType Result = TL.getType();
5018 if (getDerived().AlwaysRebuild() ||
5019 Record != T->getDecl()) {
5020 Result = getDerived().RebuildRecordType(Record);
5021 if (Result.isNull())
5022 return QualType();
5023 }
Mike Stump11289f42009-09-09 15:08:12 +00005024
John McCall550e0c22009-10-21 00:40:46 +00005025 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5026 NewTL.setNameLoc(TL.getNameLoc());
5027
5028 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005029}
Mike Stump11289f42009-09-09 15:08:12 +00005030
5031template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005032QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005033 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005034 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005035 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005036 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5037 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005038 if (!Enum)
5039 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005040
John McCall550e0c22009-10-21 00:40:46 +00005041 QualType Result = TL.getType();
5042 if (getDerived().AlwaysRebuild() ||
5043 Enum != T->getDecl()) {
5044 Result = getDerived().RebuildEnumType(Enum);
5045 if (Result.isNull())
5046 return QualType();
5047 }
Mike Stump11289f42009-09-09 15:08:12 +00005048
John McCall550e0c22009-10-21 00:40:46 +00005049 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5050 NewTL.setNameLoc(TL.getNameLoc());
5051
5052 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005053}
John McCallfcc33b02009-09-05 00:15:47 +00005054
John McCalle78aac42010-03-10 03:28:59 +00005055template<typename Derived>
5056QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5057 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005058 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005059 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5060 TL.getTypePtr()->getDecl());
5061 if (!D) return QualType();
5062
5063 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5064 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5065 return T;
5066}
5067
Douglas Gregord6ff3322009-08-04 16:50:30 +00005068template<typename Derived>
5069QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005070 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005071 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005072 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005073}
5074
Mike Stump11289f42009-09-09 15:08:12 +00005075template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005076QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005077 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005078 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005079 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005080
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005081 // Substitute into the replacement type, which itself might involve something
5082 // that needs to be transformed. This only tends to occur with default
5083 // template arguments of template template parameters.
5084 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5085 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5086 if (Replacement.isNull())
5087 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005088
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005089 // Always canonicalize the replacement type.
5090 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5091 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005092 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005093 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005094
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005095 // Propagate type-source information.
5096 SubstTemplateTypeParmTypeLoc NewTL
5097 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5098 NewTL.setNameLoc(TL.getNameLoc());
5099 return Result;
5100
John McCallcebee162009-10-18 09:09:24 +00005101}
5102
5103template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005104QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5105 TypeLocBuilder &TLB,
5106 SubstTemplateTypeParmPackTypeLoc TL) {
5107 return TransformTypeSpecType(TLB, TL);
5108}
5109
5110template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005111QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005112 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005113 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005114 const TemplateSpecializationType *T = TL.getTypePtr();
5115
Douglas Gregordf846d12011-03-02 18:46:51 +00005116 // The nested-name-specifier never matters in a TemplateSpecializationType,
5117 // because we can't have a dependent nested-name-specifier anyway.
5118 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005119 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005120 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5121 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005122 if (Template.isNull())
5123 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005124
John McCall31f82722010-11-12 08:19:04 +00005125 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5126}
5127
Eli Friedman0dfb8892011-10-06 23:00:33 +00005128template<typename Derived>
5129QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5130 AtomicTypeLoc TL) {
5131 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5132 if (ValueType.isNull())
5133 return QualType();
5134
5135 QualType Result = TL.getType();
5136 if (getDerived().AlwaysRebuild() ||
5137 ValueType != TL.getValueLoc().getType()) {
5138 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5139 if (Result.isNull())
5140 return QualType();
5141 }
5142
5143 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5144 NewTL.setKWLoc(TL.getKWLoc());
5145 NewTL.setLParenLoc(TL.getLParenLoc());
5146 NewTL.setRParenLoc(TL.getRParenLoc());
5147
5148 return Result;
5149}
5150
Chad Rosier1dcde962012-08-08 18:46:20 +00005151 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005152 /// container that provides a \c getArgLoc() member function.
5153 ///
5154 /// This iterator is intended to be used with the iterator form of
5155 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5156 template<typename ArgLocContainer>
5157 class TemplateArgumentLocContainerIterator {
5158 ArgLocContainer *Container;
5159 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005160
Douglas Gregorfe921a72010-12-20 23:36:19 +00005161 public:
5162 typedef TemplateArgumentLoc value_type;
5163 typedef TemplateArgumentLoc reference;
5164 typedef int difference_type;
5165 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005166
Douglas Gregorfe921a72010-12-20 23:36:19 +00005167 class pointer {
5168 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005169
Douglas Gregorfe921a72010-12-20 23:36:19 +00005170 public:
5171 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005172
Douglas Gregorfe921a72010-12-20 23:36:19 +00005173 const TemplateArgumentLoc *operator->() const {
5174 return &Arg;
5175 }
5176 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005177
5178
Douglas Gregorfe921a72010-12-20 23:36:19 +00005179 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005180
Douglas Gregorfe921a72010-12-20 23:36:19 +00005181 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5182 unsigned Index)
5183 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005184
Douglas Gregorfe921a72010-12-20 23:36:19 +00005185 TemplateArgumentLocContainerIterator &operator++() {
5186 ++Index;
5187 return *this;
5188 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005189
Douglas Gregorfe921a72010-12-20 23:36:19 +00005190 TemplateArgumentLocContainerIterator operator++(int) {
5191 TemplateArgumentLocContainerIterator Old(*this);
5192 ++(*this);
5193 return Old;
5194 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005195
Douglas Gregorfe921a72010-12-20 23:36:19 +00005196 TemplateArgumentLoc operator*() const {
5197 return Container->getArgLoc(Index);
5198 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005199
Douglas Gregorfe921a72010-12-20 23:36:19 +00005200 pointer operator->() const {
5201 return pointer(Container->getArgLoc(Index));
5202 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005203
Douglas Gregorfe921a72010-12-20 23:36:19 +00005204 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005205 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005206 return X.Container == Y.Container && X.Index == Y.Index;
5207 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005208
Douglas Gregorfe921a72010-12-20 23:36:19 +00005209 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005210 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005211 return !(X == Y);
5212 }
5213 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005214
5215
John McCall31f82722010-11-12 08:19:04 +00005216template <typename Derived>
5217QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5218 TypeLocBuilder &TLB,
5219 TemplateSpecializationTypeLoc TL,
5220 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005221 TemplateArgumentListInfo NewTemplateArgs;
5222 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5223 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005224 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5225 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005226 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005227 ArgIterator(TL, TL.getNumArgs()),
5228 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005229 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005230
John McCall0ad16662009-10-29 08:12:44 +00005231 // FIXME: maybe don't rebuild if all the template arguments are the same.
5232
5233 QualType Result =
5234 getDerived().RebuildTemplateSpecializationType(Template,
5235 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005236 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005237
5238 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005239 // Specializations of template template parameters are represented as
5240 // TemplateSpecializationTypes, and substitution of type alias templates
5241 // within a dependent context can transform them into
5242 // DependentTemplateSpecializationTypes.
5243 if (isa<DependentTemplateSpecializationType>(Result)) {
5244 DependentTemplateSpecializationTypeLoc NewTL
5245 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005246 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005247 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005248 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005249 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005250 NewTL.setLAngleLoc(TL.getLAngleLoc());
5251 NewTL.setRAngleLoc(TL.getRAngleLoc());
5252 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5253 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5254 return Result;
5255 }
5256
John McCall0ad16662009-10-29 08:12:44 +00005257 TemplateSpecializationTypeLoc NewTL
5258 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005259 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005260 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5261 NewTL.setLAngleLoc(TL.getLAngleLoc());
5262 NewTL.setRAngleLoc(TL.getRAngleLoc());
5263 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5264 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005265 }
Mike Stump11289f42009-09-09 15:08:12 +00005266
John McCall0ad16662009-10-29 08:12:44 +00005267 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005268}
Mike Stump11289f42009-09-09 15:08:12 +00005269
Douglas Gregor5a064722011-02-28 17:23:35 +00005270template <typename Derived>
5271QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5272 TypeLocBuilder &TLB,
5273 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005274 TemplateName Template,
5275 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005276 TemplateArgumentListInfo NewTemplateArgs;
5277 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5278 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5279 typedef TemplateArgumentLocContainerIterator<
5280 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005281 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005282 ArgIterator(TL, TL.getNumArgs()),
5283 NewTemplateArgs))
5284 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005285
Douglas Gregor5a064722011-02-28 17:23:35 +00005286 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005287
Douglas Gregor5a064722011-02-28 17:23:35 +00005288 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5289 QualType Result
5290 = getSema().Context.getDependentTemplateSpecializationType(
5291 TL.getTypePtr()->getKeyword(),
5292 DTN->getQualifier(),
5293 DTN->getIdentifier(),
5294 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005295
Douglas Gregor5a064722011-02-28 17:23:35 +00005296 DependentTemplateSpecializationTypeLoc NewTL
5297 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005298 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005299 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005300 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005301 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005302 NewTL.setLAngleLoc(TL.getLAngleLoc());
5303 NewTL.setRAngleLoc(TL.getRAngleLoc());
5304 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5305 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5306 return Result;
5307 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005308
5309 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005310 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005311 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005312 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005313
Douglas Gregor5a064722011-02-28 17:23:35 +00005314 if (!Result.isNull()) {
5315 /// FIXME: Wrap this in an elaborated-type-specifier?
5316 TemplateSpecializationTypeLoc NewTL
5317 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005318 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005319 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005320 NewTL.setLAngleLoc(TL.getLAngleLoc());
5321 NewTL.setRAngleLoc(TL.getRAngleLoc());
5322 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5323 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5324 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005325
Douglas Gregor5a064722011-02-28 17:23:35 +00005326 return Result;
5327}
5328
Mike Stump11289f42009-09-09 15:08:12 +00005329template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005330QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005331TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005332 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005333 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005334
Douglas Gregor844cb502011-03-01 18:12:44 +00005335 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005336 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005337 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005338 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005339 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5340 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005341 return QualType();
5342 }
Mike Stump11289f42009-09-09 15:08:12 +00005343
John McCall31f82722010-11-12 08:19:04 +00005344 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5345 if (NamedT.isNull())
5346 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005347
Richard Smith3f1b5d02011-05-05 21:57:07 +00005348 // C++0x [dcl.type.elab]p2:
5349 // If the identifier resolves to a typedef-name or the simple-template-id
5350 // resolves to an alias template specialization, the
5351 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005352 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5353 if (const TemplateSpecializationType *TST =
5354 NamedT->getAs<TemplateSpecializationType>()) {
5355 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005356 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5357 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005358 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5359 diag::err_tag_reference_non_tag) << 4;
5360 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5361 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005362 }
5363 }
5364
John McCall550e0c22009-10-21 00:40:46 +00005365 QualType Result = TL.getType();
5366 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005367 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005368 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005369 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005370 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005371 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005372 if (Result.isNull())
5373 return QualType();
5374 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005375
Abramo Bagnara6150c882010-05-11 21:36:43 +00005376 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005377 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005378 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005379 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005380}
Mike Stump11289f42009-09-09 15:08:12 +00005381
5382template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005383QualType TreeTransform<Derived>::TransformAttributedType(
5384 TypeLocBuilder &TLB,
5385 AttributedTypeLoc TL) {
5386 const AttributedType *oldType = TL.getTypePtr();
5387 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5388 if (modifiedType.isNull())
5389 return QualType();
5390
5391 QualType result = TL.getType();
5392
5393 // FIXME: dependent operand expressions?
5394 if (getDerived().AlwaysRebuild() ||
5395 modifiedType != oldType->getModifiedType()) {
5396 // TODO: this is really lame; we should really be rebuilding the
5397 // equivalent type from first principles.
5398 QualType equivalentType
5399 = getDerived().TransformType(oldType->getEquivalentType());
5400 if (equivalentType.isNull())
5401 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005402
5403 // Check whether we can add nullability; it is only represented as
5404 // type sugar, and therefore cannot be diagnosed in any other way.
5405 if (auto nullability = oldType->getImmediateNullability()) {
5406 if (!modifiedType->canHaveNullability()) {
5407 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005408 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005409 return QualType();
5410 }
5411 }
5412
John McCall81904512011-01-06 01:58:22 +00005413 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5414 modifiedType,
5415 equivalentType);
5416 }
5417
5418 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5419 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5420 if (TL.hasAttrOperand())
5421 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5422 if (TL.hasAttrExprOperand())
5423 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5424 else if (TL.hasAttrEnumOperand())
5425 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5426
5427 return result;
5428}
5429
5430template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005431QualType
5432TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5433 ParenTypeLoc TL) {
5434 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5435 if (Inner.isNull())
5436 return QualType();
5437
5438 QualType Result = TL.getType();
5439 if (getDerived().AlwaysRebuild() ||
5440 Inner != TL.getInnerLoc().getType()) {
5441 Result = getDerived().RebuildParenType(Inner);
5442 if (Result.isNull())
5443 return QualType();
5444 }
5445
5446 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5447 NewTL.setLParenLoc(TL.getLParenLoc());
5448 NewTL.setRParenLoc(TL.getRParenLoc());
5449 return Result;
5450}
5451
5452template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005453QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005454 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005455 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005456
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005457 NestedNameSpecifierLoc QualifierLoc
5458 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5459 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005460 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005461
John McCallc392f372010-06-11 00:33:02 +00005462 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005463 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005464 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005465 QualifierLoc,
5466 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005467 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005468 if (Result.isNull())
5469 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005470
Abramo Bagnarad7548482010-05-19 21:37:53 +00005471 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5472 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005473 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5474
Abramo Bagnarad7548482010-05-19 21:37:53 +00005475 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005476 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005477 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005478 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005479 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005480 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005481 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005482 NewTL.setNameLoc(TL.getNameLoc());
5483 }
John McCall550e0c22009-10-21 00:40:46 +00005484 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005485}
Mike Stump11289f42009-09-09 15:08:12 +00005486
Douglas Gregord6ff3322009-08-04 16:50:30 +00005487template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005488QualType TreeTransform<Derived>::
5489 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005490 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005491 NestedNameSpecifierLoc QualifierLoc;
5492 if (TL.getQualifierLoc()) {
5493 QualifierLoc
5494 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5495 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005496 return QualType();
5497 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005498
John McCall31f82722010-11-12 08:19:04 +00005499 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005500 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005501}
5502
5503template<typename Derived>
5504QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005505TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5506 DependentTemplateSpecializationTypeLoc TL,
5507 NestedNameSpecifierLoc QualifierLoc) {
5508 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005509
Douglas Gregora7a795b2011-03-01 20:11:18 +00005510 TemplateArgumentListInfo NewTemplateArgs;
5511 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5512 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005513
Douglas Gregora7a795b2011-03-01 20:11:18 +00005514 typedef TemplateArgumentLocContainerIterator<
5515 DependentTemplateSpecializationTypeLoc> ArgIterator;
5516 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5517 ArgIterator(TL, TL.getNumArgs()),
5518 NewTemplateArgs))
5519 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005520
Douglas Gregora7a795b2011-03-01 20:11:18 +00005521 QualType Result
5522 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5523 QualifierLoc,
5524 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005525 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005526 NewTemplateArgs);
5527 if (Result.isNull())
5528 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005529
Douglas Gregora7a795b2011-03-01 20:11:18 +00005530 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5531 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005532
Douglas Gregora7a795b2011-03-01 20:11:18 +00005533 // Copy information relevant to the template specialization.
5534 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005535 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005536 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005537 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005538 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5539 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005540 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005541 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005542
Douglas Gregora7a795b2011-03-01 20:11:18 +00005543 // Copy information relevant to the elaborated type.
5544 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005545 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005546 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005547 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5548 DependentTemplateSpecializationTypeLoc SpecTL
5549 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005550 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005551 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005552 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005553 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005554 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5555 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005556 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005557 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005558 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005559 TemplateSpecializationTypeLoc SpecTL
5560 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005561 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005562 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005563 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5564 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005565 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005566 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005567 }
5568 return Result;
5569}
5570
5571template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005572QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5573 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005574 QualType Pattern
5575 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005576 if (Pattern.isNull())
5577 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005578
5579 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005580 if (getDerived().AlwaysRebuild() ||
5581 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005582 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005583 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005584 TL.getEllipsisLoc(),
5585 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005586 if (Result.isNull())
5587 return QualType();
5588 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005589
Douglas Gregor822d0302011-01-12 17:07:58 +00005590 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5591 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5592 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005593}
5594
5595template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005596QualType
5597TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005598 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005599 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005600 TLB.pushFullCopy(TL);
5601 return TL.getType();
5602}
5603
5604template<typename Derived>
5605QualType
5606TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005607 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005608 // ObjCObjectType is never dependent.
5609 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005610 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005611}
Mike Stump11289f42009-09-09 15:08:12 +00005612
5613template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005614QualType
5615TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005616 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005617 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005618 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005619 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005620}
5621
Douglas Gregord6ff3322009-08-04 16:50:30 +00005622//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005623// Statement transformation
5624//===----------------------------------------------------------------------===//
5625template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005626StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005627TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005628 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005629}
5630
5631template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005632StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005633TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5634 return getDerived().TransformCompoundStmt(S, false);
5635}
5636
5637template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005638StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005639TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005640 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005641 Sema::CompoundScopeRAII CompoundScope(getSema());
5642
John McCall1ababa62010-08-27 19:56:05 +00005643 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005644 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005645 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005646 for (auto *B : S->body()) {
5647 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005648 if (Result.isInvalid()) {
5649 // Immediately fail if this was a DeclStmt, since it's very
5650 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005651 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005652 return StmtError();
5653
5654 // Otherwise, just keep processing substatements and fail later.
5655 SubStmtInvalid = true;
5656 continue;
5657 }
Mike Stump11289f42009-09-09 15:08:12 +00005658
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005659 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005660 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005661 }
Mike Stump11289f42009-09-09 15:08:12 +00005662
John McCall1ababa62010-08-27 19:56:05 +00005663 if (SubStmtInvalid)
5664 return StmtError();
5665
Douglas Gregorebe10102009-08-20 07:17:43 +00005666 if (!getDerived().AlwaysRebuild() &&
5667 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005668 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005669
5670 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005671 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005672 S->getRBracLoc(),
5673 IsStmtExpr);
5674}
Mike Stump11289f42009-09-09 15:08:12 +00005675
Douglas Gregorebe10102009-08-20 07:17:43 +00005676template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005677StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005678TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005679 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005680 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005681 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5682 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005683
Eli Friedman06577382009-11-19 03:14:00 +00005684 // Transform the left-hand case value.
5685 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005686 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005687 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005688 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005689
Eli Friedman06577382009-11-19 03:14:00 +00005690 // Transform the right-hand case value (for the GNU case-range extension).
5691 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005692 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005693 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005694 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005695 }
Mike Stump11289f42009-09-09 15:08:12 +00005696
Douglas Gregorebe10102009-08-20 07:17:43 +00005697 // Build the case statement.
5698 // Case statements are always rebuilt so that they will attached to their
5699 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005700 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005701 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005702 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005703 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005704 S->getColonLoc());
5705 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005706 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005707
Douglas Gregorebe10102009-08-20 07:17:43 +00005708 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005709 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005710 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005711 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005712
Douglas Gregorebe10102009-08-20 07:17:43 +00005713 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005714 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005715}
5716
5717template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005718StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005719TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005720 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005721 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005722 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005723 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005724
Douglas Gregorebe10102009-08-20 07:17:43 +00005725 // Default statements are always rebuilt
5726 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005727 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005728}
Mike Stump11289f42009-09-09 15:08:12 +00005729
Douglas Gregorebe10102009-08-20 07:17:43 +00005730template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005731StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005732TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005733 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005734 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005735 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005736
Chris Lattnercab02a62011-02-17 20:34:02 +00005737 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5738 S->getDecl());
5739 if (!LD)
5740 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005741
5742
Douglas Gregorebe10102009-08-20 07:17:43 +00005743 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005744 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005745 cast<LabelDecl>(LD), SourceLocation(),
5746 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005747}
Mike Stump11289f42009-09-09 15:08:12 +00005748
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005749template <typename Derived>
5750const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
5751 if (!R)
5752 return R;
5753
5754 switch (R->getKind()) {
5755// Transform attributes with a pragma spelling by calling TransformXXXAttr.
5756#define ATTR(X)
5757#define PRAGMA_SPELLING_ATTR(X) \
5758 case attr::X: \
5759 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
5760#include "clang/Basic/AttrList.inc"
5761 default:
5762 return R;
5763 }
5764}
5765
5766template <typename Derived>
5767StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5768 bool AttrsChanged = false;
5769 SmallVector<const Attr *, 1> Attrs;
5770
5771 // Visit attributes and keep track if any are transformed.
5772 for (const auto *I : S->getAttrs()) {
5773 const Attr *R = getDerived().TransformAttr(I);
5774 AttrsChanged |= (I != R);
5775 Attrs.push_back(R);
5776 }
5777
Richard Smithc202b282012-04-14 00:33:13 +00005778 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5779 if (SubStmt.isInvalid())
5780 return StmtError();
5781
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005782 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00005783 return S;
5784
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005785 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00005786 SubStmt.get());
5787}
5788
5789template<typename Derived>
5790StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005791TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005792 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005793 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005794 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005795 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005796 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005797 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005798 getDerived().TransformDefinition(
5799 S->getConditionVariable()->getLocation(),
5800 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005801 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005802 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005803 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005804 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005805
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005806 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005807 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005808
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005809 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005810 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005811 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005812 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005813 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005814 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005815
John McCallb268a282010-08-23 23:25:46 +00005816 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005817 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005818 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005819
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005820 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005821 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005822 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005823
Douglas Gregorebe10102009-08-20 07:17:43 +00005824 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005825 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005826 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005827 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005828
Douglas Gregorebe10102009-08-20 07:17:43 +00005829 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005830 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005831 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005832 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005833
Douglas Gregorebe10102009-08-20 07:17:43 +00005834 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005835 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005836 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005837 Then.get() == S->getThen() &&
5838 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005839 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005840
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005841 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005842 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005843 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005844}
5845
5846template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005847StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005848TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005849 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005850 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005851 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005852 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005853 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005854 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005855 getDerived().TransformDefinition(
5856 S->getConditionVariable()->getLocation(),
5857 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005858 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005859 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005860 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005861 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005862
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005863 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005864 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005865 }
Mike Stump11289f42009-09-09 15:08:12 +00005866
Douglas Gregorebe10102009-08-20 07:17:43 +00005867 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005868 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005869 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005870 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005871 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005872 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005873
Douglas Gregorebe10102009-08-20 07:17:43 +00005874 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005875 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005876 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005877 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005878
Douglas Gregorebe10102009-08-20 07:17:43 +00005879 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005880 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5881 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005882}
Mike Stump11289f42009-09-09 15:08:12 +00005883
Douglas Gregorebe10102009-08-20 07:17:43 +00005884template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005885StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005886TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005887 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005888 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005889 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005890 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005891 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005892 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005893 getDerived().TransformDefinition(
5894 S->getConditionVariable()->getLocation(),
5895 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005896 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005897 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005898 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005899 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005900
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005901 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005902 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005903
5904 if (S->getCond()) {
5905 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005906 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5907 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005908 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005909 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005910 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005911 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005912 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005913 }
Mike Stump11289f42009-09-09 15:08:12 +00005914
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005915 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005916 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005917 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005918
Douglas Gregorebe10102009-08-20 07:17:43 +00005919 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005920 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005921 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005922 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005923
Douglas Gregorebe10102009-08-20 07:17:43 +00005924 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005925 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005926 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005927 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005928 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005929
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005930 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005931 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005932}
Mike Stump11289f42009-09-09 15:08:12 +00005933
Douglas Gregorebe10102009-08-20 07:17:43 +00005934template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005935StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005936TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005937 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005938 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005939 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005940 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005941
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005942 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005943 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005944 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005945 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005946
Douglas Gregorebe10102009-08-20 07:17:43 +00005947 if (!getDerived().AlwaysRebuild() &&
5948 Cond.get() == S->getCond() &&
5949 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005950 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005951
John McCallb268a282010-08-23 23:25:46 +00005952 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5953 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005954 S->getRParenLoc());
5955}
Mike Stump11289f42009-09-09 15:08:12 +00005956
Douglas Gregorebe10102009-08-20 07:17:43 +00005957template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005958StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005959TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005960 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005961 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005962 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005963 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005964
Douglas Gregorebe10102009-08-20 07:17:43 +00005965 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005966 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005967 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005968 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005969 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005970 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005971 getDerived().TransformDefinition(
5972 S->getConditionVariable()->getLocation(),
5973 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005974 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005975 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005976 } else {
5977 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005978
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005979 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005980 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005981
5982 if (S->getCond()) {
5983 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005984 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5985 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005986 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005987 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005988 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005989
John McCallb268a282010-08-23 23:25:46 +00005990 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005991 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005992 }
Mike Stump11289f42009-09-09 15:08:12 +00005993
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005994 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005995 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005996 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005997
Douglas Gregorebe10102009-08-20 07:17:43 +00005998 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005999 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006000 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006001 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006002
Richard Smith945f8d32013-01-14 22:39:08 +00006003 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006004 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006005 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006006
Douglas Gregorebe10102009-08-20 07:17:43 +00006007 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006008 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006009 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006010 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006011
Douglas Gregorebe10102009-08-20 07:17:43 +00006012 if (!getDerived().AlwaysRebuild() &&
6013 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00006014 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006015 Inc.get() == S->getInc() &&
6016 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006017 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006018
Douglas Gregorebe10102009-08-20 07:17:43 +00006019 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006020 Init.get(), FullCond, ConditionVar,
6021 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006022}
6023
6024template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006025StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006026TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006027 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6028 S->getLabel());
6029 if (!LD)
6030 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006031
Douglas Gregorebe10102009-08-20 07:17:43 +00006032 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006033 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006034 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006035}
6036
6037template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006038StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006039TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006040 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006041 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006042 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006043 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006044
Douglas Gregorebe10102009-08-20 07:17:43 +00006045 if (!getDerived().AlwaysRebuild() &&
6046 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006047 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006048
6049 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006050 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006051}
6052
6053template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006054StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006055TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006056 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006057}
Mike Stump11289f42009-09-09 15:08:12 +00006058
Douglas Gregorebe10102009-08-20 07:17:43 +00006059template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006060StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006061TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006062 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006063}
Mike Stump11289f42009-09-09 15:08:12 +00006064
Douglas Gregorebe10102009-08-20 07:17:43 +00006065template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006066StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006067TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006068 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6069 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006070 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006071 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006072
Mike Stump11289f42009-09-09 15:08:12 +00006073 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006074 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006075 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006076}
Mike Stump11289f42009-09-09 15:08:12 +00006077
Douglas Gregorebe10102009-08-20 07:17:43 +00006078template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006079StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006080TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006081 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006082 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006083 for (auto *D : S->decls()) {
6084 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006085 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006086 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006087
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006088 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006089 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006090
Douglas Gregorebe10102009-08-20 07:17:43 +00006091 Decls.push_back(Transformed);
6092 }
Mike Stump11289f42009-09-09 15:08:12 +00006093
Douglas Gregorebe10102009-08-20 07:17:43 +00006094 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006095 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006096
Rafael Espindolaab417692013-07-09 12:05:01 +00006097 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006098}
Mike Stump11289f42009-09-09 15:08:12 +00006099
Douglas Gregorebe10102009-08-20 07:17:43 +00006100template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006101StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006102TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006103
Benjamin Kramerf0623432012-08-23 22:51:59 +00006104 SmallVector<Expr*, 8> Constraints;
6105 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006106 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006107
John McCalldadc5752010-08-24 06:29:42 +00006108 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006109 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006110
6111 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006112
Anders Carlssonaaeef072010-01-24 05:50:09 +00006113 // Go through the outputs.
6114 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006115 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006116
Anders Carlssonaaeef072010-01-24 05:50:09 +00006117 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006118 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006119
Anders Carlssonaaeef072010-01-24 05:50:09 +00006120 // Transform the output expr.
6121 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006122 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006123 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006124 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006125
Anders Carlssonaaeef072010-01-24 05:50:09 +00006126 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006127
John McCallb268a282010-08-23 23:25:46 +00006128 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006129 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006130
Anders Carlssonaaeef072010-01-24 05:50:09 +00006131 // Go through the inputs.
6132 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006133 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006134
Anders Carlssonaaeef072010-01-24 05:50:09 +00006135 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006136 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006137
Anders Carlssonaaeef072010-01-24 05:50:09 +00006138 // Transform the input expr.
6139 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006140 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006141 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006142 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006143
Anders Carlssonaaeef072010-01-24 05:50:09 +00006144 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006145
John McCallb268a282010-08-23 23:25:46 +00006146 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006147 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006148
Anders Carlssonaaeef072010-01-24 05:50:09 +00006149 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006150 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006151
6152 // Go through the clobbers.
6153 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006154 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006155
6156 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006157 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006158 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6159 S->isVolatile(), S->getNumOutputs(),
6160 S->getNumInputs(), Names.data(),
6161 Constraints, Exprs, AsmString.get(),
6162 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006163}
6164
Chad Rosier32503022012-06-11 20:47:18 +00006165template<typename Derived>
6166StmtResult
6167TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006168 ArrayRef<Token> AsmToks =
6169 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006170
John McCallf413f5e2013-05-03 00:10:13 +00006171 bool HadError = false, HadChange = false;
6172
6173 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6174 SmallVector<Expr*, 8> TransformedExprs;
6175 TransformedExprs.reserve(SrcExprs.size());
6176 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6177 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6178 if (!Result.isUsable()) {
6179 HadError = true;
6180 } else {
6181 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006182 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006183 }
6184 }
6185
6186 if (HadError) return StmtError();
6187 if (!HadChange && !getDerived().AlwaysRebuild())
6188 return Owned(S);
6189
Chad Rosierb6f46c12012-08-15 16:53:30 +00006190 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006191 AsmToks, S->getAsmString(),
6192 S->getNumOutputs(), S->getNumInputs(),
6193 S->getAllConstraints(), S->getClobbers(),
6194 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006195}
Douglas Gregorebe10102009-08-20 07:17:43 +00006196
6197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006198StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006199TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006200 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006201 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006202 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006203 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006204
Douglas Gregor96c79492010-04-23 22:50:49 +00006205 // Transform the @catch statements (if present).
6206 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006207 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006208 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006209 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006210 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006211 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006212 if (Catch.get() != S->getCatchStmt(I))
6213 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006214 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006215 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006216
Douglas Gregor306de2f2010-04-22 23:59:56 +00006217 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006218 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006219 if (S->getFinallyStmt()) {
6220 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6221 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006222 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006223 }
6224
6225 // If nothing changed, just retain this statement.
6226 if (!getDerived().AlwaysRebuild() &&
6227 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006228 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006229 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006230 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006231
Douglas Gregor306de2f2010-04-22 23:59:56 +00006232 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006233 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006234 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006235}
Mike Stump11289f42009-09-09 15:08:12 +00006236
Douglas Gregorebe10102009-08-20 07:17:43 +00006237template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006238StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006239TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006240 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006241 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006242 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006243 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006244 if (FromVar->getTypeSourceInfo()) {
6245 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6246 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006247 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006248 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006249
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006250 QualType T;
6251 if (TSInfo)
6252 T = TSInfo->getType();
6253 else {
6254 T = getDerived().TransformType(FromVar->getType());
6255 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006256 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006257 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006258
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006259 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6260 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006261 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006262 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006263
John McCalldadc5752010-08-24 06:29:42 +00006264 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006265 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006266 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006267
6268 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006269 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006270 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006271}
Mike Stump11289f42009-09-09 15:08:12 +00006272
Douglas Gregorebe10102009-08-20 07:17:43 +00006273template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006274StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006275TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006276 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006277 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006278 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006279 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006280
Douglas Gregor306de2f2010-04-22 23:59:56 +00006281 // If nothing changed, just retain this statement.
6282 if (!getDerived().AlwaysRebuild() &&
6283 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006284 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006285
6286 // Build a new statement.
6287 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006288 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006289}
Mike Stump11289f42009-09-09 15:08:12 +00006290
Douglas Gregorebe10102009-08-20 07:17:43 +00006291template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006292StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006293TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006294 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006295 if (S->getThrowExpr()) {
6296 Operand = getDerived().TransformExpr(S->getThrowExpr());
6297 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006298 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006299 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006300
Douglas Gregor2900c162010-04-22 21:44:01 +00006301 if (!getDerived().AlwaysRebuild() &&
6302 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006303 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006304
John McCallb268a282010-08-23 23:25:46 +00006305 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006306}
Mike Stump11289f42009-09-09 15:08:12 +00006307
Douglas Gregorebe10102009-08-20 07:17:43 +00006308template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006309StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006310TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006311 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006312 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006313 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006314 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006315 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006316 Object =
6317 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6318 Object.get());
6319 if (Object.isInvalid())
6320 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006321
Douglas Gregor6148de72010-04-22 22:01:21 +00006322 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006323 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006324 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006325 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006326
Douglas Gregor6148de72010-04-22 22:01:21 +00006327 // If nothing change, just retain the current statement.
6328 if (!getDerived().AlwaysRebuild() &&
6329 Object.get() == S->getSynchExpr() &&
6330 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006331 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006332
6333 // Build a new statement.
6334 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006335 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006336}
6337
6338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006339StmtResult
John McCall31168b02011-06-15 23:02:42 +00006340TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6341 ObjCAutoreleasePoolStmt *S) {
6342 // Transform the body.
6343 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6344 if (Body.isInvalid())
6345 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006346
John McCall31168b02011-06-15 23:02:42 +00006347 // If nothing changed, just retain this statement.
6348 if (!getDerived().AlwaysRebuild() &&
6349 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006350 return S;
John McCall31168b02011-06-15 23:02:42 +00006351
6352 // Build a new statement.
6353 return getDerived().RebuildObjCAutoreleasePoolStmt(
6354 S->getAtLoc(), Body.get());
6355}
6356
6357template<typename Derived>
6358StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006359TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006360 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006361 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006362 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006363 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006364 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006365
Douglas Gregorf68a5082010-04-22 23:10:45 +00006366 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006367 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006368 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006369 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006370
Douglas Gregorf68a5082010-04-22 23:10:45 +00006371 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006372 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006373 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006374 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006375
Douglas Gregorf68a5082010-04-22 23:10:45 +00006376 // If nothing changed, just retain this statement.
6377 if (!getDerived().AlwaysRebuild() &&
6378 Element.get() == S->getElement() &&
6379 Collection.get() == S->getCollection() &&
6380 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006381 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006382
Douglas Gregorf68a5082010-04-22 23:10:45 +00006383 // Build a new statement.
6384 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006385 Element.get(),
6386 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006387 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006388 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006389}
6390
David Majnemer5f7efef2013-10-15 09:50:08 +00006391template <typename Derived>
6392StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006393 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006394 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006395 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6396 TypeSourceInfo *T =
6397 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006398 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006399 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006400
David Majnemer5f7efef2013-10-15 09:50:08 +00006401 Var = getDerived().RebuildExceptionDecl(
6402 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6403 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006404 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006405 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006406 }
Mike Stump11289f42009-09-09 15:08:12 +00006407
Douglas Gregorebe10102009-08-20 07:17:43 +00006408 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006409 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006410 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006411 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006412
David Majnemer5f7efef2013-10-15 09:50:08 +00006413 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006414 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006415 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006416
David Majnemer5f7efef2013-10-15 09:50:08 +00006417 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006418}
Mike Stump11289f42009-09-09 15:08:12 +00006419
David Majnemer5f7efef2013-10-15 09:50:08 +00006420template <typename Derived>
6421StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006422 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006423 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006424 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006425 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006426
Douglas Gregorebe10102009-08-20 07:17:43 +00006427 // Transform the handlers.
6428 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006429 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006430 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006431 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006432 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006433 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006434
Douglas Gregorebe10102009-08-20 07:17:43 +00006435 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006436 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006437 }
Mike Stump11289f42009-09-09 15:08:12 +00006438
David Majnemer5f7efef2013-10-15 09:50:08 +00006439 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006440 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006441 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006442
John McCallb268a282010-08-23 23:25:46 +00006443 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006444 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006445}
Mike Stump11289f42009-09-09 15:08:12 +00006446
Richard Smith02e85f32011-04-14 22:09:26 +00006447template<typename Derived>
6448StmtResult
6449TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6450 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6451 if (Range.isInvalid())
6452 return StmtError();
6453
6454 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6455 if (BeginEnd.isInvalid())
6456 return StmtError();
6457
6458 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6459 if (Cond.isInvalid())
6460 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006461 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006462 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006463 if (Cond.isInvalid())
6464 return StmtError();
6465 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006466 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006467
6468 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6469 if (Inc.isInvalid())
6470 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006471 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006472 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006473
6474 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6475 if (LoopVar.isInvalid())
6476 return StmtError();
6477
6478 StmtResult NewStmt = S;
6479 if (getDerived().AlwaysRebuild() ||
6480 Range.get() != S->getRangeStmt() ||
6481 BeginEnd.get() != S->getBeginEndStmt() ||
6482 Cond.get() != S->getCond() ||
6483 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006484 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006485 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6486 S->getColonLoc(), Range.get(),
6487 BeginEnd.get(), Cond.get(),
6488 Inc.get(), LoopVar.get(),
6489 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006490 if (NewStmt.isInvalid())
6491 return StmtError();
6492 }
Richard Smith02e85f32011-04-14 22:09:26 +00006493
6494 StmtResult Body = getDerived().TransformStmt(S->getBody());
6495 if (Body.isInvalid())
6496 return StmtError();
6497
6498 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6499 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006500 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006501 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6502 S->getColonLoc(), Range.get(),
6503 BeginEnd.get(), Cond.get(),
6504 Inc.get(), LoopVar.get(),
6505 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006506 if (NewStmt.isInvalid())
6507 return StmtError();
6508 }
Richard Smith02e85f32011-04-14 22:09:26 +00006509
6510 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006511 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006512
6513 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6514}
6515
John Wiegley1c0675e2011-04-28 01:08:34 +00006516template<typename Derived>
6517StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006518TreeTransform<Derived>::TransformMSDependentExistsStmt(
6519 MSDependentExistsStmt *S) {
6520 // Transform the nested-name-specifier, if any.
6521 NestedNameSpecifierLoc QualifierLoc;
6522 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006523 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006524 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6525 if (!QualifierLoc)
6526 return StmtError();
6527 }
6528
6529 // Transform the declaration name.
6530 DeclarationNameInfo NameInfo = S->getNameInfo();
6531 if (NameInfo.getName()) {
6532 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6533 if (!NameInfo.getName())
6534 return StmtError();
6535 }
6536
6537 // Check whether anything changed.
6538 if (!getDerived().AlwaysRebuild() &&
6539 QualifierLoc == S->getQualifierLoc() &&
6540 NameInfo.getName() == S->getNameInfo().getName())
6541 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006542
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006543 // Determine whether this name exists, if we can.
6544 CXXScopeSpec SS;
6545 SS.Adopt(QualifierLoc);
6546 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006547 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006548 case Sema::IER_Exists:
6549 if (S->isIfExists())
6550 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006551
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006552 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6553
6554 case Sema::IER_DoesNotExist:
6555 if (S->isIfNotExists())
6556 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006557
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006558 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006559
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006560 case Sema::IER_Dependent:
6561 Dependent = true;
6562 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006563
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006564 case Sema::IER_Error:
6565 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006566 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006567
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006568 // We need to continue with the instantiation, so do so now.
6569 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6570 if (SubStmt.isInvalid())
6571 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006572
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006573 // If we have resolved the name, just transform to the substatement.
6574 if (!Dependent)
6575 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006576
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006577 // The name is still dependent, so build a dependent expression again.
6578 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6579 S->isIfExists(),
6580 QualifierLoc,
6581 NameInfo,
6582 SubStmt.get());
6583}
6584
6585template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006586ExprResult
6587TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6588 NestedNameSpecifierLoc QualifierLoc;
6589 if (E->getQualifierLoc()) {
6590 QualifierLoc
6591 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6592 if (!QualifierLoc)
6593 return ExprError();
6594 }
6595
6596 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6597 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6598 if (!PD)
6599 return ExprError();
6600
6601 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6602 if (Base.isInvalid())
6603 return ExprError();
6604
6605 return new (SemaRef.getASTContext())
6606 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6607 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6608 QualifierLoc, E->getMemberLoc());
6609}
6610
David Majnemerfad8f482013-10-15 09:33:02 +00006611template <typename Derived>
6612StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006613 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006614 if (TryBlock.isInvalid())
6615 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006616
6617 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006618 if (Handler.isInvalid())
6619 return StmtError();
6620
David Majnemerfad8f482013-10-15 09:33:02 +00006621 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6622 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006623 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006624
Warren Huntf6be4cb2014-07-25 20:52:51 +00006625 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6626 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006627}
6628
David Majnemerfad8f482013-10-15 09:33:02 +00006629template <typename Derived>
6630StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006631 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006632 if (Block.isInvalid())
6633 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006634
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006635 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006636}
6637
David Majnemerfad8f482013-10-15 09:33:02 +00006638template <typename Derived>
6639StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006640 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006641 if (FilterExpr.isInvalid())
6642 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006643
David Majnemer7e755502013-10-15 09:30:14 +00006644 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006645 if (Block.isInvalid())
6646 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006647
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006648 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6649 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006650}
6651
David Majnemerfad8f482013-10-15 09:33:02 +00006652template <typename Derived>
6653StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6654 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006655 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6656 else
6657 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6658}
6659
Nico Weber9b982072014-07-07 00:12:30 +00006660template<typename Derived>
6661StmtResult
6662TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6663 return S;
6664}
6665
Alexander Musman64d33f12014-06-04 07:53:32 +00006666//===----------------------------------------------------------------------===//
6667// OpenMP directive transformation
6668//===----------------------------------------------------------------------===//
6669template <typename Derived>
6670StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6671 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006672
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006673 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006674 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006675 ArrayRef<OMPClause *> Clauses = D->clauses();
6676 TClauses.reserve(Clauses.size());
6677 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6678 I != E; ++I) {
6679 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00006680 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006681 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00006682 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00006683 if (Clause)
6684 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006685 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006686 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006687 }
6688 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006689 StmtResult AssociatedStmt;
6690 if (D->hasAssociatedStmt()) {
6691 if (!D->getAssociatedStmt()) {
6692 return StmtError();
6693 }
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00006694 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
6695 /*CurScope=*/nullptr);
6696 StmtResult Body;
6697 {
6698 Sema::CompoundScopeRAII CompoundScope(getSema());
6699 Body = getDerived().TransformStmt(
6700 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
6701 }
6702 AssociatedStmt =
6703 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00006704 if (AssociatedStmt.isInvalid()) {
6705 return StmtError();
6706 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006707 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006708 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006709 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006710 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006711
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006712 // Transform directive name for 'omp critical' directive.
6713 DeclarationNameInfo DirName;
6714 if (D->getDirectiveKind() == OMPD_critical) {
6715 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6716 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6717 }
6718
Alexander Musman64d33f12014-06-04 07:53:32 +00006719 return getDerived().RebuildOMPExecutableDirective(
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006720 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
6721 D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006722}
6723
Alexander Musman64d33f12014-06-04 07:53:32 +00006724template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006725StmtResult
6726TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6727 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006728 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6729 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006730 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6731 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6732 return Res;
6733}
6734
Alexander Musman64d33f12014-06-04 07:53:32 +00006735template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006736StmtResult
6737TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6738 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006739 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6740 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006741 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6742 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006743 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006744}
6745
Alexey Bataevf29276e2014-06-18 04:14:57 +00006746template <typename Derived>
6747StmtResult
6748TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6749 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006750 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6751 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006752 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6753 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6754 return Res;
6755}
6756
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006757template <typename Derived>
6758StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00006759TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
6760 DeclarationNameInfo DirName;
6761 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
6762 D->getLocStart());
6763 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6764 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6765 return Res;
6766}
6767
6768template <typename Derived>
6769StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006770TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6771 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006772 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6773 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006774 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6775 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6776 return Res;
6777}
6778
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006779template <typename Derived>
6780StmtResult
6781TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6782 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006783 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6784 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006785 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6786 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6787 return Res;
6788}
6789
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006790template <typename Derived>
6791StmtResult
6792TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6793 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006794 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6795 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006796 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6797 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6798 return Res;
6799}
6800
Alexey Bataev4acb8592014-07-07 13:01:15 +00006801template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006802StmtResult
6803TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6804 DeclarationNameInfo DirName;
6805 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6806 D->getLocStart());
6807 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6808 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6809 return Res;
6810}
6811
6812template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006813StmtResult
6814TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6815 getDerived().getSema().StartOpenMPDSABlock(
6816 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
6817 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6818 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6819 return Res;
6820}
6821
6822template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00006823StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6824 OMPParallelForDirective *D) {
6825 DeclarationNameInfo DirName;
6826 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6827 nullptr, D->getLocStart());
6828 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6829 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6830 return Res;
6831}
6832
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006833template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00006834StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
6835 OMPParallelForSimdDirective *D) {
6836 DeclarationNameInfo DirName;
6837 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
6838 nullptr, D->getLocStart());
6839 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6840 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6841 return Res;
6842}
6843
6844template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006845StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6846 OMPParallelSectionsDirective *D) {
6847 DeclarationNameInfo DirName;
6848 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6849 nullptr, D->getLocStart());
6850 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6851 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6852 return Res;
6853}
6854
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00006855template <typename Derived>
6856StmtResult
6857TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6858 DeclarationNameInfo DirName;
6859 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6860 D->getLocStart());
6861 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6862 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6863 return Res;
6864}
6865
Alexey Bataev68446b72014-07-18 07:47:19 +00006866template <typename Derived>
6867StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
6868 OMPTaskyieldDirective *D) {
6869 DeclarationNameInfo DirName;
6870 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
6871 D->getLocStart());
6872 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6873 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6874 return Res;
6875}
6876
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00006877template <typename Derived>
6878StmtResult
6879TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
6880 DeclarationNameInfo DirName;
6881 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
6882 D->getLocStart());
6883 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6884 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6885 return Res;
6886}
6887
Alexey Bataev2df347a2014-07-18 10:17:07 +00006888template <typename Derived>
6889StmtResult
6890TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
6891 DeclarationNameInfo DirName;
6892 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
6893 D->getLocStart());
6894 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6895 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6896 return Res;
6897}
6898
Alexey Bataev6125da92014-07-21 11:26:11 +00006899template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00006900StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
6901 OMPTaskgroupDirective *D) {
6902 DeclarationNameInfo DirName;
6903 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
6904 D->getLocStart());
6905 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6906 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6907 return Res;
6908}
6909
6910template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00006911StmtResult
6912TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
6913 DeclarationNameInfo DirName;
6914 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
6915 D->getLocStart());
6916 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6917 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6918 return Res;
6919}
6920
Alexey Bataev9fb6e642014-07-22 06:45:04 +00006921template <typename Derived>
6922StmtResult
6923TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
6924 DeclarationNameInfo DirName;
6925 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
6926 D->getLocStart());
6927 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6928 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6929 return Res;
6930}
6931
Alexey Bataev0162e452014-07-22 10:10:35 +00006932template <typename Derived>
6933StmtResult
6934TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
6935 DeclarationNameInfo DirName;
6936 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
6937 D->getLocStart());
6938 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6939 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6940 return Res;
6941}
6942
Alexey Bataev0bd520b2014-09-19 08:19:49 +00006943template <typename Derived>
6944StmtResult
6945TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
6946 DeclarationNameInfo DirName;
6947 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
6948 D->getLocStart());
6949 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6950 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6951 return Res;
6952}
6953
Alexey Bataev13314bf2014-10-09 04:18:56 +00006954template <typename Derived>
6955StmtResult
6956TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
6957 DeclarationNameInfo DirName;
6958 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
6959 D->getLocStart());
6960 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6961 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6962 return Res;
6963}
6964
Alexander Musman64d33f12014-06-04 07:53:32 +00006965//===----------------------------------------------------------------------===//
6966// OpenMP clause transformation
6967//===----------------------------------------------------------------------===//
6968template <typename Derived>
6969OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006970 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6971 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006972 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006973 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006974 C->getLParenLoc(), C->getLocEnd());
6975}
6976
Alexander Musman64d33f12014-06-04 07:53:32 +00006977template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00006978OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
6979 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6980 if (Cond.isInvalid())
6981 return nullptr;
6982 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
6983 C->getLParenLoc(), C->getLocEnd());
6984}
6985
6986template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006987OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006988TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6989 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6990 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006991 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006992 return getDerived().RebuildOMPNumThreadsClause(
6993 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006994}
6995
Alexey Bataev62c87d22014-03-21 04:51:18 +00006996template <typename Derived>
6997OMPClause *
6998TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6999 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7000 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007001 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007002 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007003 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007004}
7005
Alexander Musman8bd31e62014-05-27 15:12:19 +00007006template <typename Derived>
7007OMPClause *
7008TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7009 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7010 if (E.isInvalid())
7011 return 0;
7012 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007013 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007014}
7015
Alexander Musman64d33f12014-06-04 07:53:32 +00007016template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007017OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007018TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007019 return getDerived().RebuildOMPDefaultClause(
7020 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7021 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007022}
7023
Alexander Musman64d33f12014-06-04 07:53:32 +00007024template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007025OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007026TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007027 return getDerived().RebuildOMPProcBindClause(
7028 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7029 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007030}
7031
Alexander Musman64d33f12014-06-04 07:53:32 +00007032template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007033OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007034TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7035 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7036 if (E.isInvalid())
7037 return nullptr;
7038 return getDerived().RebuildOMPScheduleClause(
7039 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7040 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7041}
7042
7043template <typename Derived>
7044OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007045TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
7046 // No need to rebuild this clause, no template-dependent parameters.
7047 return C;
7048}
7049
7050template <typename Derived>
7051OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007052TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7053 // No need to rebuild this clause, no template-dependent parameters.
7054 return C;
7055}
7056
7057template <typename Derived>
7058OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007059TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7060 // No need to rebuild this clause, no template-dependent parameters.
7061 return C;
7062}
7063
7064template <typename Derived>
7065OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007066TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7067 // No need to rebuild this clause, no template-dependent parameters.
7068 return C;
7069}
7070
7071template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007072OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7073 // No need to rebuild this clause, no template-dependent parameters.
7074 return C;
7075}
7076
7077template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007078OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7079 // No need to rebuild this clause, no template-dependent parameters.
7080 return C;
7081}
7082
7083template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007084OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007085TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7086 // No need to rebuild this clause, no template-dependent parameters.
7087 return C;
7088}
7089
7090template <typename Derived>
7091OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007092TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7093 // No need to rebuild this clause, no template-dependent parameters.
7094 return C;
7095}
7096
7097template <typename Derived>
7098OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007099TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7100 // No need to rebuild this clause, no template-dependent parameters.
7101 return C;
7102}
7103
7104template <typename Derived>
7105OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007106TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007107 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007108 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007109 for (auto *VE : C->varlists()) {
7110 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007111 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007112 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007113 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007114 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007115 return getDerived().RebuildOMPPrivateClause(
7116 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007117}
7118
Alexander Musman64d33f12014-06-04 07:53:32 +00007119template <typename Derived>
7120OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7121 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007122 llvm::SmallVector<Expr *, 16> Vars;
7123 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007124 for (auto *VE : C->varlists()) {
7125 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007126 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007127 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007128 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007129 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007130 return getDerived().RebuildOMPFirstprivateClause(
7131 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007132}
7133
Alexander Musman64d33f12014-06-04 07:53:32 +00007134template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007135OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007136TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7137 llvm::SmallVector<Expr *, 16> Vars;
7138 Vars.reserve(C->varlist_size());
7139 for (auto *VE : C->varlists()) {
7140 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7141 if (EVar.isInvalid())
7142 return nullptr;
7143 Vars.push_back(EVar.get());
7144 }
7145 return getDerived().RebuildOMPLastprivateClause(
7146 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7147}
7148
7149template <typename Derived>
7150OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007151TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7152 llvm::SmallVector<Expr *, 16> Vars;
7153 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007154 for (auto *VE : C->varlists()) {
7155 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007156 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007157 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007158 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007159 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007160 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7161 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007162}
7163
Alexander Musman64d33f12014-06-04 07:53:32 +00007164template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007165OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007166TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7167 llvm::SmallVector<Expr *, 16> Vars;
7168 Vars.reserve(C->varlist_size());
7169 for (auto *VE : C->varlists()) {
7170 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7171 if (EVar.isInvalid())
7172 return nullptr;
7173 Vars.push_back(EVar.get());
7174 }
7175 CXXScopeSpec ReductionIdScopeSpec;
7176 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7177
7178 DeclarationNameInfo NameInfo = C->getNameInfo();
7179 if (NameInfo.getName()) {
7180 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7181 if (!NameInfo.getName())
7182 return nullptr;
7183 }
7184 return getDerived().RebuildOMPReductionClause(
7185 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7186 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7187}
7188
7189template <typename Derived>
7190OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007191TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7192 llvm::SmallVector<Expr *, 16> Vars;
7193 Vars.reserve(C->varlist_size());
7194 for (auto *VE : C->varlists()) {
7195 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7196 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007197 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007198 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007199 }
7200 ExprResult Step = getDerived().TransformExpr(C->getStep());
7201 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007202 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007203 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
7204 C->getLParenLoc(),
7205 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007206}
7207
Alexander Musman64d33f12014-06-04 07:53:32 +00007208template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007209OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007210TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7211 llvm::SmallVector<Expr *, 16> Vars;
7212 Vars.reserve(C->varlist_size());
7213 for (auto *VE : C->varlists()) {
7214 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7215 if (EVar.isInvalid())
7216 return nullptr;
7217 Vars.push_back(EVar.get());
7218 }
7219 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7220 if (Alignment.isInvalid())
7221 return nullptr;
7222 return getDerived().RebuildOMPAlignedClause(
7223 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7224 C->getColonLoc(), C->getLocEnd());
7225}
7226
Alexander Musman64d33f12014-06-04 07:53:32 +00007227template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007228OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007229TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7230 llvm::SmallVector<Expr *, 16> Vars;
7231 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007232 for (auto *VE : C->varlists()) {
7233 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007234 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007235 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007236 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007237 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007238 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7239 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007240}
7241
Alexey Bataevbae9a792014-06-27 10:37:06 +00007242template <typename Derived>
7243OMPClause *
7244TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7245 llvm::SmallVector<Expr *, 16> Vars;
7246 Vars.reserve(C->varlist_size());
7247 for (auto *VE : C->varlists()) {
7248 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7249 if (EVar.isInvalid())
7250 return nullptr;
7251 Vars.push_back(EVar.get());
7252 }
7253 return getDerived().RebuildOMPCopyprivateClause(
7254 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7255}
7256
Alexey Bataev6125da92014-07-21 11:26:11 +00007257template <typename Derived>
7258OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7259 llvm::SmallVector<Expr *, 16> Vars;
7260 Vars.reserve(C->varlist_size());
7261 for (auto *VE : C->varlists()) {
7262 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7263 if (EVar.isInvalid())
7264 return nullptr;
7265 Vars.push_back(EVar.get());
7266 }
7267 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7268 C->getLParenLoc(), C->getLocEnd());
7269}
7270
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007271template <typename Derived>
7272OMPClause *
7273TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7274 llvm::SmallVector<Expr *, 16> Vars;
7275 Vars.reserve(C->varlist_size());
7276 for (auto *VE : C->varlists()) {
7277 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7278 if (EVar.isInvalid())
7279 return nullptr;
7280 Vars.push_back(EVar.get());
7281 }
7282 return getDerived().RebuildOMPDependClause(
7283 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7284 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7285}
7286
Douglas Gregorebe10102009-08-20 07:17:43 +00007287//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007288// Expression transformation
7289//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007290template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007291ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007292TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007293 if (!E->isTypeDependent())
7294 return E;
7295
7296 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7297 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007298}
Mike Stump11289f42009-09-09 15:08:12 +00007299
7300template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007301ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007302TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007303 NestedNameSpecifierLoc QualifierLoc;
7304 if (E->getQualifierLoc()) {
7305 QualifierLoc
7306 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7307 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007308 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007309 }
John McCallce546572009-12-08 09:08:17 +00007310
7311 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007312 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7313 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007314 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007315 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007316
John McCall815039a2010-08-17 21:27:17 +00007317 DeclarationNameInfo NameInfo = E->getNameInfo();
7318 if (NameInfo.getName()) {
7319 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7320 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007321 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007322 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007323
7324 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007325 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007326 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007327 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007328 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007329
7330 // Mark it referenced in the new context regardless.
7331 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007332 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007333
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007334 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007335 }
John McCallce546572009-12-08 09:08:17 +00007336
Craig Topperc3ec1492014-05-26 06:22:03 +00007337 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007338 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007339 TemplateArgs = &TransArgs;
7340 TransArgs.setLAngleLoc(E->getLAngleLoc());
7341 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007342 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7343 E->getNumTemplateArgs(),
7344 TransArgs))
7345 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007346 }
7347
Chad Rosier1dcde962012-08-08 18:46:20 +00007348 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007349 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007350}
Mike Stump11289f42009-09-09 15:08:12 +00007351
Douglas Gregora16548e2009-08-11 05:31:07 +00007352template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007353ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007354TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007355 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007356}
Mike Stump11289f42009-09-09 15:08:12 +00007357
Douglas Gregora16548e2009-08-11 05:31:07 +00007358template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007359ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007360TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007361 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007362}
Mike Stump11289f42009-09-09 15:08:12 +00007363
Douglas Gregora16548e2009-08-11 05:31:07 +00007364template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007365ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007366TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007367 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007368}
Mike Stump11289f42009-09-09 15:08:12 +00007369
Douglas Gregora16548e2009-08-11 05:31:07 +00007370template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007371ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007372TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007373 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007374}
Mike Stump11289f42009-09-09 15:08:12 +00007375
Douglas Gregora16548e2009-08-11 05:31:07 +00007376template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007377ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007378TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007379 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007380}
7381
7382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007383ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007384TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007385 if (FunctionDecl *FD = E->getDirectCallee())
7386 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007387 return SemaRef.MaybeBindToTemporary(E);
7388}
7389
7390template<typename Derived>
7391ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007392TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7393 ExprResult ControllingExpr =
7394 getDerived().TransformExpr(E->getControllingExpr());
7395 if (ControllingExpr.isInvalid())
7396 return ExprError();
7397
Chris Lattner01cf8db2011-07-20 06:58:45 +00007398 SmallVector<Expr *, 4> AssocExprs;
7399 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007400 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7401 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7402 if (TS) {
7403 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7404 if (!AssocType)
7405 return ExprError();
7406 AssocTypes.push_back(AssocType);
7407 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007408 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007409 }
7410
7411 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7412 if (AssocExpr.isInvalid())
7413 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007414 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007415 }
7416
7417 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7418 E->getDefaultLoc(),
7419 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007420 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007421 AssocTypes,
7422 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007423}
7424
7425template<typename Derived>
7426ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007427TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007428 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007429 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007430 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007431
Douglas Gregora16548e2009-08-11 05:31:07 +00007432 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007433 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007434
John McCallb268a282010-08-23 23:25:46 +00007435 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007436 E->getRParen());
7437}
7438
Richard Smithdb2630f2012-10-21 03:28:35 +00007439/// \brief The operand of a unary address-of operator has special rules: it's
7440/// allowed to refer to a non-static member of a class even if there's no 'this'
7441/// object available.
7442template<typename Derived>
7443ExprResult
7444TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7445 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007446 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007447 else
7448 return getDerived().TransformExpr(E);
7449}
7450
Mike Stump11289f42009-09-09 15:08:12 +00007451template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007452ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007453TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007454 ExprResult SubExpr;
7455 if (E->getOpcode() == UO_AddrOf)
7456 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7457 else
7458 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007459 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007460 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007461
Douglas Gregora16548e2009-08-11 05:31:07 +00007462 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007463 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007464
Douglas Gregora16548e2009-08-11 05:31:07 +00007465 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7466 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007467 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007468}
Mike Stump11289f42009-09-09 15:08:12 +00007469
Douglas Gregora16548e2009-08-11 05:31:07 +00007470template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007471ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007472TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7473 // Transform the type.
7474 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7475 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007476 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007477
Douglas Gregor882211c2010-04-28 22:16:22 +00007478 // Transform all of the components into components similar to what the
7479 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007480 // FIXME: It would be slightly more efficient in the non-dependent case to
7481 // just map FieldDecls, rather than requiring the rebuilder to look for
7482 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007483 // template code that we don't care.
7484 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007485 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007486 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007487 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007488 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7489 const Node &ON = E->getComponent(I);
7490 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007491 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007492 Comp.LocStart = ON.getSourceRange().getBegin();
7493 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007494 switch (ON.getKind()) {
7495 case Node::Array: {
7496 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007497 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007498 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007499 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007500
Douglas Gregor882211c2010-04-28 22:16:22 +00007501 ExprChanged = ExprChanged || Index.get() != FromIndex;
7502 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007503 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007504 break;
7505 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007506
Douglas Gregor882211c2010-04-28 22:16:22 +00007507 case Node::Field:
7508 case Node::Identifier:
7509 Comp.isBrackets = false;
7510 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007511 if (!Comp.U.IdentInfo)
7512 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007513
Douglas Gregor882211c2010-04-28 22:16:22 +00007514 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007515
Douglas Gregord1702062010-04-29 00:18:15 +00007516 case Node::Base:
7517 // Will be recomputed during the rebuild.
7518 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007519 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007520
Douglas Gregor882211c2010-04-28 22:16:22 +00007521 Components.push_back(Comp);
7522 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007523
Douglas Gregor882211c2010-04-28 22:16:22 +00007524 // If nothing changed, retain the existing expression.
7525 if (!getDerived().AlwaysRebuild() &&
7526 Type == E->getTypeSourceInfo() &&
7527 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007528 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007529
Douglas Gregor882211c2010-04-28 22:16:22 +00007530 // Build a new offsetof expression.
7531 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7532 Components.data(), Components.size(),
7533 E->getRParenLoc());
7534}
7535
7536template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007537ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007538TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7539 assert(getDerived().AlreadyTransformed(E->getType()) &&
7540 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007541 return E;
John McCall8d69a212010-11-15 23:31:06 +00007542}
7543
7544template<typename Derived>
7545ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00007546TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
7547 return E;
7548}
7549
7550template<typename Derived>
7551ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007552TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007553 // Rebuild the syntactic form. The original syntactic form has
7554 // opaque-value expressions in it, so strip those away and rebuild
7555 // the result. This is a really awful way of doing this, but the
7556 // better solution (rebuilding the semantic expressions and
7557 // rebinding OVEs as necessary) doesn't work; we'd need
7558 // TreeTransform to not strip away implicit conversions.
7559 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7560 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007561 if (result.isInvalid()) return ExprError();
7562
7563 // If that gives us a pseudo-object result back, the pseudo-object
7564 // expression must have been an lvalue-to-rvalue conversion which we
7565 // should reapply.
7566 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007567 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007568
7569 return result;
7570}
7571
7572template<typename Derived>
7573ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007574TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7575 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007576 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007577 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007578
John McCallbcd03502009-12-07 02:54:59 +00007579 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007580 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007581 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007582
John McCall4c98fd82009-11-04 07:28:41 +00007583 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007584 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007585
Peter Collingbournee190dee2011-03-11 19:24:49 +00007586 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7587 E->getKind(),
7588 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007589 }
Mike Stump11289f42009-09-09 15:08:12 +00007590
Eli Friedmane4f22df2012-02-29 04:03:55 +00007591 // C++0x [expr.sizeof]p1:
7592 // The operand is either an expression, which is an unevaluated operand
7593 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007594 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7595 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007596
Reid Kleckner32506ed2014-06-12 23:03:48 +00007597 // Try to recover if we have something like sizeof(T::X) where X is a type.
7598 // Notably, there must be *exactly* one set of parens if X is a type.
7599 TypeSourceInfo *RecoveryTSI = nullptr;
7600 ExprResult SubExpr;
7601 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7602 if (auto *DRE =
7603 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7604 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7605 PE, DRE, false, &RecoveryTSI);
7606 else
7607 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7608
7609 if (RecoveryTSI) {
7610 return getDerived().RebuildUnaryExprOrTypeTrait(
7611 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7612 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007613 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007614
Eli Friedmane4f22df2012-02-29 04:03:55 +00007615 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007616 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007617
Peter Collingbournee190dee2011-03-11 19:24:49 +00007618 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7619 E->getOperatorLoc(),
7620 E->getKind(),
7621 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007622}
Mike Stump11289f42009-09-09 15:08:12 +00007623
Douglas Gregora16548e2009-08-11 05:31:07 +00007624template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007625ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007626TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007627 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007628 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007629 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007630
John McCalldadc5752010-08-24 06:29:42 +00007631 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007632 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007633 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007634
7635
Douglas Gregora16548e2009-08-11 05:31:07 +00007636 if (!getDerived().AlwaysRebuild() &&
7637 LHS.get() == E->getLHS() &&
7638 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007639 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007640
John McCallb268a282010-08-23 23:25:46 +00007641 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007642 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007643 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007644 E->getRBracketLoc());
7645}
Mike Stump11289f42009-09-09 15:08:12 +00007646
7647template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007648ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007649TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007650 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007651 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007652 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007653 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007654
7655 // Transform arguments.
7656 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007657 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007658 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007659 &ArgChanged))
7660 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007661
Douglas Gregora16548e2009-08-11 05:31:07 +00007662 if (!getDerived().AlwaysRebuild() &&
7663 Callee.get() == E->getCallee() &&
7664 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007665 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007666
Douglas Gregora16548e2009-08-11 05:31:07 +00007667 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007668 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007669 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007670 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007671 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007672 E->getRParenLoc());
7673}
Mike Stump11289f42009-09-09 15:08:12 +00007674
7675template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007676ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007677TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007678 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007679 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007680 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007681
Douglas Gregorea972d32011-02-28 21:54:11 +00007682 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007683 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007684 QualifierLoc
7685 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007686
Douglas Gregorea972d32011-02-28 21:54:11 +00007687 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007688 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007689 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007690 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007691
Eli Friedman2cfcef62009-12-04 06:40:45 +00007692 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007693 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7694 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007695 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007696 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007697
John McCall16df1e52010-03-30 21:47:33 +00007698 NamedDecl *FoundDecl = E->getFoundDecl();
7699 if (FoundDecl == E->getMemberDecl()) {
7700 FoundDecl = Member;
7701 } else {
7702 FoundDecl = cast_or_null<NamedDecl>(
7703 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7704 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007705 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007706 }
7707
Douglas Gregora16548e2009-08-11 05:31:07 +00007708 if (!getDerived().AlwaysRebuild() &&
7709 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007710 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007711 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007712 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007713 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007714
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007715 // Mark it referenced in the new context regardless.
7716 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007717 SemaRef.MarkMemberReferenced(E);
7718
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007719 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007720 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007721
John McCall6b51f282009-11-23 01:53:49 +00007722 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007723 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007724 TransArgs.setLAngleLoc(E->getLAngleLoc());
7725 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007726 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7727 E->getNumTemplateArgs(),
7728 TransArgs))
7729 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007730 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007731
Douglas Gregora16548e2009-08-11 05:31:07 +00007732 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007733 SourceLocation FakeOperatorLoc =
7734 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007735
John McCall38836f02010-01-15 08:34:02 +00007736 // FIXME: to do this check properly, we will need to preserve the
7737 // first-qualifier-in-scope here, just in case we had a dependent
7738 // base (and therefore couldn't do the check) and a
7739 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007740 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007741
John McCallb268a282010-08-23 23:25:46 +00007742 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007743 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007744 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007745 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007746 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007747 Member,
John McCall16df1e52010-03-30 21:47:33 +00007748 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007749 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007750 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007751 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007752}
Mike Stump11289f42009-09-09 15:08:12 +00007753
Douglas Gregora16548e2009-08-11 05:31:07 +00007754template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007755ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007756TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007757 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007758 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007759 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007760
John McCalldadc5752010-08-24 06:29:42 +00007761 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007762 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007763 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007764
Douglas Gregora16548e2009-08-11 05:31:07 +00007765 if (!getDerived().AlwaysRebuild() &&
7766 LHS.get() == E->getLHS() &&
7767 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007768 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007769
Lang Hames5de91cc2012-10-02 04:45:10 +00007770 Sema::FPContractStateRAII FPContractState(getSema());
7771 getSema().FPFeatures.fp_contract = E->isFPContractable();
7772
Douglas Gregora16548e2009-08-11 05:31:07 +00007773 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007774 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007775}
7776
Mike Stump11289f42009-09-09 15:08:12 +00007777template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007778ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007779TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007780 CompoundAssignOperator *E) {
7781 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007782}
Mike Stump11289f42009-09-09 15:08:12 +00007783
Douglas Gregora16548e2009-08-11 05:31:07 +00007784template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007785ExprResult TreeTransform<Derived>::
7786TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7787 // Just rebuild the common and RHS expressions and see whether we
7788 // get any changes.
7789
7790 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7791 if (commonExpr.isInvalid())
7792 return ExprError();
7793
7794 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7795 if (rhs.isInvalid())
7796 return ExprError();
7797
7798 if (!getDerived().AlwaysRebuild() &&
7799 commonExpr.get() == e->getCommon() &&
7800 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007801 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007802
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007803 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007804 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007805 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007806 e->getColonLoc(),
7807 rhs.get());
7808}
7809
7810template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007811ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007812TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007813 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007814 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007815 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007816
John McCalldadc5752010-08-24 06:29:42 +00007817 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007818 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007819 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007820
John McCalldadc5752010-08-24 06:29:42 +00007821 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007822 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007823 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007824
Douglas Gregora16548e2009-08-11 05:31:07 +00007825 if (!getDerived().AlwaysRebuild() &&
7826 Cond.get() == E->getCond() &&
7827 LHS.get() == E->getLHS() &&
7828 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007829 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007830
John McCallb268a282010-08-23 23:25:46 +00007831 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007832 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007833 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007834 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007835 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007836}
Mike Stump11289f42009-09-09 15:08:12 +00007837
7838template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007839ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007840TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007841 // Implicit casts are eliminated during transformation, since they
7842 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007843 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007844}
Mike Stump11289f42009-09-09 15:08:12 +00007845
Douglas Gregora16548e2009-08-11 05:31:07 +00007846template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007847ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007848TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007849 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7850 if (!Type)
7851 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007852
John McCalldadc5752010-08-24 06:29:42 +00007853 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007854 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007855 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007856 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007857
Douglas Gregora16548e2009-08-11 05:31:07 +00007858 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007859 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007860 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007861 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007862
John McCall97513962010-01-15 18:39:57 +00007863 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007864 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007865 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007866 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007867}
Mike Stump11289f42009-09-09 15:08:12 +00007868
Douglas Gregora16548e2009-08-11 05:31:07 +00007869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007870ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007871TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007872 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7873 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7874 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007875 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007876
John McCalldadc5752010-08-24 06:29:42 +00007877 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007878 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007879 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007880
Douglas Gregora16548e2009-08-11 05:31:07 +00007881 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007882 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007883 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007884 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007885
John McCall5d7aa7f2010-01-19 22:33:45 +00007886 // Note: the expression type doesn't necessarily match the
7887 // type-as-written, but that's okay, because it should always be
7888 // derivable from the initializer.
7889
John McCalle15bbff2010-01-18 19:35:47 +00007890 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007891 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007892 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007893}
Mike Stump11289f42009-09-09 15:08:12 +00007894
Douglas Gregora16548e2009-08-11 05:31:07 +00007895template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007896ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007897TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007898 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007899 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007900 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007901
Douglas Gregora16548e2009-08-11 05:31:07 +00007902 if (!getDerived().AlwaysRebuild() &&
7903 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007904 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007905
Douglas Gregora16548e2009-08-11 05:31:07 +00007906 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007907 SourceLocation FakeOperatorLoc =
7908 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007909 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007910 E->getAccessorLoc(),
7911 E->getAccessor());
7912}
Mike Stump11289f42009-09-09 15:08:12 +00007913
Douglas Gregora16548e2009-08-11 05:31:07 +00007914template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007915ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007916TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00007917 if (InitListExpr *Syntactic = E->getSyntacticForm())
7918 E = Syntactic;
7919
Douglas Gregora16548e2009-08-11 05:31:07 +00007920 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007921
Benjamin Kramerf0623432012-08-23 22:51:59 +00007922 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007923 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007924 Inits, &InitChanged))
7925 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007926
Richard Smith520449d2015-02-05 06:15:50 +00007927 if (!getDerived().AlwaysRebuild() && !InitChanged) {
7928 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
7929 // in some cases. We can't reuse it in general, because the syntactic and
7930 // semantic forms are linked, and we can't know that semantic form will
7931 // match even if the syntactic form does.
7932 }
Mike Stump11289f42009-09-09 15:08:12 +00007933
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007934 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007935 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007936}
Mike Stump11289f42009-09-09 15:08:12 +00007937
Douglas Gregora16548e2009-08-11 05:31:07 +00007938template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007939ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007940TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007941 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007942
Douglas Gregorebe10102009-08-20 07:17:43 +00007943 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007944 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007945 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007946 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007947
Douglas Gregorebe10102009-08-20 07:17:43 +00007948 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007949 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007950 bool ExprChanged = false;
7951 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7952 DEnd = E->designators_end();
7953 D != DEnd; ++D) {
7954 if (D->isFieldDesignator()) {
7955 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7956 D->getDotLoc(),
7957 D->getFieldLoc()));
7958 continue;
7959 }
Mike Stump11289f42009-09-09 15:08:12 +00007960
Douglas Gregora16548e2009-08-11 05:31:07 +00007961 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007962 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007963 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007964 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007965
7966 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007967 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007968
Douglas Gregora16548e2009-08-11 05:31:07 +00007969 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007970 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007971 continue;
7972 }
Mike Stump11289f42009-09-09 15:08:12 +00007973
Douglas Gregora16548e2009-08-11 05:31:07 +00007974 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007975 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007976 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7977 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007978 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007979
John McCalldadc5752010-08-24 06:29:42 +00007980 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007981 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007982 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007983
7984 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007985 End.get(),
7986 D->getLBracketLoc(),
7987 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007988
Douglas Gregora16548e2009-08-11 05:31:07 +00007989 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7990 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007991
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007992 ArrayExprs.push_back(Start.get());
7993 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007994 }
Mike Stump11289f42009-09-09 15:08:12 +00007995
Douglas Gregora16548e2009-08-11 05:31:07 +00007996 if (!getDerived().AlwaysRebuild() &&
7997 Init.get() == E->getInit() &&
7998 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007999 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008000
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008001 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008002 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008003 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008004}
Mike Stump11289f42009-09-09 15:08:12 +00008005
Yunzhong Gaocb779302015-06-10 00:27:52 +00008006// Seems that if TransformInitListExpr() only works on the syntactic form of an
8007// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8008template<typename Derived>
8009ExprResult
8010TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8011 DesignatedInitUpdateExpr *E) {
8012 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8013 "initializer");
8014 return ExprError();
8015}
8016
8017template<typename Derived>
8018ExprResult
8019TreeTransform<Derived>::TransformNoInitExpr(
8020 NoInitExpr *E) {
8021 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8022 return ExprError();
8023}
8024
Douglas Gregora16548e2009-08-11 05:31:07 +00008025template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008026ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008027TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008028 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008029 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008030
Douglas Gregor3da3c062009-10-28 00:29:27 +00008031 // FIXME: Will we ever have proper type location here? Will we actually
8032 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008033 QualType T = getDerived().TransformType(E->getType());
8034 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008035 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008036
Douglas Gregora16548e2009-08-11 05:31:07 +00008037 if (!getDerived().AlwaysRebuild() &&
8038 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008039 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008040
Douglas Gregora16548e2009-08-11 05:31:07 +00008041 return getDerived().RebuildImplicitValueInitExpr(T);
8042}
Mike Stump11289f42009-09-09 15:08:12 +00008043
Douglas Gregora16548e2009-08-11 05:31:07 +00008044template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008045ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008046TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008047 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8048 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008049 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008050
John McCalldadc5752010-08-24 06:29:42 +00008051 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008052 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008053 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008054
Douglas Gregora16548e2009-08-11 05:31:07 +00008055 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008056 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008057 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008058 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008059
John McCallb268a282010-08-23 23:25:46 +00008060 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008061 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008062}
8063
8064template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008065ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008066TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008067 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008068 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008069 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8070 &ArgumentChanged))
8071 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008072
Douglas Gregora16548e2009-08-11 05:31:07 +00008073 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008074 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008075 E->getRParenLoc());
8076}
Mike Stump11289f42009-09-09 15:08:12 +00008077
Douglas Gregora16548e2009-08-11 05:31:07 +00008078/// \brief Transform an address-of-label expression.
8079///
8080/// By default, the transformation of an address-of-label expression always
8081/// rebuilds the expression, so that the label identifier can be resolved to
8082/// the corresponding label statement by semantic analysis.
8083template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008084ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008085TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008086 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8087 E->getLabel());
8088 if (!LD)
8089 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008090
Douglas Gregora16548e2009-08-11 05:31:07 +00008091 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008092 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008093}
Mike Stump11289f42009-09-09 15:08:12 +00008094
8095template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008096ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008097TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008098 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008099 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008100 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008101 if (SubStmt.isInvalid()) {
8102 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008103 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008104 }
Mike Stump11289f42009-09-09 15:08:12 +00008105
Douglas Gregora16548e2009-08-11 05:31:07 +00008106 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008107 SubStmt.get() == E->getSubStmt()) {
8108 // Calling this an 'error' is unintuitive, but it does the right thing.
8109 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008110 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008111 }
Mike Stump11289f42009-09-09 15:08:12 +00008112
8113 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008114 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008115 E->getRParenLoc());
8116}
Mike Stump11289f42009-09-09 15:08:12 +00008117
Douglas Gregora16548e2009-08-11 05:31:07 +00008118template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008119ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008120TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008121 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008122 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008123 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008124
John McCalldadc5752010-08-24 06:29:42 +00008125 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008126 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008127 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008128
John McCalldadc5752010-08-24 06:29:42 +00008129 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008130 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008131 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008132
Douglas Gregora16548e2009-08-11 05:31:07 +00008133 if (!getDerived().AlwaysRebuild() &&
8134 Cond.get() == E->getCond() &&
8135 LHS.get() == E->getLHS() &&
8136 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008137 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008138
Douglas Gregora16548e2009-08-11 05:31:07 +00008139 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008140 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008141 E->getRParenLoc());
8142}
Mike Stump11289f42009-09-09 15:08:12 +00008143
Douglas Gregora16548e2009-08-11 05:31:07 +00008144template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008145ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008146TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008147 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008148}
8149
8150template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008151ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008152TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008153 switch (E->getOperator()) {
8154 case OO_New:
8155 case OO_Delete:
8156 case OO_Array_New:
8157 case OO_Array_Delete:
8158 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008159
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008160 case OO_Call: {
8161 // This is a call to an object's operator().
8162 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8163
8164 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008165 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008166 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008167 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008168
8169 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008170 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8171 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008172
8173 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008174 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008175 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008176 Args))
8177 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008178
John McCallb268a282010-08-23 23:25:46 +00008179 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008180 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008181 E->getLocEnd());
8182 }
8183
8184#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8185 case OO_##Name:
8186#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8187#include "clang/Basic/OperatorKinds.def"
8188 case OO_Subscript:
8189 // Handled below.
8190 break;
8191
8192 case OO_Conditional:
8193 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008194
8195 case OO_None:
8196 case NUM_OVERLOADED_OPERATORS:
8197 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008198 }
8199
John McCalldadc5752010-08-24 06:29:42 +00008200 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008201 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008202 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008203
Richard Smithdb2630f2012-10-21 03:28:35 +00008204 ExprResult First;
8205 if (E->getOperator() == OO_Amp)
8206 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8207 else
8208 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008209 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008210 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008211
John McCalldadc5752010-08-24 06:29:42 +00008212 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008213 if (E->getNumArgs() == 2) {
8214 Second = getDerived().TransformExpr(E->getArg(1));
8215 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008216 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008217 }
Mike Stump11289f42009-09-09 15:08:12 +00008218
Douglas Gregora16548e2009-08-11 05:31:07 +00008219 if (!getDerived().AlwaysRebuild() &&
8220 Callee.get() == E->getCallee() &&
8221 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008222 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008223 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008224
Lang Hames5de91cc2012-10-02 04:45:10 +00008225 Sema::FPContractStateRAII FPContractState(getSema());
8226 getSema().FPFeatures.fp_contract = E->isFPContractable();
8227
Douglas Gregora16548e2009-08-11 05:31:07 +00008228 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8229 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008230 Callee.get(),
8231 First.get(),
8232 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008233}
Mike Stump11289f42009-09-09 15:08:12 +00008234
Douglas Gregora16548e2009-08-11 05:31:07 +00008235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008236ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008237TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8238 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008239}
Mike Stump11289f42009-09-09 15:08:12 +00008240
Douglas Gregora16548e2009-08-11 05:31:07 +00008241template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008242ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008243TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8244 // Transform the callee.
8245 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8246 if (Callee.isInvalid())
8247 return ExprError();
8248
8249 // Transform exec config.
8250 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8251 if (EC.isInvalid())
8252 return ExprError();
8253
8254 // Transform arguments.
8255 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008256 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008257 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008258 &ArgChanged))
8259 return ExprError();
8260
8261 if (!getDerived().AlwaysRebuild() &&
8262 Callee.get() == E->getCallee() &&
8263 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008264 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008265
8266 // FIXME: Wrong source location information for the '('.
8267 SourceLocation FakeLParenLoc
8268 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8269 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008270 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008271 E->getRParenLoc(), EC.get());
8272}
8273
8274template<typename Derived>
8275ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008276TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008277 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8278 if (!Type)
8279 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008280
John McCalldadc5752010-08-24 06:29:42 +00008281 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008282 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008283 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008284 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008285
Douglas Gregora16548e2009-08-11 05:31:07 +00008286 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008287 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008288 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008289 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008290 return getDerived().RebuildCXXNamedCastExpr(
8291 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8292 Type, E->getAngleBrackets().getEnd(),
8293 // FIXME. this should be '(' location
8294 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008295}
Mike Stump11289f42009-09-09 15:08:12 +00008296
Douglas Gregora16548e2009-08-11 05:31:07 +00008297template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008298ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008299TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8300 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008301}
Mike Stump11289f42009-09-09 15:08:12 +00008302
8303template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008304ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008305TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8306 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008307}
8308
Douglas Gregora16548e2009-08-11 05:31:07 +00008309template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008310ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008311TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008312 CXXReinterpretCastExpr *E) {
8313 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008314}
Mike Stump11289f42009-09-09 15:08:12 +00008315
Douglas Gregora16548e2009-08-11 05:31:07 +00008316template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008317ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008318TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8319 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008320}
Mike Stump11289f42009-09-09 15:08:12 +00008321
Douglas Gregora16548e2009-08-11 05:31:07 +00008322template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008323ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008324TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008325 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008326 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8327 if (!Type)
8328 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008329
John McCalldadc5752010-08-24 06:29:42 +00008330 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008331 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008332 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008333 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008334
Douglas Gregora16548e2009-08-11 05:31:07 +00008335 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008336 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008337 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008338 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008339
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008340 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008341 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008342 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008343 E->getRParenLoc());
8344}
Mike Stump11289f42009-09-09 15:08:12 +00008345
Douglas Gregora16548e2009-08-11 05:31:07 +00008346template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008347ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008348TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008349 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008350 TypeSourceInfo *TInfo
8351 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8352 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008353 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008354
Douglas Gregora16548e2009-08-11 05:31:07 +00008355 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008356 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008357 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008358
Douglas Gregor9da64192010-04-26 22:37:10 +00008359 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8360 E->getLocStart(),
8361 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008362 E->getLocEnd());
8363 }
Mike Stump11289f42009-09-09 15:08:12 +00008364
Eli Friedman456f0182012-01-20 01:26:23 +00008365 // We don't know whether the subexpression is potentially evaluated until
8366 // after we perform semantic analysis. We speculatively assume it is
8367 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008368 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008369 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8370 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008371
John McCalldadc5752010-08-24 06:29:42 +00008372 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008373 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008374 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008375
Douglas Gregora16548e2009-08-11 05:31:07 +00008376 if (!getDerived().AlwaysRebuild() &&
8377 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008378 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008379
Douglas Gregor9da64192010-04-26 22:37:10 +00008380 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8381 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008382 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008383 E->getLocEnd());
8384}
8385
8386template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008387ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008388TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8389 if (E->isTypeOperand()) {
8390 TypeSourceInfo *TInfo
8391 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8392 if (!TInfo)
8393 return ExprError();
8394
8395 if (!getDerived().AlwaysRebuild() &&
8396 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008397 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008398
Douglas Gregor69735112011-03-06 17:40:41 +00008399 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008400 E->getLocStart(),
8401 TInfo,
8402 E->getLocEnd());
8403 }
8404
Francois Pichet9f4f2072010-09-08 12:20:18 +00008405 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8406
8407 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8408 if (SubExpr.isInvalid())
8409 return ExprError();
8410
8411 if (!getDerived().AlwaysRebuild() &&
8412 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008413 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008414
8415 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8416 E->getLocStart(),
8417 SubExpr.get(),
8418 E->getLocEnd());
8419}
8420
8421template<typename Derived>
8422ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008423TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008424 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008425}
Mike Stump11289f42009-09-09 15:08:12 +00008426
Douglas Gregora16548e2009-08-11 05:31:07 +00008427template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008428ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008429TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008430 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008431 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008432}
Mike Stump11289f42009-09-09 15:08:12 +00008433
Douglas Gregora16548e2009-08-11 05:31:07 +00008434template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008435ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008436TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008437 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008438
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008439 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8440 // Make sure that we capture 'this'.
8441 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008442 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008443 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008444
Douglas Gregorb15af892010-01-07 23:12:05 +00008445 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008446}
Mike Stump11289f42009-09-09 15:08:12 +00008447
Douglas Gregora16548e2009-08-11 05:31:07 +00008448template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008449ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008450TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008451 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008452 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008453 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008454
Douglas Gregora16548e2009-08-11 05:31:07 +00008455 if (!getDerived().AlwaysRebuild() &&
8456 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008457 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008458
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008459 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8460 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008461}
Mike Stump11289f42009-09-09 15:08:12 +00008462
Douglas Gregora16548e2009-08-11 05:31:07 +00008463template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008464ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008465TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008466 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008467 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8468 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008469 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008470 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008471
Chandler Carruth794da4c2010-02-08 06:42:49 +00008472 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008473 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008474 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008475
Douglas Gregor033f6752009-12-23 23:03:06 +00008476 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008477}
Mike Stump11289f42009-09-09 15:08:12 +00008478
Douglas Gregora16548e2009-08-11 05:31:07 +00008479template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008480ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008481TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8482 FieldDecl *Field
8483 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8484 E->getField()));
8485 if (!Field)
8486 return ExprError();
8487
8488 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008489 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008490
8491 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8492}
8493
8494template<typename Derived>
8495ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008496TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8497 CXXScalarValueInitExpr *E) {
8498 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8499 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008500 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008501
Douglas Gregora16548e2009-08-11 05:31:07 +00008502 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008503 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008504 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008505
Chad Rosier1dcde962012-08-08 18:46:20 +00008506 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008507 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008508 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008509}
Mike Stump11289f42009-09-09 15:08:12 +00008510
Douglas Gregora16548e2009-08-11 05:31:07 +00008511template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008512ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008513TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008514 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008515 TypeSourceInfo *AllocTypeInfo
8516 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8517 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008518 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008519
Douglas Gregora16548e2009-08-11 05:31:07 +00008520 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008521 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008522 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008523 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008524
Douglas Gregora16548e2009-08-11 05:31:07 +00008525 // Transform the placement arguments (if any).
8526 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008527 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008528 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008529 E->getNumPlacementArgs(), true,
8530 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008531 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008532
Sebastian Redl6047f072012-02-16 12:22:20 +00008533 // Transform the initializer (if any).
8534 Expr *OldInit = E->getInitializer();
8535 ExprResult NewInit;
8536 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008537 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008538 if (NewInit.isInvalid())
8539 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008540
Sebastian Redl6047f072012-02-16 12:22:20 +00008541 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008542 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008543 if (E->getOperatorNew()) {
8544 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008545 getDerived().TransformDecl(E->getLocStart(),
8546 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008547 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008548 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008549 }
8550
Craig Topperc3ec1492014-05-26 06:22:03 +00008551 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008552 if (E->getOperatorDelete()) {
8553 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008554 getDerived().TransformDecl(E->getLocStart(),
8555 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008556 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008557 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008558 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008559
Douglas Gregora16548e2009-08-11 05:31:07 +00008560 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008561 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008562 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008563 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008564 OperatorNew == E->getOperatorNew() &&
8565 OperatorDelete == E->getOperatorDelete() &&
8566 !ArgumentChanged) {
8567 // Mark any declarations we need as referenced.
8568 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008569 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008570 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008571 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008572 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008573
Sebastian Redl6047f072012-02-16 12:22:20 +00008574 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008575 QualType ElementType
8576 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8577 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8578 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8579 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008580 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008581 }
8582 }
8583 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008584
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008585 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008586 }
Mike Stump11289f42009-09-09 15:08:12 +00008587
Douglas Gregor0744ef62010-09-07 21:49:58 +00008588 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008589 if (!ArraySize.get()) {
8590 // If no array size was specified, but the new expression was
8591 // instantiated with an array type (e.g., "new T" where T is
8592 // instantiated with "int[4]"), extract the outer bound from the
8593 // array type as our array size. We do this with constant and
8594 // dependently-sized array types.
8595 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8596 if (!ArrayT) {
8597 // Do nothing
8598 } else if (const ConstantArrayType *ConsArrayT
8599 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008600 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8601 SemaRef.Context.getSizeType(),
8602 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008603 AllocType = ConsArrayT->getElementType();
8604 } else if (const DependentSizedArrayType *DepArrayT
8605 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8606 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008607 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008608 AllocType = DepArrayT->getElementType();
8609 }
8610 }
8611 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008612
Douglas Gregora16548e2009-08-11 05:31:07 +00008613 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8614 E->isGlobalNew(),
8615 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008616 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008617 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008618 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008619 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008620 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008621 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008622 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008623 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008624}
Mike Stump11289f42009-09-09 15:08:12 +00008625
Douglas Gregora16548e2009-08-11 05:31:07 +00008626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008627ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008628TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008629 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008630 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008631 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008632
Douglas Gregord2d9da02010-02-26 00:38:10 +00008633 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008634 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008635 if (E->getOperatorDelete()) {
8636 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008637 getDerived().TransformDecl(E->getLocStart(),
8638 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008639 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008640 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008641 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008642
Douglas Gregora16548e2009-08-11 05:31:07 +00008643 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008644 Operand.get() == E->getArgument() &&
8645 OperatorDelete == E->getOperatorDelete()) {
8646 // Mark any declarations we need as referenced.
8647 // FIXME: instantiation-specific.
8648 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008649 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008650
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008651 if (!E->getArgument()->isTypeDependent()) {
8652 QualType Destroyed = SemaRef.Context.getBaseElementType(
8653 E->getDestroyedType());
8654 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8655 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008656 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008657 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008658 }
8659 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008660
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008661 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008662 }
Mike Stump11289f42009-09-09 15:08:12 +00008663
Douglas Gregora16548e2009-08-11 05:31:07 +00008664 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8665 E->isGlobalDelete(),
8666 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008667 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008668}
Mike Stump11289f42009-09-09 15:08:12 +00008669
Douglas Gregora16548e2009-08-11 05:31:07 +00008670template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008671ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008672TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008673 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008674 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008675 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008676 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008677
John McCallba7bf592010-08-24 05:47:05 +00008678 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008679 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008680 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008681 E->getOperatorLoc(),
8682 E->isArrow()? tok::arrow : tok::period,
8683 ObjectTypePtr,
8684 MayBePseudoDestructor);
8685 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008686 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008687
John McCallba7bf592010-08-24 05:47:05 +00008688 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008689 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8690 if (QualifierLoc) {
8691 QualifierLoc
8692 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8693 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008694 return ExprError();
8695 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008696 CXXScopeSpec SS;
8697 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008698
Douglas Gregor678f90d2010-02-25 01:56:36 +00008699 PseudoDestructorTypeStorage Destroyed;
8700 if (E->getDestroyedTypeInfo()) {
8701 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008702 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008703 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008704 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008705 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008706 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008707 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008708 // We aren't likely to be able to resolve the identifier down to a type
8709 // now anyway, so just retain the identifier.
8710 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8711 E->getDestroyedTypeLoc());
8712 } else {
8713 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008714 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008715 *E->getDestroyedTypeIdentifier(),
8716 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008717 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008718 SS, ObjectTypePtr,
8719 false);
8720 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008721 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008722
Douglas Gregor678f90d2010-02-25 01:56:36 +00008723 Destroyed
8724 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8725 E->getDestroyedTypeLoc());
8726 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008727
Craig Topperc3ec1492014-05-26 06:22:03 +00008728 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008729 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008730 CXXScopeSpec EmptySS;
8731 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008732 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008733 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008734 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008735 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008736
John McCallb268a282010-08-23 23:25:46 +00008737 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008738 E->getOperatorLoc(),
8739 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008740 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008741 ScopeTypeInfo,
8742 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008743 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008744 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008745}
Mike Stump11289f42009-09-09 15:08:12 +00008746
Douglas Gregorad8a3362009-09-04 17:36:40 +00008747template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008748ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008749TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008750 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008751 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8752 Sema::LookupOrdinaryName);
8753
8754 // Transform all the decls.
8755 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8756 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008757 NamedDecl *InstD = static_cast<NamedDecl*>(
8758 getDerived().TransformDecl(Old->getNameLoc(),
8759 *I));
John McCall84d87672009-12-10 09:41:52 +00008760 if (!InstD) {
8761 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8762 // This can happen because of dependent hiding.
8763 if (isa<UsingShadowDecl>(*I))
8764 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008765 else {
8766 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008767 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008768 }
John McCall84d87672009-12-10 09:41:52 +00008769 }
John McCalle66edc12009-11-24 19:00:30 +00008770
8771 // Expand using declarations.
8772 if (isa<UsingDecl>(InstD)) {
8773 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008774 for (auto *I : UD->shadows())
8775 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008776 continue;
8777 }
8778
8779 R.addDecl(InstD);
8780 }
8781
8782 // Resolve a kind, but don't do any further analysis. If it's
8783 // ambiguous, the callee needs to deal with it.
8784 R.resolveKind();
8785
8786 // Rebuild the nested-name qualifier, if present.
8787 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008788 if (Old->getQualifierLoc()) {
8789 NestedNameSpecifierLoc QualifierLoc
8790 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8791 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008792 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008793
Douglas Gregor0da1d432011-02-28 20:01:57 +00008794 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008795 }
8796
Douglas Gregor9262f472010-04-27 18:19:34 +00008797 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008798 CXXRecordDecl *NamingClass
8799 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8800 Old->getNameLoc(),
8801 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008802 if (!NamingClass) {
8803 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008804 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008805 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008806
Douglas Gregorda7be082010-04-27 16:10:10 +00008807 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008808 }
8809
Abramo Bagnara7945c982012-01-27 09:46:47 +00008810 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8811
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008812 // If we have neither explicit template arguments, nor the template keyword,
8813 // it's a normal declaration name.
8814 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008815 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8816
8817 // If we have template arguments, rebuild them, then rebuild the
8818 // templateid expression.
8819 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008820 if (Old->hasExplicitTemplateArgs() &&
8821 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008822 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008823 TransArgs)) {
8824 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008825 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008826 }
John McCalle66edc12009-11-24 19:00:30 +00008827
Abramo Bagnara7945c982012-01-27 09:46:47 +00008828 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008829 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008830}
Mike Stump11289f42009-09-09 15:08:12 +00008831
Douglas Gregora16548e2009-08-11 05:31:07 +00008832template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008833ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008834TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8835 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008836 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008837 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8838 TypeSourceInfo *From = E->getArg(I);
8839 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008840 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008841 TypeLocBuilder TLB;
8842 TLB.reserve(FromTL.getFullDataSize());
8843 QualType To = getDerived().TransformType(TLB, FromTL);
8844 if (To.isNull())
8845 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008846
Douglas Gregor29c42f22012-02-24 07:38:34 +00008847 if (To == From->getType())
8848 Args.push_back(From);
8849 else {
8850 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8851 ArgChanged = true;
8852 }
8853 continue;
8854 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008855
Douglas Gregor29c42f22012-02-24 07:38:34 +00008856 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008857
Douglas Gregor29c42f22012-02-24 07:38:34 +00008858 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008859 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008860 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8861 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8862 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008863
Douglas Gregor29c42f22012-02-24 07:38:34 +00008864 // Determine whether the set of unexpanded parameter packs can and should
8865 // be expanded.
8866 bool Expand = true;
8867 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008868 Optional<unsigned> OrigNumExpansions =
8869 ExpansionTL.getTypePtr()->getNumExpansions();
8870 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008871 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8872 PatternTL.getSourceRange(),
8873 Unexpanded,
8874 Expand, RetainExpansion,
8875 NumExpansions))
8876 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008877
Douglas Gregor29c42f22012-02-24 07:38:34 +00008878 if (!Expand) {
8879 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008880 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008881 // expansion.
8882 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008883
Douglas Gregor29c42f22012-02-24 07:38:34 +00008884 TypeLocBuilder TLB;
8885 TLB.reserve(From->getTypeLoc().getFullDataSize());
8886
8887 QualType To = getDerived().TransformType(TLB, PatternTL);
8888 if (To.isNull())
8889 return ExprError();
8890
Chad Rosier1dcde962012-08-08 18:46:20 +00008891 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008892 PatternTL.getSourceRange(),
8893 ExpansionTL.getEllipsisLoc(),
8894 NumExpansions);
8895 if (To.isNull())
8896 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008897
Douglas Gregor29c42f22012-02-24 07:38:34 +00008898 PackExpansionTypeLoc ToExpansionTL
8899 = TLB.push<PackExpansionTypeLoc>(To);
8900 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8901 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8902 continue;
8903 }
8904
8905 // Expand the pack expansion by substituting for each argument in the
8906 // pack(s).
8907 for (unsigned I = 0; I != *NumExpansions; ++I) {
8908 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8909 TypeLocBuilder TLB;
8910 TLB.reserve(PatternTL.getFullDataSize());
8911 QualType To = getDerived().TransformType(TLB, PatternTL);
8912 if (To.isNull())
8913 return ExprError();
8914
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008915 if (To->containsUnexpandedParameterPack()) {
8916 To = getDerived().RebuildPackExpansionType(To,
8917 PatternTL.getSourceRange(),
8918 ExpansionTL.getEllipsisLoc(),
8919 NumExpansions);
8920 if (To.isNull())
8921 return ExprError();
8922
8923 PackExpansionTypeLoc ToExpansionTL
8924 = TLB.push<PackExpansionTypeLoc>(To);
8925 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8926 }
8927
Douglas Gregor29c42f22012-02-24 07:38:34 +00008928 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8929 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008930
Douglas Gregor29c42f22012-02-24 07:38:34 +00008931 if (!RetainExpansion)
8932 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008933
Douglas Gregor29c42f22012-02-24 07:38:34 +00008934 // If we're supposed to retain a pack expansion, do so by temporarily
8935 // forgetting the partially-substituted parameter pack.
8936 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8937
8938 TypeLocBuilder TLB;
8939 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008940
Douglas Gregor29c42f22012-02-24 07:38:34 +00008941 QualType To = getDerived().TransformType(TLB, PatternTL);
8942 if (To.isNull())
8943 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008944
8945 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008946 PatternTL.getSourceRange(),
8947 ExpansionTL.getEllipsisLoc(),
8948 NumExpansions);
8949 if (To.isNull())
8950 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008951
Douglas Gregor29c42f22012-02-24 07:38:34 +00008952 PackExpansionTypeLoc ToExpansionTL
8953 = TLB.push<PackExpansionTypeLoc>(To);
8954 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8955 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8956 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008957
Douglas Gregor29c42f22012-02-24 07:38:34 +00008958 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008959 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008960
8961 return getDerived().RebuildTypeTrait(E->getTrait(),
8962 E->getLocStart(),
8963 Args,
8964 E->getLocEnd());
8965}
8966
8967template<typename Derived>
8968ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008969TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8970 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8971 if (!T)
8972 return ExprError();
8973
8974 if (!getDerived().AlwaysRebuild() &&
8975 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008976 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008977
8978 ExprResult SubExpr;
8979 {
8980 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8981 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8982 if (SubExpr.isInvalid())
8983 return ExprError();
8984
8985 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008986 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008987 }
8988
8989 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8990 E->getLocStart(),
8991 T,
8992 SubExpr.get(),
8993 E->getLocEnd());
8994}
8995
8996template<typename Derived>
8997ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008998TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8999 ExprResult SubExpr;
9000 {
9001 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9002 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9003 if (SubExpr.isInvalid())
9004 return ExprError();
9005
9006 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009007 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009008 }
9009
9010 return getDerived().RebuildExpressionTrait(
9011 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9012}
9013
Reid Kleckner32506ed2014-06-12 23:03:48 +00009014template <typename Derived>
9015ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9016 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9017 TypeSourceInfo **RecoveryTSI) {
9018 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9019 DRE, AddrTaken, RecoveryTSI);
9020
9021 // Propagate both errors and recovered types, which return ExprEmpty.
9022 if (!NewDRE.isUsable())
9023 return NewDRE;
9024
9025 // We got an expr, wrap it up in parens.
9026 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9027 return PE;
9028 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9029 PE->getRParen());
9030}
9031
9032template <typename Derived>
9033ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9034 DependentScopeDeclRefExpr *E) {
9035 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9036 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009037}
9038
9039template<typename Derived>
9040ExprResult
9041TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9042 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009043 bool IsAddressOfOperand,
9044 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009045 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009046 NestedNameSpecifierLoc QualifierLoc
9047 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9048 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009049 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009050 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009051
John McCall31f82722010-11-12 08:19:04 +00009052 // TODO: If this is a conversion-function-id, verify that the
9053 // destination type name (if present) resolves the same way after
9054 // instantiation as it did in the local scope.
9055
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009056 DeclarationNameInfo NameInfo
9057 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9058 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009059 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009060
John McCalle66edc12009-11-24 19:00:30 +00009061 if (!E->hasExplicitTemplateArgs()) {
9062 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009063 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009064 // Note: it is sufficient to compare the Name component of NameInfo:
9065 // if name has not changed, DNLoc has not changed either.
9066 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009067 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009068
Reid Kleckner32506ed2014-06-12 23:03:48 +00009069 return getDerived().RebuildDependentScopeDeclRefExpr(
9070 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9071 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009072 }
John McCall6b51f282009-11-23 01:53:49 +00009073
9074 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009075 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9076 E->getNumTemplateArgs(),
9077 TransArgs))
9078 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009079
Reid Kleckner32506ed2014-06-12 23:03:48 +00009080 return getDerived().RebuildDependentScopeDeclRefExpr(
9081 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9082 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009083}
9084
9085template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009086ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009087TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009088 // CXXConstructExprs other than for list-initialization and
9089 // CXXTemporaryObjectExpr are always implicit, so when we have
9090 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009091 if ((E->getNumArgs() == 1 ||
9092 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009093 (!getDerived().DropCallArgument(E->getArg(0))) &&
9094 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009095 return getDerived().TransformExpr(E->getArg(0));
9096
Douglas Gregora16548e2009-08-11 05:31:07 +00009097 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9098
9099 QualType T = getDerived().TransformType(E->getType());
9100 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009101 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009102
9103 CXXConstructorDecl *Constructor
9104 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009105 getDerived().TransformDecl(E->getLocStart(),
9106 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009107 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009108 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009109
Douglas Gregora16548e2009-08-11 05:31:07 +00009110 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009111 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009112 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009113 &ArgumentChanged))
9114 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009115
Douglas Gregora16548e2009-08-11 05:31:07 +00009116 if (!getDerived().AlwaysRebuild() &&
9117 T == E->getType() &&
9118 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009119 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009120 // Mark the constructor as referenced.
9121 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009122 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009123 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009124 }
Mike Stump11289f42009-09-09 15:08:12 +00009125
Douglas Gregordb121ba2009-12-14 16:27:04 +00009126 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9127 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009128 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009129 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009130 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009131 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009132 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009133 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009134 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009135}
Mike Stump11289f42009-09-09 15:08:12 +00009136
Douglas Gregora16548e2009-08-11 05:31:07 +00009137/// \brief Transform a C++ temporary-binding expression.
9138///
Douglas Gregor363b1512009-12-24 18:51:59 +00009139/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9140/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009141template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009142ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009143TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009144 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009145}
Mike Stump11289f42009-09-09 15:08:12 +00009146
John McCall5d413782010-12-06 08:20:24 +00009147/// \brief Transform a C++ expression that contains cleanups that should
9148/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009149///
John McCall5d413782010-12-06 08:20:24 +00009150/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009151/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009152template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009153ExprResult
John McCall5d413782010-12-06 08:20:24 +00009154TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009155 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009156}
Mike Stump11289f42009-09-09 15:08:12 +00009157
Douglas Gregora16548e2009-08-11 05:31:07 +00009158template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009159ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009160TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009161 CXXTemporaryObjectExpr *E) {
9162 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9163 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009164 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009165
Douglas Gregora16548e2009-08-11 05:31:07 +00009166 CXXConstructorDecl *Constructor
9167 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009168 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009169 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009170 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009171 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009172
Douglas Gregora16548e2009-08-11 05:31:07 +00009173 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009174 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009175 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009176 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009177 &ArgumentChanged))
9178 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009179
Douglas Gregora16548e2009-08-11 05:31:07 +00009180 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009181 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009182 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009183 !ArgumentChanged) {
9184 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009185 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009186 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009187 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009188
Richard Smithd59b8322012-12-19 01:39:02 +00009189 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009190 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9191 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009192 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009193 E->getLocEnd());
9194}
Mike Stump11289f42009-09-09 15:08:12 +00009195
Douglas Gregora16548e2009-08-11 05:31:07 +00009196template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009197ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009198TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009199 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009200 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009201 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009202 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9203 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009204 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009205 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009206 CEnd = E->capture_end();
9207 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009208 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009209 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009210 EnterExpressionEvaluationContext EEEC(getSema(),
9211 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009212 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9213 C->getCapturedVar()->getInit(),
9214 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009215
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009216 if (NewExprInitResult.isInvalid())
9217 return ExprError();
9218 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009219
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009220 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009221 QualType NewInitCaptureType =
9222 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
9223 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009224 NewExprInit);
9225 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009226 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9227 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009228 }
9229
Faisal Vali2cba1332013-10-23 06:44:28 +00009230 // Transform the template parameters, and add them to the current
9231 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009232 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009233 E->getTemplateParameterList());
9234
Richard Smith01014ce2014-11-20 23:53:14 +00009235 // Transform the type of the original lambda's call operator.
9236 // The transformation MUST be done in the CurrentInstantiationScope since
9237 // it introduces a mapping of the original to the newly created
9238 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009239 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009240 {
9241 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9242 FunctionProtoTypeLoc OldCallOpFPTL =
9243 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009244
9245 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009246 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009247 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009248 QualType NewCallOpType = TransformFunctionProtoType(
9249 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009250 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9251 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9252 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009253 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009254 if (NewCallOpType.isNull())
9255 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009256 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9257 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009258 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009259
Richard Smithc38498f2015-04-27 21:27:54 +00009260 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9261 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9262 LSI->GLTemplateParameterList = TPL;
9263
Eli Friedmand564afb2012-09-19 01:18:11 +00009264 // Create the local class that will describe the lambda.
9265 CXXRecordDecl *Class
9266 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009267 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009268 /*KnownDependent=*/false,
9269 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009270 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9271
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009272 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009273 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9274 Class, E->getIntroducerRange(), NewCallOpTSI,
9275 E->getCallOperator()->getLocEnd(),
9276 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009277 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009278
Faisal Vali2cba1332013-10-23 06:44:28 +00009279 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009280 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009281
Douglas Gregorb4328232012-02-14 00:00:48 +00009282 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009283 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009284 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009285
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009286 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009287 getSema().buildLambdaScope(LSI, NewCallOperator,
9288 E->getIntroducerRange(),
9289 E->getCaptureDefault(),
9290 E->getCaptureDefaultLoc(),
9291 E->hasExplicitParameters(),
9292 E->hasExplicitResultType(),
9293 E->isMutable());
9294
9295 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009296
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009297 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009298 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009299 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009300 CEnd = E->capture_end();
9301 C != CEnd; ++C) {
9302 // When we hit the first implicit capture, tell Sema that we've finished
9303 // the list of explicit captures.
9304 if (!FinishedExplicitCaptures && C->isImplicit()) {
9305 getSema().finishLambdaExplicitCaptures(LSI);
9306 FinishedExplicitCaptures = true;
9307 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009308
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009309 // Capturing 'this' is trivial.
9310 if (C->capturesThis()) {
9311 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9312 continue;
9313 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009314 // Captured expression will be recaptured during captured variables
9315 // rebuilding.
9316 if (C->capturesVLAType())
9317 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009318
Richard Smithba71c082013-05-16 06:20:58 +00009319 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +00009320 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009321 InitCaptureInfoTy InitExprTypePair =
9322 InitCaptureExprsAndTypes[C - E->capture_begin()];
9323 ExprResult Init = InitExprTypePair.first;
9324 QualType InitQualType = InitExprTypePair.second;
9325 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009326 Invalid = true;
9327 continue;
9328 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009329 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009330 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9331 OldVD->getLocation(), InitExprTypePair.second,
9332 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009333 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009334 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009335 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009336 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009337 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009338 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009339 continue;
9340 }
9341
9342 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9343
Douglas Gregor3e308b12012-02-14 19:27:52 +00009344 // Determine the capture kind for Sema.
9345 Sema::TryCaptureKind Kind
9346 = C->isImplicit()? Sema::TryCapture_Implicit
9347 : C->getCaptureKind() == LCK_ByCopy
9348 ? Sema::TryCapture_ExplicitByVal
9349 : Sema::TryCapture_ExplicitByRef;
9350 SourceLocation EllipsisLoc;
9351 if (C->isPackExpansion()) {
9352 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9353 bool ShouldExpand = false;
9354 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009355 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009356 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9357 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009358 Unexpanded,
9359 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009360 NumExpansions)) {
9361 Invalid = true;
9362 continue;
9363 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009364
Douglas Gregor3e308b12012-02-14 19:27:52 +00009365 if (ShouldExpand) {
9366 // The transform has determined that we should perform an expansion;
9367 // transform and capture each of the arguments.
9368 // expansion of the pattern. Do so.
9369 VarDecl *Pack = C->getCapturedVar();
9370 for (unsigned I = 0; I != *NumExpansions; ++I) {
9371 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9372 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009373 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009374 Pack));
9375 if (!CapturedVar) {
9376 Invalid = true;
9377 continue;
9378 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009379
Douglas Gregor3e308b12012-02-14 19:27:52 +00009380 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009381 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9382 }
Richard Smith9467be42014-06-06 17:33:35 +00009383
9384 // FIXME: Retain a pack expansion if RetainExpansion is true.
9385
Douglas Gregor3e308b12012-02-14 19:27:52 +00009386 continue;
9387 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009388
Douglas Gregor3e308b12012-02-14 19:27:52 +00009389 EllipsisLoc = C->getEllipsisLoc();
9390 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009391
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009392 // Transform the captured variable.
9393 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009394 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009395 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009396 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009397 Invalid = true;
9398 continue;
9399 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009400
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009401 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00009402 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009403 }
9404 if (!FinishedExplicitCaptures)
9405 getSema().finishLambdaExplicitCaptures(LSI);
9406
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009407 // Enter a new evaluation context to insulate the lambda from any
9408 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009409 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009410
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009411 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +00009412 StmtResult Body =
9413 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
9414
9415 // ActOnLambda* will pop the function scope for us.
9416 FuncScopeCleanup.disable();
9417
Douglas Gregorb4328232012-02-14 00:00:48 +00009418 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +00009419 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +00009420 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009421 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009422 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009423 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009424
Richard Smithc38498f2015-04-27 21:27:54 +00009425 // Copy the LSI before ActOnFinishFunctionBody removes it.
9426 // FIXME: This is dumb. Store the lambda information somewhere that outlives
9427 // the call operator.
9428 auto LSICopy = *LSI;
9429 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
9430 /*IsInstantiation*/ true);
9431 SavedContext.pop();
9432
9433 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
9434 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +00009435}
9436
9437template<typename Derived>
9438ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009439TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009440 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009441 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9442 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009443 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009444
Douglas Gregora16548e2009-08-11 05:31:07 +00009445 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009446 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009447 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009448 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009449 &ArgumentChanged))
9450 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009451
Douglas Gregora16548e2009-08-11 05:31:07 +00009452 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009453 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009454 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009455 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009456
Douglas Gregora16548e2009-08-11 05:31:07 +00009457 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009458 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009459 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009460 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009461 E->getRParenLoc());
9462}
Mike Stump11289f42009-09-09 15:08:12 +00009463
Douglas Gregora16548e2009-08-11 05:31:07 +00009464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009465ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009466TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009467 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009468 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009469 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009470 Expr *OldBase;
9471 QualType BaseType;
9472 QualType ObjectType;
9473 if (!E->isImplicitAccess()) {
9474 OldBase = E->getBase();
9475 Base = getDerived().TransformExpr(OldBase);
9476 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009477 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009478
John McCall2d74de92009-12-01 22:10:20 +00009479 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009480 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009481 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009482 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009483 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009484 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009485 ObjectTy,
9486 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009487 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009488 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009489
John McCallba7bf592010-08-24 05:47:05 +00009490 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009491 BaseType = ((Expr*) Base.get())->getType();
9492 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009493 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009494 BaseType = getDerived().TransformType(E->getBaseType());
9495 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9496 }
Mike Stump11289f42009-09-09 15:08:12 +00009497
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009498 // Transform the first part of the nested-name-specifier that qualifies
9499 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009500 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009501 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009502 E->getFirstQualifierFoundInScope(),
9503 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009504
Douglas Gregore16af532011-02-28 18:50:33 +00009505 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009506 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009507 QualifierLoc
9508 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9509 ObjectType,
9510 FirstQualifierInScope);
9511 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009512 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009513 }
Mike Stump11289f42009-09-09 15:08:12 +00009514
Abramo Bagnara7945c982012-01-27 09:46:47 +00009515 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9516
John McCall31f82722010-11-12 08:19:04 +00009517 // TODO: If this is a conversion-function-id, verify that the
9518 // destination type name (if present) resolves the same way after
9519 // instantiation as it did in the local scope.
9520
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009521 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009522 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009523 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009524 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009525
John McCall2d74de92009-12-01 22:10:20 +00009526 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009527 // This is a reference to a member without an explicitly-specified
9528 // template argument list. Optimize for this common case.
9529 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009530 Base.get() == OldBase &&
9531 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009532 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009533 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009534 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009535 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009536
John McCallb268a282010-08-23 23:25:46 +00009537 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009538 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009539 E->isArrow(),
9540 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009541 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009542 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009543 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009544 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009545 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009546 }
9547
John McCall6b51f282009-11-23 01:53:49 +00009548 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009549 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9550 E->getNumTemplateArgs(),
9551 TransArgs))
9552 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009553
John McCallb268a282010-08-23 23:25:46 +00009554 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009555 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009556 E->isArrow(),
9557 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009558 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009559 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009560 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009561 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009562 &TransArgs);
9563}
9564
9565template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009566ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009567TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009568 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009569 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009570 QualType BaseType;
9571 if (!Old->isImplicitAccess()) {
9572 Base = getDerived().TransformExpr(Old->getBase());
9573 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009574 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009575 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009576 Old->isArrow());
9577 if (Base.isInvalid())
9578 return ExprError();
9579 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009580 } else {
9581 BaseType = getDerived().TransformType(Old->getBaseType());
9582 }
John McCall10eae182009-11-30 22:42:35 +00009583
Douglas Gregor0da1d432011-02-28 20:01:57 +00009584 NestedNameSpecifierLoc QualifierLoc;
9585 if (Old->getQualifierLoc()) {
9586 QualifierLoc
9587 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9588 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009589 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009590 }
9591
Abramo Bagnara7945c982012-01-27 09:46:47 +00009592 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9593
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009594 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009595 Sema::LookupOrdinaryName);
9596
9597 // Transform all the decls.
9598 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9599 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009600 NamedDecl *InstD = static_cast<NamedDecl*>(
9601 getDerived().TransformDecl(Old->getMemberLoc(),
9602 *I));
John McCall84d87672009-12-10 09:41:52 +00009603 if (!InstD) {
9604 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9605 // This can happen because of dependent hiding.
9606 if (isa<UsingShadowDecl>(*I))
9607 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009608 else {
9609 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009610 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009611 }
John McCall84d87672009-12-10 09:41:52 +00009612 }
John McCall10eae182009-11-30 22:42:35 +00009613
9614 // Expand using declarations.
9615 if (isa<UsingDecl>(InstD)) {
9616 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009617 for (auto *I : UD->shadows())
9618 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009619 continue;
9620 }
9621
9622 R.addDecl(InstD);
9623 }
9624
9625 R.resolveKind();
9626
Douglas Gregor9262f472010-04-27 18:19:34 +00009627 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009628 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009629 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009630 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009631 Old->getMemberLoc(),
9632 Old->getNamingClass()));
9633 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009634 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009635
Douglas Gregorda7be082010-04-27 16:10:10 +00009636 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009637 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009638
John McCall10eae182009-11-30 22:42:35 +00009639 TemplateArgumentListInfo TransArgs;
9640 if (Old->hasExplicitTemplateArgs()) {
9641 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9642 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009643 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9644 Old->getNumTemplateArgs(),
9645 TransArgs))
9646 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009647 }
John McCall38836f02010-01-15 08:34:02 +00009648
9649 // FIXME: to do this check properly, we will need to preserve the
9650 // first-qualifier-in-scope here, just in case we had a dependent
9651 // base (and therefore couldn't do the check) and a
9652 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009653 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009654
John McCallb268a282010-08-23 23:25:46 +00009655 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009656 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009657 Old->getOperatorLoc(),
9658 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009659 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009660 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009661 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009662 R,
9663 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009664 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009665}
9666
9667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009668ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009669TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009670 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009671 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9672 if (SubExpr.isInvalid())
9673 return ExprError();
9674
9675 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009676 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009677
9678 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9679}
9680
9681template<typename Derived>
9682ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009683TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009684 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9685 if (Pattern.isInvalid())
9686 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009687
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009688 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009689 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009690
Douglas Gregorb8840002011-01-14 21:20:45 +00009691 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9692 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009693}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009694
9695template<typename Derived>
9696ExprResult
9697TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9698 // If E is not value-dependent, then nothing will change when we transform it.
9699 // Note: This is an instantiation-centric view.
9700 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009701 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009702
9703 // Note: None of the implementations of TryExpandParameterPacks can ever
9704 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009705 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009706 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9707 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009708 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009709 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009710 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009711 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009712 ShouldExpand, RetainExpansion,
9713 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009714 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009715
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009716 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009717 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009718
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009719 NamedDecl *Pack = E->getPack();
9720 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009721 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009722 Pack));
9723 if (!Pack)
9724 return ExprError();
9725 }
9726
Chad Rosier1dcde962012-08-08 18:46:20 +00009727
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009728 // We now know the length of the parameter pack, so build a new expression
9729 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009730 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9731 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009732 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009733}
9734
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009735template<typename Derived>
9736ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009737TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9738 SubstNonTypeTemplateParmPackExpr *E) {
9739 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009740 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009741}
9742
9743template<typename Derived>
9744ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009745TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9746 SubstNonTypeTemplateParmExpr *E) {
9747 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009748 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009749}
9750
9751template<typename Derived>
9752ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009753TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9754 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009755 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009756}
9757
9758template<typename Derived>
9759ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009760TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9761 MaterializeTemporaryExpr *E) {
9762 return getDerived().TransformExpr(E->GetTemporaryExpr());
9763}
Chad Rosier1dcde962012-08-08 18:46:20 +00009764
Douglas Gregorfe314812011-06-21 17:03:29 +00009765template<typename Derived>
9766ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +00009767TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
9768 Expr *Pattern = E->getPattern();
9769
9770 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9771 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
9772 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9773
9774 // Determine whether the set of unexpanded parameter packs can and should
9775 // be expanded.
9776 bool Expand = true;
9777 bool RetainExpansion = false;
9778 Optional<unsigned> NumExpansions;
9779 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
9780 Pattern->getSourceRange(),
9781 Unexpanded,
9782 Expand, RetainExpansion,
9783 NumExpansions))
9784 return true;
9785
9786 if (!Expand) {
9787 // Do not expand any packs here, just transform and rebuild a fold
9788 // expression.
9789 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9790
9791 ExprResult LHS =
9792 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
9793 if (LHS.isInvalid())
9794 return true;
9795
9796 ExprResult RHS =
9797 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
9798 if (RHS.isInvalid())
9799 return true;
9800
9801 if (!getDerived().AlwaysRebuild() &&
9802 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
9803 return E;
9804
9805 return getDerived().RebuildCXXFoldExpr(
9806 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
9807 RHS.get(), E->getLocEnd());
9808 }
9809
9810 // The transform has determined that we should perform an elementwise
9811 // expansion of the pattern. Do so.
9812 ExprResult Result = getDerived().TransformExpr(E->getInit());
9813 if (Result.isInvalid())
9814 return true;
9815 bool LeftFold = E->isLeftFold();
9816
9817 // If we're retaining an expansion for a right fold, it is the innermost
9818 // component and takes the init (if any).
9819 if (!LeftFold && RetainExpansion) {
9820 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9821
9822 ExprResult Out = getDerived().TransformExpr(Pattern);
9823 if (Out.isInvalid())
9824 return true;
9825
9826 Result = getDerived().RebuildCXXFoldExpr(
9827 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
9828 Result.get(), E->getLocEnd());
9829 if (Result.isInvalid())
9830 return true;
9831 }
9832
9833 for (unsigned I = 0; I != *NumExpansions; ++I) {
9834 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
9835 getSema(), LeftFold ? I : *NumExpansions - I - 1);
9836 ExprResult Out = getDerived().TransformExpr(Pattern);
9837 if (Out.isInvalid())
9838 return true;
9839
9840 if (Out.get()->containsUnexpandedParameterPack()) {
9841 // We still have a pack; retain a pack expansion for this slice.
9842 Result = getDerived().RebuildCXXFoldExpr(
9843 E->getLocStart(),
9844 LeftFold ? Result.get() : Out.get(),
9845 E->getOperator(), E->getEllipsisLoc(),
9846 LeftFold ? Out.get() : Result.get(),
9847 E->getLocEnd());
9848 } else if (Result.isUsable()) {
9849 // We've got down to a single element; build a binary operator.
9850 Result = getDerived().RebuildBinaryOperator(
9851 E->getEllipsisLoc(), E->getOperator(),
9852 LeftFold ? Result.get() : Out.get(),
9853 LeftFold ? Out.get() : Result.get());
9854 } else
9855 Result = Out;
9856
9857 if (Result.isInvalid())
9858 return true;
9859 }
9860
9861 // If we're retaining an expansion for a left fold, it is the outermost
9862 // component and takes the complete expansion so far as its init (if any).
9863 if (LeftFold && RetainExpansion) {
9864 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9865
9866 ExprResult Out = getDerived().TransformExpr(Pattern);
9867 if (Out.isInvalid())
9868 return true;
9869
9870 Result = getDerived().RebuildCXXFoldExpr(
9871 E->getLocStart(), Result.get(),
9872 E->getOperator(), E->getEllipsisLoc(),
9873 Out.get(), E->getLocEnd());
9874 if (Result.isInvalid())
9875 return true;
9876 }
9877
9878 // If we had no init and an empty pack, and we're not retaining an expansion,
9879 // then produce a fallback value or error.
9880 if (Result.isUnset())
9881 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
9882 E->getOperator());
9883
9884 return Result;
9885}
9886
9887template<typename Derived>
9888ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009889TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9890 CXXStdInitializerListExpr *E) {
9891 return getDerived().TransformExpr(E->getSubExpr());
9892}
9893
9894template<typename Derived>
9895ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009896TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009897 return SemaRef.MaybeBindToTemporary(E);
9898}
9899
9900template<typename Derived>
9901ExprResult
9902TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009903 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009904}
9905
9906template<typename Derived>
9907ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009908TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9909 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9910 if (SubExpr.isInvalid())
9911 return ExprError();
9912
9913 if (!getDerived().AlwaysRebuild() &&
9914 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009915 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009916
9917 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009918}
9919
9920template<typename Derived>
9921ExprResult
9922TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9923 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009924 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009925 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009926 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009927 /*IsCall=*/false, Elements, &ArgChanged))
9928 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009929
Ted Kremeneke65b0862012-03-06 20:05:56 +00009930 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9931 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009932
Ted Kremeneke65b0862012-03-06 20:05:56 +00009933 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9934 Elements.data(),
9935 Elements.size());
9936}
9937
9938template<typename Derived>
9939ExprResult
9940TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009941 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009942 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009943 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009944 bool ArgChanged = false;
9945 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9946 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009947
Ted Kremeneke65b0862012-03-06 20:05:56 +00009948 if (OrigElement.isPackExpansion()) {
9949 // This key/value element is a pack expansion.
9950 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9951 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9952 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9953 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9954
9955 // Determine whether the set of unexpanded parameter packs can
9956 // and should be expanded.
9957 bool Expand = true;
9958 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009959 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9960 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009961 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9962 OrigElement.Value->getLocEnd());
9963 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9964 PatternRange,
9965 Unexpanded,
9966 Expand, RetainExpansion,
9967 NumExpansions))
9968 return ExprError();
9969
9970 if (!Expand) {
9971 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009972 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009973 // expansion.
9974 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9975 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9976 if (Key.isInvalid())
9977 return ExprError();
9978
9979 if (Key.get() != OrigElement.Key)
9980 ArgChanged = true;
9981
9982 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9983 if (Value.isInvalid())
9984 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009985
Ted Kremeneke65b0862012-03-06 20:05:56 +00009986 if (Value.get() != OrigElement.Value)
9987 ArgChanged = true;
9988
Chad Rosier1dcde962012-08-08 18:46:20 +00009989 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009990 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9991 };
9992 Elements.push_back(Expansion);
9993 continue;
9994 }
9995
9996 // Record right away that the argument was changed. This needs
9997 // to happen even if the array expands to nothing.
9998 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009999
Ted Kremeneke65b0862012-03-06 20:05:56 +000010000 // The transform has determined that we should perform an elementwise
10001 // expansion of the pattern. Do so.
10002 for (unsigned I = 0; I != *NumExpansions; ++I) {
10003 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10004 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10005 if (Key.isInvalid())
10006 return ExprError();
10007
10008 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10009 if (Value.isInvalid())
10010 return ExprError();
10011
Chad Rosier1dcde962012-08-08 18:46:20 +000010012 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010013 Key.get(), Value.get(), SourceLocation(), NumExpansions
10014 };
10015
10016 // If any unexpanded parameter packs remain, we still have a
10017 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010018 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010019 if (Key.get()->containsUnexpandedParameterPack() ||
10020 Value.get()->containsUnexpandedParameterPack())
10021 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010022
Ted Kremeneke65b0862012-03-06 20:05:56 +000010023 Elements.push_back(Element);
10024 }
10025
Richard Smith9467be42014-06-06 17:33:35 +000010026 // FIXME: Retain a pack expansion if RetainExpansion is true.
10027
Ted Kremeneke65b0862012-03-06 20:05:56 +000010028 // We've finished with this pack expansion.
10029 continue;
10030 }
10031
10032 // Transform and check key.
10033 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10034 if (Key.isInvalid())
10035 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010036
Ted Kremeneke65b0862012-03-06 20:05:56 +000010037 if (Key.get() != OrigElement.Key)
10038 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010039
Ted Kremeneke65b0862012-03-06 20:05:56 +000010040 // Transform and check value.
10041 ExprResult Value
10042 = getDerived().TransformExpr(OrigElement.Value);
10043 if (Value.isInvalid())
10044 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010045
Ted Kremeneke65b0862012-03-06 20:05:56 +000010046 if (Value.get() != OrigElement.Value)
10047 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010048
10049 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010050 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010051 };
10052 Elements.push_back(Element);
10053 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010054
Ted Kremeneke65b0862012-03-06 20:05:56 +000010055 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10056 return SemaRef.MaybeBindToTemporary(E);
10057
10058 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
10059 Elements.data(),
10060 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +000010061}
10062
Mike Stump11289f42009-09-09 15:08:12 +000010063template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010064ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010065TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010066 TypeSourceInfo *EncodedTypeInfo
10067 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10068 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010069 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010070
Douglas Gregora16548e2009-08-11 05:31:07 +000010071 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010072 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010073 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010074
10075 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010076 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010077 E->getRParenLoc());
10078}
Mike Stump11289f42009-09-09 15:08:12 +000010079
Douglas Gregora16548e2009-08-11 05:31:07 +000010080template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010081ExprResult TreeTransform<Derived>::
10082TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010083 // This is a kind of implicit conversion, and it needs to get dropped
10084 // and recomputed for the same general reasons that ImplicitCastExprs
10085 // do, as well a more specific one: this expression is only valid when
10086 // it appears *immediately* as an argument expression.
10087 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010088}
10089
10090template<typename Derived>
10091ExprResult TreeTransform<Derived>::
10092TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010093 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010094 = getDerived().TransformType(E->getTypeInfoAsWritten());
10095 if (!TSInfo)
10096 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010097
John McCall31168b02011-06-15 23:02:42 +000010098 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010099 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010100 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010101
John McCall31168b02011-06-15 23:02:42 +000010102 if (!getDerived().AlwaysRebuild() &&
10103 TSInfo == E->getTypeInfoAsWritten() &&
10104 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010105 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010106
John McCall31168b02011-06-15 23:02:42 +000010107 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010108 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010109 Result.get());
10110}
10111
10112template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010113ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010114TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010115 // Transform arguments.
10116 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010117 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010118 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010119 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010120 &ArgChanged))
10121 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010122
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010123 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10124 // Class message: transform the receiver type.
10125 TypeSourceInfo *ReceiverTypeInfo
10126 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10127 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010128 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010129
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010130 // If nothing changed, just retain the existing message send.
10131 if (!getDerived().AlwaysRebuild() &&
10132 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010133 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010134
10135 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010136 SmallVector<SourceLocation, 16> SelLocs;
10137 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010138 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10139 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010140 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010141 E->getMethodDecl(),
10142 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010143 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010144 E->getRightLoc());
10145 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010146 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10147 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10148 // Build a new class message send to 'super'.
10149 SmallVector<SourceLocation, 16> SelLocs;
10150 E->getSelectorLocs(SelLocs);
10151 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10152 E->getSelector(),
10153 SelLocs,
10154 E->getMethodDecl(),
10155 E->getLeftLoc(),
10156 Args,
10157 E->getRightLoc());
10158 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010159
10160 // Instance message: transform the receiver
10161 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10162 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010163 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010164 = getDerived().TransformExpr(E->getInstanceReceiver());
10165 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010166 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010167
10168 // If nothing changed, just retain the existing message send.
10169 if (!getDerived().AlwaysRebuild() &&
10170 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010171 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010172
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010173 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010174 SmallVector<SourceLocation, 16> SelLocs;
10175 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010176 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010177 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010178 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010179 E->getMethodDecl(),
10180 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010181 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010182 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010183}
10184
Mike Stump11289f42009-09-09 15:08:12 +000010185template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010186ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010187TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010188 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010189}
10190
Mike Stump11289f42009-09-09 15:08:12 +000010191template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010192ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010193TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010194 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010195}
10196
Mike Stump11289f42009-09-09 15:08:12 +000010197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010198ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010199TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010200 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010201 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010202 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010203 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010204
10205 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010206
Douglas Gregord51d90d2010-04-26 20:11:03 +000010207 // If nothing changed, just retain the existing expression.
10208 if (!getDerived().AlwaysRebuild() &&
10209 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010210 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010211
John McCallb268a282010-08-23 23:25:46 +000010212 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010213 E->getLocation(),
10214 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010215}
10216
Mike Stump11289f42009-09-09 15:08:12 +000010217template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010218ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010219TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010220 // 'super' and types never change. Property never changes. Just
10221 // retain the existing expression.
10222 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010223 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010224
Douglas Gregor9faee212010-04-26 20:47:02 +000010225 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010226 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010227 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010228 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010229
Douglas Gregor9faee212010-04-26 20:47:02 +000010230 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010231
Douglas Gregor9faee212010-04-26 20:47:02 +000010232 // If nothing changed, just retain the existing expression.
10233 if (!getDerived().AlwaysRebuild() &&
10234 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010235 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010236
John McCallb7bd14f2010-12-02 01:19:52 +000010237 if (E->isExplicitProperty())
10238 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10239 E->getExplicitProperty(),
10240 E->getLocation());
10241
10242 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010243 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010244 E->getImplicitPropertyGetter(),
10245 E->getImplicitPropertySetter(),
10246 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010247}
10248
Mike Stump11289f42009-09-09 15:08:12 +000010249template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010250ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010251TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10252 // Transform the base expression.
10253 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10254 if (Base.isInvalid())
10255 return ExprError();
10256
10257 // Transform the key expression.
10258 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10259 if (Key.isInvalid())
10260 return ExprError();
10261
10262 // If nothing changed, just retain the existing expression.
10263 if (!getDerived().AlwaysRebuild() &&
10264 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010265 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010266
Chad Rosier1dcde962012-08-08 18:46:20 +000010267 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010268 Base.get(), Key.get(),
10269 E->getAtIndexMethodDecl(),
10270 E->setAtIndexMethodDecl());
10271}
10272
10273template<typename Derived>
10274ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010275TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010276 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010277 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010278 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010279 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010280
Douglas Gregord51d90d2010-04-26 20:11:03 +000010281 // If nothing changed, just retain the existing expression.
10282 if (!getDerived().AlwaysRebuild() &&
10283 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010284 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010285
John McCallb268a282010-08-23 23:25:46 +000010286 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010287 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010288 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010289}
10290
Mike Stump11289f42009-09-09 15:08:12 +000010291template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010292ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010293TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010294 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010295 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010296 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010297 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010298 SubExprs, &ArgumentChanged))
10299 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010300
Douglas Gregora16548e2009-08-11 05:31:07 +000010301 if (!getDerived().AlwaysRebuild() &&
10302 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010303 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010304
Douglas Gregora16548e2009-08-11 05:31:07 +000010305 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010306 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010307 E->getRParenLoc());
10308}
10309
Mike Stump11289f42009-09-09 15:08:12 +000010310template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010311ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010312TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10313 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10314 if (SrcExpr.isInvalid())
10315 return ExprError();
10316
10317 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10318 if (!Type)
10319 return ExprError();
10320
10321 if (!getDerived().AlwaysRebuild() &&
10322 Type == E->getTypeSourceInfo() &&
10323 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010324 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010325
10326 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10327 SrcExpr.get(), Type,
10328 E->getRParenLoc());
10329}
10330
10331template<typename Derived>
10332ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010333TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010334 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010335
Craig Topperc3ec1492014-05-26 06:22:03 +000010336 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010337 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10338
10339 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010340 blockScope->TheDecl->setBlockMissingReturnType(
10341 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010342
Chris Lattner01cf8db2011-07-20 06:58:45 +000010343 SmallVector<ParmVarDecl*, 4> params;
10344 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010345
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010346 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010347 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
10348 oldBlock->param_begin(),
10349 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010350 nullptr, paramTypes, &params)) {
10351 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010352 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010353 }
John McCall490112f2011-02-04 18:33:18 +000010354
Jordan Rosea0a86be2013-03-08 22:25:36 +000010355 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000010356 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000010357 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000010358
Jordan Rose5c382722013-03-08 21:51:21 +000010359 QualType functionType =
10360 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010361 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000010362 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000010363
10364 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000010365 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000010366 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000010367
10368 if (!oldBlock->blockMissingReturnType()) {
10369 blockScope->HasImplicitReturnType = false;
10370 blockScope->ReturnType = exprResultType;
10371 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010372
John McCall3882ace2011-01-05 12:14:39 +000010373 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000010374 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010375 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010376 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000010377 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010378 }
John McCall3882ace2011-01-05 12:14:39 +000010379
John McCall490112f2011-02-04 18:33:18 +000010380#ifndef NDEBUG
10381 // In builds with assertions, make sure that we captured everything we
10382 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010383 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010384 for (const auto &I : oldBlock->captures()) {
10385 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010386
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010387 // Ignore parameter packs.
10388 if (isa<ParmVarDecl>(oldCapture) &&
10389 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10390 continue;
John McCall490112f2011-02-04 18:33:18 +000010391
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010392 VarDecl *newCapture =
10393 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10394 oldCapture));
10395 assert(blockScope->CaptureMap.count(newCapture));
10396 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010397 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010398 }
10399#endif
10400
10401 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010402 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010403}
10404
Mike Stump11289f42009-09-09 15:08:12 +000010405template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010406ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010407TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010408 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010409}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010410
10411template<typename Derived>
10412ExprResult
10413TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010414 QualType RetTy = getDerived().TransformType(E->getType());
10415 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010416 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010417 SubExprs.reserve(E->getNumSubExprs());
10418 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10419 SubExprs, &ArgumentChanged))
10420 return ExprError();
10421
10422 if (!getDerived().AlwaysRebuild() &&
10423 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010424 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010425
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010426 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010427 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010428}
Chad Rosier1dcde962012-08-08 18:46:20 +000010429
Douglas Gregora16548e2009-08-11 05:31:07 +000010430//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010431// Type reconstruction
10432//===----------------------------------------------------------------------===//
10433
Mike Stump11289f42009-09-09 15:08:12 +000010434template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010435QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10436 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010437 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010438 getDerived().getBaseEntity());
10439}
10440
Mike Stump11289f42009-09-09 15:08:12 +000010441template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010442QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10443 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010444 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010445 getDerived().getBaseEntity());
10446}
10447
Mike Stump11289f42009-09-09 15:08:12 +000010448template<typename Derived>
10449QualType
John McCall70dd5f62009-10-30 00:06:24 +000010450TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10451 bool WrittenAsLValue,
10452 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010453 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010454 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010455}
10456
10457template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010458QualType
John McCall70dd5f62009-10-30 00:06:24 +000010459TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10460 QualType ClassType,
10461 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010462 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10463 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010464}
10465
10466template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010467QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010468TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10469 ArrayType::ArraySizeModifier SizeMod,
10470 const llvm::APInt *Size,
10471 Expr *SizeExpr,
10472 unsigned IndexTypeQuals,
10473 SourceRange BracketsRange) {
10474 if (SizeExpr || !Size)
10475 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10476 IndexTypeQuals, BracketsRange,
10477 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010478
10479 QualType Types[] = {
10480 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10481 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10482 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010483 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010484 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010485 QualType SizeType;
10486 for (unsigned I = 0; I != NumTypes; ++I)
10487 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10488 SizeType = Types[I];
10489 break;
10490 }
Mike Stump11289f42009-09-09 15:08:12 +000010491
Eli Friedman9562f392012-01-25 23:20:27 +000010492 // Note that we can return a VariableArrayType here in the case where
10493 // the element type was a dependent VariableArrayType.
10494 IntegerLiteral *ArraySize
10495 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10496 /*FIXME*/BracketsRange.getBegin());
10497 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010498 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010499 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010500}
Mike Stump11289f42009-09-09 15:08:12 +000010501
Douglas Gregord6ff3322009-08-04 16:50:30 +000010502template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010503QualType
10504TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010505 ArrayType::ArraySizeModifier SizeMod,
10506 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010507 unsigned IndexTypeQuals,
10508 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010509 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010510 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010511}
10512
10513template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010514QualType
Mike Stump11289f42009-09-09 15:08:12 +000010515TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010516 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010517 unsigned IndexTypeQuals,
10518 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010519 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010520 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010521}
Mike Stump11289f42009-09-09 15:08:12 +000010522
Douglas Gregord6ff3322009-08-04 16:50:30 +000010523template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010524QualType
10525TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010526 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010527 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010528 unsigned IndexTypeQuals,
10529 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010530 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010531 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010532 IndexTypeQuals, BracketsRange);
10533}
10534
10535template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010536QualType
10537TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010538 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010539 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010540 unsigned IndexTypeQuals,
10541 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010542 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010543 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010544 IndexTypeQuals, BracketsRange);
10545}
10546
10547template<typename Derived>
10548QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010549 unsigned NumElements,
10550 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010551 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010552 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010553}
Mike Stump11289f42009-09-09 15:08:12 +000010554
Douglas Gregord6ff3322009-08-04 16:50:30 +000010555template<typename Derived>
10556QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10557 unsigned NumElements,
10558 SourceLocation AttributeLoc) {
10559 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10560 NumElements, true);
10561 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010562 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10563 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010564 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010565}
Mike Stump11289f42009-09-09 15:08:12 +000010566
Douglas Gregord6ff3322009-08-04 16:50:30 +000010567template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010568QualType
10569TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010570 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010571 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010572 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010573}
Mike Stump11289f42009-09-09 15:08:12 +000010574
Douglas Gregord6ff3322009-08-04 16:50:30 +000010575template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010576QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10577 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010578 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010579 const FunctionProtoType::ExtProtoInfo &EPI) {
10580 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010581 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010582 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010583 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010584}
Mike Stump11289f42009-09-09 15:08:12 +000010585
Douglas Gregord6ff3322009-08-04 16:50:30 +000010586template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010587QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10588 return SemaRef.Context.getFunctionNoProtoType(T);
10589}
10590
10591template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010592QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10593 assert(D && "no decl found");
10594 if (D->isInvalidDecl()) return QualType();
10595
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010596 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010597 TypeDecl *Ty;
10598 if (isa<UsingDecl>(D)) {
10599 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010600 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010601 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10602
10603 // A valid resolved using typename decl points to exactly one type decl.
10604 assert(++Using->shadow_begin() == Using->shadow_end());
10605 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010606
John McCallb96ec562009-12-04 22:46:56 +000010607 } else {
10608 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10609 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10610 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10611 }
10612
10613 return SemaRef.Context.getTypeDeclType(Ty);
10614}
10615
10616template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010617QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10618 SourceLocation Loc) {
10619 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010620}
10621
10622template<typename Derived>
10623QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10624 return SemaRef.Context.getTypeOfType(Underlying);
10625}
10626
10627template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010628QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10629 SourceLocation Loc) {
10630 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010631}
10632
10633template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010634QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10635 UnaryTransformType::UTTKind UKind,
10636 SourceLocation Loc) {
10637 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10638}
10639
10640template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010641QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010642 TemplateName Template,
10643 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010644 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010645 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010646}
Mike Stump11289f42009-09-09 15:08:12 +000010647
Douglas Gregor1135c352009-08-06 05:28:30 +000010648template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010649QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10650 SourceLocation KWLoc) {
10651 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10652}
10653
10654template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010655TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010656TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010657 bool TemplateKW,
10658 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010659 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010660 Template);
10661}
10662
10663template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010664TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010665TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10666 const IdentifierInfo &Name,
10667 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010668 QualType ObjectType,
10669 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010670 UnqualifiedId TemplateName;
10671 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010672 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010673 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010674 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010675 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010676 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010677 /*EnteringContext=*/false,
10678 Template);
John McCall31f82722010-11-12 08:19:04 +000010679 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010680}
Mike Stump11289f42009-09-09 15:08:12 +000010681
Douglas Gregora16548e2009-08-11 05:31:07 +000010682template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010683TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010684TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010685 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010686 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010687 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010688 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010689 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010690 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010691 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010692 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010693 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010694 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010695 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010696 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010697 /*EnteringContext=*/false,
10698 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010699 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010700}
Chad Rosier1dcde962012-08-08 18:46:20 +000010701
Douglas Gregor71395fa2009-11-04 00:56:37 +000010702template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010703ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010704TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10705 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010706 Expr *OrigCallee,
10707 Expr *First,
10708 Expr *Second) {
10709 Expr *Callee = OrigCallee->IgnoreParenCasts();
10710 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010711
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010712 if (First->getObjectKind() == OK_ObjCProperty) {
10713 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10714 if (BinaryOperator::isAssignmentOp(Opc))
10715 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10716 First, Second);
10717 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10718 if (Result.isInvalid())
10719 return ExprError();
10720 First = Result.get();
10721 }
10722
10723 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10724 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10725 if (Result.isInvalid())
10726 return ExprError();
10727 Second = Result.get();
10728 }
10729
Douglas Gregora16548e2009-08-11 05:31:07 +000010730 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010731 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010732 if (!First->getType()->isOverloadableType() &&
10733 !Second->getType()->isOverloadableType())
10734 return getSema().CreateBuiltinArraySubscriptExpr(First,
10735 Callee->getLocStart(),
10736 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010737 } else if (Op == OO_Arrow) {
10738 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010739 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10740 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010741 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010742 // The argument is not of overloadable type, so try to create a
10743 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010744 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010745 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010746
John McCallb268a282010-08-23 23:25:46 +000010747 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010748 }
10749 } else {
John McCallb268a282010-08-23 23:25:46 +000010750 if (!First->getType()->isOverloadableType() &&
10751 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010752 // Neither of the arguments is an overloadable type, so try to
10753 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010754 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010755 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010756 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010757 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010758 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010759
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010760 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010761 }
10762 }
Mike Stump11289f42009-09-09 15:08:12 +000010763
10764 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010765 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010766 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010767
John McCallb268a282010-08-23 23:25:46 +000010768 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010769 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010770 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010771 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010772 // If we've resolved this to a particular non-member function, just call
10773 // that function. If we resolved it to a member function,
10774 // CreateOverloaded* will find that function for us.
10775 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10776 if (!isa<CXXMethodDecl>(ND))
10777 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000010778 }
Mike Stump11289f42009-09-09 15:08:12 +000010779
Douglas Gregora16548e2009-08-11 05:31:07 +000010780 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000010781 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000010782 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000010783
Douglas Gregora16548e2009-08-11 05:31:07 +000010784 // Create the overloaded operator invocation for unary operators.
10785 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000010786 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010787 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000010788 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010789 }
Mike Stump11289f42009-09-09 15:08:12 +000010790
Douglas Gregore9d62932011-07-15 16:25:15 +000010791 if (Op == OO_Subscript) {
10792 SourceLocation LBrace;
10793 SourceLocation RBrace;
10794
10795 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000010796 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000010797 LBrace = SourceLocation::getFromRawEncoding(
10798 NameLoc.CXXOperatorName.BeginOpNameLoc);
10799 RBrace = SourceLocation::getFromRawEncoding(
10800 NameLoc.CXXOperatorName.EndOpNameLoc);
10801 } else {
10802 LBrace = Callee->getLocStart();
10803 RBrace = OpLoc;
10804 }
10805
10806 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10807 First, Second);
10808 }
Sebastian Redladba46e2009-10-29 20:17:01 +000010809
Douglas Gregora16548e2009-08-11 05:31:07 +000010810 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000010811 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010812 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000010813 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10814 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010815 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010816
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010817 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010818}
Mike Stump11289f42009-09-09 15:08:12 +000010819
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010820template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010821ExprResult
John McCallb268a282010-08-23 23:25:46 +000010822TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010823 SourceLocation OperatorLoc,
10824 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010825 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010826 TypeSourceInfo *ScopeType,
10827 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010828 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010829 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010830 QualType BaseType = Base->getType();
10831 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010832 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010833 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010834 !BaseType->getAs<PointerType>()->getPointeeType()
10835 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010836 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000010837 return SemaRef.BuildPseudoDestructorExpr(
10838 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
10839 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010840 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010841
Douglas Gregor678f90d2010-02-25 01:56:36 +000010842 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010843 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10844 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10845 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10846 NameInfo.setNamedTypeInfo(DestroyedType);
10847
Richard Smith8e4a3862012-05-15 06:15:11 +000010848 // The scope type is now known to be a valid nested name specifier
10849 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000010850 if (ScopeType) {
10851 if (!ScopeType->getType()->getAs<TagType>()) {
10852 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
10853 diag::err_expected_class_or_namespace)
10854 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
10855 return ExprError();
10856 }
10857 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
10858 CCLoc);
10859 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010860
Abramo Bagnara7945c982012-01-27 09:46:47 +000010861 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010862 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010863 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010864 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010865 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010866 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010867 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010868}
10869
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010870template<typename Derived>
10871StmtResult
10872TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010873 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010874 CapturedDecl *CD = S->getCapturedDecl();
10875 unsigned NumParams = CD->getNumParams();
10876 unsigned ContextParamPos = CD->getContextParamPosition();
10877 SmallVector<Sema::CapturedParamNameType, 4> Params;
10878 for (unsigned I = 0; I < NumParams; ++I) {
10879 if (I != ContextParamPos) {
10880 Params.push_back(
10881 std::make_pair(
10882 CD->getParam(I)->getName(),
10883 getDerived().TransformType(CD->getParam(I)->getType())));
10884 } else {
10885 Params.push_back(std::make_pair(StringRef(), QualType()));
10886 }
10887 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010888 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010889 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010890 StmtResult Body;
10891 {
10892 Sema::CompoundScopeRAII CompoundScope(getSema());
10893 Body = getDerived().TransformStmt(S->getCapturedStmt());
10894 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010895
10896 if (Body.isInvalid()) {
10897 getSema().ActOnCapturedRegionError();
10898 return StmtError();
10899 }
10900
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010901 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010902}
10903
Douglas Gregord6ff3322009-08-04 16:50:30 +000010904} // end namespace clang
10905
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000010906#endif