blob: 41ab5a2e9b0965f17adaf6c11680364ab576eaf5 [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 Bataev6d4ed052015-07-01 06:57:41 +00001324 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001325 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001326 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001327 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001328 return getSema().ActOnOpenMPExecutableDirective(
1329 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001330 }
1331
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001332 /// \brief Build a new OpenMP 'if' clause.
1333 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001334 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001335 /// Subclasses may override this routine to provide different behavior.
1336 OMPClause *RebuildOMPIfClause(Expr *Condition,
1337 SourceLocation StartLoc,
1338 SourceLocation LParenLoc,
1339 SourceLocation EndLoc) {
1340 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1341 LParenLoc, EndLoc);
1342 }
1343
Alexey Bataev3778b602014-07-17 07:32:53 +00001344 /// \brief Build a new OpenMP 'final' clause.
1345 ///
1346 /// By default, performs semantic analysis to build the new OpenMP clause.
1347 /// Subclasses may override this routine to provide different behavior.
1348 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1349 SourceLocation LParenLoc,
1350 SourceLocation EndLoc) {
1351 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1352 EndLoc);
1353 }
1354
Alexey Bataev568a8332014-03-06 06:15:19 +00001355 /// \brief Build a new OpenMP 'num_threads' clause.
1356 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001357 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001358 /// Subclasses may override this routine to provide different behavior.
1359 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1360 SourceLocation StartLoc,
1361 SourceLocation LParenLoc,
1362 SourceLocation EndLoc) {
1363 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1364 LParenLoc, EndLoc);
1365 }
1366
Alexey Bataev62c87d22014-03-21 04:51:18 +00001367 /// \brief Build a new OpenMP 'safelen' clause.
1368 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001369 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001370 /// Subclasses may override this routine to provide different behavior.
1371 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1372 SourceLocation LParenLoc,
1373 SourceLocation EndLoc) {
1374 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1375 }
1376
Alexander Musman8bd31e62014-05-27 15:12:19 +00001377 /// \brief Build a new OpenMP 'collapse' clause.
1378 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001379 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001380 /// Subclasses may override this routine to provide different behavior.
1381 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1382 SourceLocation LParenLoc,
1383 SourceLocation EndLoc) {
1384 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1385 EndLoc);
1386 }
1387
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001388 /// \brief Build a new OpenMP 'default' clause.
1389 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001390 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001391 /// Subclasses may override this routine to provide different behavior.
1392 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1393 SourceLocation KindKwLoc,
1394 SourceLocation StartLoc,
1395 SourceLocation LParenLoc,
1396 SourceLocation EndLoc) {
1397 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1398 StartLoc, LParenLoc, EndLoc);
1399 }
1400
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001401 /// \brief Build a new OpenMP 'proc_bind' clause.
1402 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001403 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001404 /// Subclasses may override this routine to provide different behavior.
1405 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1406 SourceLocation KindKwLoc,
1407 SourceLocation StartLoc,
1408 SourceLocation LParenLoc,
1409 SourceLocation EndLoc) {
1410 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1411 StartLoc, LParenLoc, EndLoc);
1412 }
1413
Alexey Bataev56dafe82014-06-20 07:16:17 +00001414 /// \brief Build a new OpenMP 'schedule' clause.
1415 ///
1416 /// By default, performs semantic analysis to build the new OpenMP clause.
1417 /// Subclasses may override this routine to provide different behavior.
1418 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1419 Expr *ChunkSize,
1420 SourceLocation StartLoc,
1421 SourceLocation LParenLoc,
1422 SourceLocation KindLoc,
1423 SourceLocation CommaLoc,
1424 SourceLocation EndLoc) {
1425 return getSema().ActOnOpenMPScheduleClause(
1426 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1427 }
1428
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001429 /// \brief Build a new OpenMP 'private' clause.
1430 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001431 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001432 /// Subclasses may override this routine to provide different behavior.
1433 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1434 SourceLocation StartLoc,
1435 SourceLocation LParenLoc,
1436 SourceLocation EndLoc) {
1437 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1438 EndLoc);
1439 }
1440
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001441 /// \brief Build a new OpenMP 'firstprivate' clause.
1442 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001443 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001444 /// Subclasses may override this routine to provide different behavior.
1445 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1446 SourceLocation StartLoc,
1447 SourceLocation LParenLoc,
1448 SourceLocation EndLoc) {
1449 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1450 EndLoc);
1451 }
1452
Alexander Musman1bb328c2014-06-04 13:06:39 +00001453 /// \brief Build a new OpenMP 'lastprivate' clause.
1454 ///
1455 /// By default, performs semantic analysis to build the new OpenMP clause.
1456 /// Subclasses may override this routine to provide different behavior.
1457 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1458 SourceLocation StartLoc,
1459 SourceLocation LParenLoc,
1460 SourceLocation EndLoc) {
1461 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1462 EndLoc);
1463 }
1464
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001465 /// \brief Build a new OpenMP 'shared' clause.
1466 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001467 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001468 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001469 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1470 SourceLocation StartLoc,
1471 SourceLocation LParenLoc,
1472 SourceLocation EndLoc) {
1473 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1474 EndLoc);
1475 }
1476
Alexey Bataevc5e02582014-06-16 07:08:35 +00001477 /// \brief Build a new OpenMP 'reduction' clause.
1478 ///
1479 /// By default, performs semantic analysis to build the new statement.
1480 /// Subclasses may override this routine to provide different behavior.
1481 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1482 SourceLocation StartLoc,
1483 SourceLocation LParenLoc,
1484 SourceLocation ColonLoc,
1485 SourceLocation EndLoc,
1486 CXXScopeSpec &ReductionIdScopeSpec,
1487 const DeclarationNameInfo &ReductionId) {
1488 return getSema().ActOnOpenMPReductionClause(
1489 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1490 ReductionId);
1491 }
1492
Alexander Musman8dba6642014-04-22 13:09:42 +00001493 /// \brief Build a new OpenMP 'linear' clause.
1494 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001495 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001496 /// Subclasses may override this routine to provide different behavior.
1497 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1498 SourceLocation StartLoc,
1499 SourceLocation LParenLoc,
1500 SourceLocation ColonLoc,
1501 SourceLocation EndLoc) {
1502 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1503 ColonLoc, EndLoc);
1504 }
1505
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001506 /// \brief Build a new OpenMP 'aligned' clause.
1507 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001508 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001509 /// Subclasses may override this routine to provide different behavior.
1510 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1511 SourceLocation StartLoc,
1512 SourceLocation LParenLoc,
1513 SourceLocation ColonLoc,
1514 SourceLocation EndLoc) {
1515 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1516 LParenLoc, ColonLoc, EndLoc);
1517 }
1518
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001519 /// \brief Build a new OpenMP 'copyin' clause.
1520 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001521 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001522 /// Subclasses may override this routine to provide different behavior.
1523 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1524 SourceLocation StartLoc,
1525 SourceLocation LParenLoc,
1526 SourceLocation EndLoc) {
1527 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1528 EndLoc);
1529 }
1530
Alexey Bataevbae9a792014-06-27 10:37:06 +00001531 /// \brief Build a new OpenMP 'copyprivate' clause.
1532 ///
1533 /// By default, performs semantic analysis to build the new OpenMP clause.
1534 /// Subclasses may override this routine to provide different behavior.
1535 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1536 SourceLocation StartLoc,
1537 SourceLocation LParenLoc,
1538 SourceLocation EndLoc) {
1539 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1540 EndLoc);
1541 }
1542
Alexey Bataev6125da92014-07-21 11:26:11 +00001543 /// \brief Build a new OpenMP 'flush' pseudo clause.
1544 ///
1545 /// By default, performs semantic analysis to build the new OpenMP clause.
1546 /// Subclasses may override this routine to provide different behavior.
1547 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1548 SourceLocation StartLoc,
1549 SourceLocation LParenLoc,
1550 SourceLocation EndLoc) {
1551 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1552 EndLoc);
1553 }
1554
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001555 /// \brief Build a new OpenMP 'depend' pseudo clause.
1556 ///
1557 /// By default, performs semantic analysis to build the new OpenMP clause.
1558 /// Subclasses may override this routine to provide different behavior.
1559 OMPClause *
1560 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1561 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1562 SourceLocation StartLoc, SourceLocation LParenLoc,
1563 SourceLocation EndLoc) {
1564 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1565 StartLoc, LParenLoc, EndLoc);
1566 }
1567
James Dennett2a4d13c2012-06-15 07:13:21 +00001568 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001569 ///
1570 /// By default, performs semantic analysis to build the new statement.
1571 /// Subclasses may override this routine to provide different behavior.
1572 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1573 Expr *object) {
1574 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1575 }
1576
James Dennett2a4d13c2012-06-15 07:13:21 +00001577 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001578 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001579 /// By default, performs semantic analysis to build the new statement.
1580 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001581 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001582 Expr *Object, Stmt *Body) {
1583 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001584 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001585
James Dennett2a4d13c2012-06-15 07:13:21 +00001586 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001587 ///
1588 /// By default, performs semantic analysis to build the new statement.
1589 /// Subclasses may override this routine to provide different behavior.
1590 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1591 Stmt *Body) {
1592 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1593 }
John McCall53848232011-07-27 01:07:15 +00001594
Douglas Gregorf68a5082010-04-22 23:10:45 +00001595 /// \brief Build a new Objective-C fast enumeration statement.
1596 ///
1597 /// By default, performs semantic analysis to build the new statement.
1598 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001599 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001600 Stmt *Element,
1601 Expr *Collection,
1602 SourceLocation RParenLoc,
1603 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001604 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001605 Element,
John McCallb268a282010-08-23 23:25:46 +00001606 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001607 RParenLoc);
1608 if (ForEachStmt.isInvalid())
1609 return StmtError();
1610
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001611 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001612 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001613
Douglas Gregorebe10102009-08-20 07:17:43 +00001614 /// \brief Build a new C++ exception declaration.
1615 ///
1616 /// By default, performs semantic analysis to build the new decaration.
1617 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001618 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001619 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001620 SourceLocation StartLoc,
1621 SourceLocation IdLoc,
1622 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001623 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001624 StartLoc, IdLoc, Id);
1625 if (Var)
1626 getSema().CurContext->addDecl(Var);
1627 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001628 }
1629
1630 /// \brief Build a new C++ catch statement.
1631 ///
1632 /// By default, performs semantic analysis to build the new statement.
1633 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001634 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001635 VarDecl *ExceptionDecl,
1636 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001637 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1638 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001639 }
Mike Stump11289f42009-09-09 15:08:12 +00001640
Douglas Gregorebe10102009-08-20 07:17:43 +00001641 /// \brief Build a new C++ try statement.
1642 ///
1643 /// By default, performs semantic analysis to build the new statement.
1644 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001645 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1646 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001647 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001648 }
Mike Stump11289f42009-09-09 15:08:12 +00001649
Richard Smith02e85f32011-04-14 22:09:26 +00001650 /// \brief Build a new C++0x range-based for statement.
1651 ///
1652 /// By default, performs semantic analysis to build the new statement.
1653 /// Subclasses may override this routine to provide different behavior.
1654 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1655 SourceLocation ColonLoc,
1656 Stmt *Range, Stmt *BeginEnd,
1657 Expr *Cond, Expr *Inc,
1658 Stmt *LoopVar,
1659 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001660 // If we've just learned that the range is actually an Objective-C
1661 // collection, treat this as an Objective-C fast enumeration loop.
1662 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1663 if (RangeStmt->isSingleDecl()) {
1664 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001665 if (RangeVar->isInvalidDecl())
1666 return StmtError();
1667
Douglas Gregorf7106af2013-04-08 18:40:13 +00001668 Expr *RangeExpr = RangeVar->getInit();
1669 if (!RangeExpr->isTypeDependent() &&
1670 RangeExpr->getType()->isObjCObjectPointerType())
1671 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1672 RParenLoc);
1673 }
1674 }
1675 }
1676
Richard Smith02e85f32011-04-14 22:09:26 +00001677 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001678 Cond, Inc, LoopVar, RParenLoc,
1679 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001680 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001681
1682 /// \brief Build a new C++0x range-based for statement.
1683 ///
1684 /// By default, performs semantic analysis to build the new statement.
1685 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001686 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001687 bool IsIfExists,
1688 NestedNameSpecifierLoc QualifierLoc,
1689 DeclarationNameInfo NameInfo,
1690 Stmt *Nested) {
1691 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1692 QualifierLoc, NameInfo, Nested);
1693 }
1694
Richard Smith02e85f32011-04-14 22:09:26 +00001695 /// \brief Attach body to a C++0x range-based for statement.
1696 ///
1697 /// By default, performs semantic analysis to finish the new statement.
1698 /// Subclasses may override this routine to provide different behavior.
1699 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1700 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1701 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001702
David Majnemerfad8f482013-10-15 09:33:02 +00001703 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001704 Stmt *TryBlock, Stmt *Handler) {
1705 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001706 }
1707
David Majnemerfad8f482013-10-15 09:33:02 +00001708 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001709 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001710 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001711 }
1712
David Majnemerfad8f482013-10-15 09:33:02 +00001713 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001714 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001715 }
1716
Alexey Bataevec474782014-10-09 08:45:04 +00001717 /// \brief Build a new predefined expression.
1718 ///
1719 /// By default, performs semantic analysis to build the new expression.
1720 /// Subclasses may override this routine to provide different behavior.
1721 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1722 PredefinedExpr::IdentType IT) {
1723 return getSema().BuildPredefinedExpr(Loc, IT);
1724 }
1725
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 /// \brief Build a new expression that references a declaration.
1727 ///
1728 /// By default, performs semantic analysis to build the new expression.
1729 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001730 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001731 LookupResult &R,
1732 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001733 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1734 }
1735
1736
1737 /// \brief Build a new expression that references a declaration.
1738 ///
1739 /// By default, performs semantic analysis to build the new expression.
1740 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001741 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001742 ValueDecl *VD,
1743 const DeclarationNameInfo &NameInfo,
1744 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001745 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001746 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001747
1748 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001749
1750 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001751 }
Mike Stump11289f42009-09-09 15:08:12 +00001752
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001754 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 /// By default, performs semantic analysis to build the new expression.
1756 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001757 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001758 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001759 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001760 }
1761
Douglas Gregorad8a3362009-09-04 17:36:40 +00001762 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001763 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001764 /// By default, performs semantic analysis to build the new expression.
1765 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001766 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001767 SourceLocation OperatorLoc,
1768 bool isArrow,
1769 CXXScopeSpec &SS,
1770 TypeSourceInfo *ScopeType,
1771 SourceLocation CCLoc,
1772 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001773 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001774
Douglas Gregora16548e2009-08-11 05:31:07 +00001775 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001776 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001777 /// By default, performs semantic analysis to build the new expression.
1778 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001779 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001780 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001781 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001782 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001783 }
Mike Stump11289f42009-09-09 15:08:12 +00001784
Douglas Gregor882211c2010-04-28 22:16:22 +00001785 /// \brief Build a new builtin offsetof expression.
1786 ///
1787 /// By default, performs semantic analysis to build the new expression.
1788 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001789 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001790 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001791 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001792 unsigned NumComponents,
1793 SourceLocation RParenLoc) {
1794 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1795 NumComponents, RParenLoc);
1796 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001797
1798 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001799 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001800 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001801 /// By default, performs semantic analysis to build the new expression.
1802 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001803 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1804 SourceLocation OpLoc,
1805 UnaryExprOrTypeTrait ExprKind,
1806 SourceRange R) {
1807 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001808 }
1809
Peter Collingbournee190dee2011-03-11 19:24:49 +00001810 /// \brief Build a new sizeof, alignof or vec step expression with an
1811 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001812 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001813 /// By default, performs semantic analysis to build the new expression.
1814 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001815 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1816 UnaryExprOrTypeTrait ExprKind,
1817 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001818 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001819 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001820 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001821 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001822
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001823 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001824 }
Mike Stump11289f42009-09-09 15:08:12 +00001825
Douglas Gregora16548e2009-08-11 05:31:07 +00001826 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001827 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001828 /// By default, performs semantic analysis to build the new expression.
1829 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001830 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001831 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001832 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001833 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001834 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001835 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001836 RBracketLoc);
1837 }
1838
1839 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001840 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001841 /// By default, performs semantic analysis to build the new expression.
1842 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001843 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001845 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001846 Expr *ExecConfig = nullptr) {
1847 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001848 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 }
1850
1851 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001852 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001853 /// By default, performs semantic analysis to build the new expression.
1854 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001855 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001856 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001857 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001858 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001859 const DeclarationNameInfo &MemberNameInfo,
1860 ValueDecl *Member,
1861 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001862 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001863 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001864 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1865 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001866 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001867 // We have a reference to an unnamed field. This is always the
1868 // base of an anonymous struct/union member access, i.e. the
1869 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001870 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001871 assert(Member->getType()->isRecordType() &&
1872 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001873
Richard Smithcab9a7d2011-10-26 19:06:56 +00001874 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001875 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001876 QualifierLoc.getNestedNameSpecifier(),
1877 FoundDecl, Member);
1878 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001879 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001880 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001881 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00001882 MemberExpr *ME = new (getSema().Context)
1883 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
1884 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001885 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001886 }
Mike Stump11289f42009-09-09 15:08:12 +00001887
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001888 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001889 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001890
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001891 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001892 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001893
John McCall16df1e52010-03-30 21:47:33 +00001894 // FIXME: this involves duplicating earlier analysis in a lot of
1895 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001896 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001897 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001898 R.resolveKind();
1899
John McCallb268a282010-08-23 23:25:46 +00001900 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001901 SS, TemplateKWLoc,
1902 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001903 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 }
Mike Stump11289f42009-09-09 15:08:12 +00001905
Douglas Gregora16548e2009-08-11 05:31:07 +00001906 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001907 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001908 /// By default, performs semantic analysis to build the new expression.
1909 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001910 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001911 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001912 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001913 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 }
1915
1916 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001917 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001918 /// By default, performs semantic analysis to build the new expression.
1919 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001920 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001921 SourceLocation QuestionLoc,
1922 Expr *LHS,
1923 SourceLocation ColonLoc,
1924 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001925 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1926 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 }
1928
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001930 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001931 /// By default, performs semantic analysis to build the new expression.
1932 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001933 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001934 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001936 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001937 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001938 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 }
Mike Stump11289f42009-09-09 15:08:12 +00001940
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001942 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 /// By default, performs semantic analysis to build the new expression.
1944 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001945 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001946 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001948 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001949 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001950 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 }
Mike Stump11289f42009-09-09 15:08:12 +00001952
Douglas Gregora16548e2009-08-11 05:31:07 +00001953 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001954 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001955 /// By default, performs semantic analysis to build the new expression.
1956 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001957 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001958 SourceLocation OpLoc,
1959 SourceLocation AccessorLoc,
1960 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001961
John McCall10eae182009-11-30 22:42:35 +00001962 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001963 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001964 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001965 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001966 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001967 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001968 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001969 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001970 }
Mike Stump11289f42009-09-09 15:08:12 +00001971
Douglas Gregora16548e2009-08-11 05:31:07 +00001972 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001973 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 /// By default, performs semantic analysis to build the new expression.
1975 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001976 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001977 MultiExprArg Inits,
1978 SourceLocation RBraceLoc,
1979 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001980 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001981 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001982 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001983 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001984
Douglas Gregord3d93062009-11-09 17:16:50 +00001985 // Patch in the result type we were given, which may have been computed
1986 // when the initial InitListExpr was built.
1987 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1988 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001989 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001990 }
Mike Stump11289f42009-09-09 15:08:12 +00001991
Douglas Gregora16548e2009-08-11 05:31:07 +00001992 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001993 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 /// By default, performs semantic analysis to build the new expression.
1995 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001996 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001997 MultiExprArg ArrayExprs,
1998 SourceLocation EqualOrColonLoc,
1999 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002000 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002001 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002002 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002003 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002004 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002005 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002006
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002007 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002008 }
Mike Stump11289f42009-09-09 15:08:12 +00002009
Douglas Gregora16548e2009-08-11 05:31:07 +00002010 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002011 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002012 /// By default, builds the implicit value initialization without performing
2013 /// any semantic analysis. Subclasses may override this routine to provide
2014 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002015 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002016 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002017 }
Mike Stump11289f42009-09-09 15:08:12 +00002018
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002020 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002021 /// By default, performs semantic analysis to build the new expression.
2022 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002023 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002024 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002025 SourceLocation RParenLoc) {
2026 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002027 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002028 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002029 }
2030
2031 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002032 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002033 /// By default, performs semantic analysis to build the new expression.
2034 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002035 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002036 MultiExprArg SubExprs,
2037 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002038 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002039 }
Mike Stump11289f42009-09-09 15:08:12 +00002040
Douglas Gregora16548e2009-08-11 05:31:07 +00002041 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002042 ///
2043 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002044 /// rather than attempting to map the label statement itself.
2045 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002046 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002047 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002048 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002049 }
Mike Stump11289f42009-09-09 15:08:12 +00002050
Douglas Gregora16548e2009-08-11 05:31:07 +00002051 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002052 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 /// By default, performs semantic analysis to build the new expression.
2054 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002055 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002056 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002057 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002058 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002059 }
Mike Stump11289f42009-09-09 15:08:12 +00002060
Douglas Gregora16548e2009-08-11 05:31:07 +00002061 /// \brief Build a new __builtin_choose_expr expression.
2062 ///
2063 /// By default, performs semantic analysis to build the new expression.
2064 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002065 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002066 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 SourceLocation RParenLoc) {
2068 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002069 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002070 RParenLoc);
2071 }
Mike Stump11289f42009-09-09 15:08:12 +00002072
Peter Collingbourne91147592011-04-15 00:35:48 +00002073 /// \brief Build a new generic selection expression.
2074 ///
2075 /// By default, performs semantic analysis to build the new expression.
2076 /// Subclasses may override this routine to provide different behavior.
2077 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2078 SourceLocation DefaultLoc,
2079 SourceLocation RParenLoc,
2080 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002081 ArrayRef<TypeSourceInfo *> Types,
2082 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002083 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002084 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002085 }
2086
Douglas Gregora16548e2009-08-11 05:31:07 +00002087 /// \brief Build a new overloaded operator call expression.
2088 ///
2089 /// By default, performs semantic analysis to build the new expression.
2090 /// The semantic analysis provides the behavior of template instantiation,
2091 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002092 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002093 /// argument-dependent lookup, etc. Subclasses may override this routine to
2094 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002095 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002096 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002097 Expr *Callee,
2098 Expr *First,
2099 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002100
2101 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002102 /// reinterpret_cast.
2103 ///
2104 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002105 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002106 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002107 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002108 Stmt::StmtClass Class,
2109 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002110 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002111 SourceLocation RAngleLoc,
2112 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002113 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002114 SourceLocation RParenLoc) {
2115 switch (Class) {
2116 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002117 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002118 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002119 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002120
2121 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002122 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002123 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002124 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002125
Douglas Gregora16548e2009-08-11 05:31:07 +00002126 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002127 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002128 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002129 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002130 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002131
Douglas Gregora16548e2009-08-11 05:31:07 +00002132 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002133 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002134 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002135 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002136
Douglas Gregora16548e2009-08-11 05:31:07 +00002137 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002138 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002139 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002140 }
Mike Stump11289f42009-09-09 15:08:12 +00002141
Douglas Gregora16548e2009-08-11 05:31:07 +00002142 /// \brief Build a new C++ static_cast expression.
2143 ///
2144 /// By default, performs semantic analysis to build the new expression.
2145 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002146 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002147 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002148 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002149 SourceLocation RAngleLoc,
2150 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002151 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002152 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002153 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002154 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002155 SourceRange(LAngleLoc, RAngleLoc),
2156 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002157 }
2158
2159 /// \brief Build a new C++ dynamic_cast expression.
2160 ///
2161 /// By default, performs semantic analysis to build the new expression.
2162 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002163 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002164 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002165 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002166 SourceLocation RAngleLoc,
2167 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002168 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002169 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002170 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002171 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002172 SourceRange(LAngleLoc, RAngleLoc),
2173 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002174 }
2175
2176 /// \brief Build a new C++ reinterpret_cast expression.
2177 ///
2178 /// By default, performs semantic analysis to build the new expression.
2179 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002180 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002182 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002183 SourceLocation RAngleLoc,
2184 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002185 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002187 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002188 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002189 SourceRange(LAngleLoc, RAngleLoc),
2190 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002191 }
2192
2193 /// \brief Build a new C++ const_cast expression.
2194 ///
2195 /// By default, performs semantic analysis to build the new expression.
2196 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002197 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002198 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002199 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002200 SourceLocation RAngleLoc,
2201 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002202 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002203 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002204 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002205 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002206 SourceRange(LAngleLoc, RAngleLoc),
2207 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002208 }
Mike Stump11289f42009-09-09 15:08:12 +00002209
Douglas Gregora16548e2009-08-11 05:31:07 +00002210 /// \brief Build a new C++ functional-style cast expression.
2211 ///
2212 /// By default, performs semantic analysis to build the new expression.
2213 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002214 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2215 SourceLocation LParenLoc,
2216 Expr *Sub,
2217 SourceLocation RParenLoc) {
2218 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002219 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002220 RParenLoc);
2221 }
Mike Stump11289f42009-09-09 15:08:12 +00002222
Douglas Gregora16548e2009-08-11 05:31:07 +00002223 /// \brief Build a new C++ typeid(type) expression.
2224 ///
2225 /// By default, performs semantic analysis to build the new expression.
2226 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002227 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002228 SourceLocation TypeidLoc,
2229 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002230 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002231 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002232 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 }
Mike Stump11289f42009-09-09 15:08:12 +00002234
Francois Pichet9f4f2072010-09-08 12:20:18 +00002235
Douglas Gregora16548e2009-08-11 05:31:07 +00002236 /// \brief Build a new C++ typeid(expr) expression.
2237 ///
2238 /// By default, performs semantic analysis to build the new expression.
2239 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002240 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002241 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002242 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002243 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002244 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002245 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002246 }
2247
Francois Pichet9f4f2072010-09-08 12:20:18 +00002248 /// \brief Build a new C++ __uuidof(type) expression.
2249 ///
2250 /// By default, performs semantic analysis to build the new expression.
2251 /// Subclasses may override this routine to provide different behavior.
2252 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2253 SourceLocation TypeidLoc,
2254 TypeSourceInfo *Operand,
2255 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002256 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002257 RParenLoc);
2258 }
2259
2260 /// \brief Build a new C++ __uuidof(expr) expression.
2261 ///
2262 /// By default, performs semantic analysis to build the new expression.
2263 /// Subclasses may override this routine to provide different behavior.
2264 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2265 SourceLocation TypeidLoc,
2266 Expr *Operand,
2267 SourceLocation RParenLoc) {
2268 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2269 RParenLoc);
2270 }
2271
Douglas Gregora16548e2009-08-11 05:31:07 +00002272 /// \brief Build a new C++ "this" expression.
2273 ///
2274 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002275 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002276 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002277 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002278 QualType ThisType,
2279 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002280 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002281 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002282 }
2283
2284 /// \brief Build a new C++ throw expression.
2285 ///
2286 /// By default, performs semantic analysis to build the new expression.
2287 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002288 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2289 bool IsThrownVariableInScope) {
2290 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002291 }
2292
2293 /// \brief Build a new C++ default-argument expression.
2294 ///
2295 /// By default, builds a new default-argument expression, which does not
2296 /// require any semantic analysis. Subclasses may override this routine to
2297 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002298 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002299 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002300 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002301 }
2302
Richard Smith852c9db2013-04-20 22:23:05 +00002303 /// \brief Build a new C++11 default-initialization expression.
2304 ///
2305 /// By default, builds a new default field initialization expression, which
2306 /// does not require any semantic analysis. Subclasses may override this
2307 /// routine to provide different behavior.
2308 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2309 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002310 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002311 }
2312
Douglas Gregora16548e2009-08-11 05:31:07 +00002313 /// \brief Build a new C++ zero-initialization expression.
2314 ///
2315 /// By default, performs semantic analysis to build the new expression.
2316 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002317 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2318 SourceLocation LParenLoc,
2319 SourceLocation RParenLoc) {
2320 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002321 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002322 }
Mike Stump11289f42009-09-09 15:08:12 +00002323
Douglas Gregora16548e2009-08-11 05:31:07 +00002324 /// \brief Build a new C++ "new" expression.
2325 ///
2326 /// By default, performs semantic analysis to build the new expression.
2327 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002328 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002329 bool UseGlobal,
2330 SourceLocation PlacementLParen,
2331 MultiExprArg PlacementArgs,
2332 SourceLocation PlacementRParen,
2333 SourceRange TypeIdParens,
2334 QualType AllocatedType,
2335 TypeSourceInfo *AllocatedTypeInfo,
2336 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002337 SourceRange DirectInitRange,
2338 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002339 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002340 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002341 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002342 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002343 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002344 AllocatedType,
2345 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002346 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002347 DirectInitRange,
2348 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002349 }
Mike Stump11289f42009-09-09 15:08:12 +00002350
Douglas Gregora16548e2009-08-11 05:31:07 +00002351 /// \brief Build a new C++ "delete" expression.
2352 ///
2353 /// By default, performs semantic analysis to build the new expression.
2354 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002355 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002356 bool IsGlobalDelete,
2357 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002358 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002359 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002360 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002361 }
Mike Stump11289f42009-09-09 15:08:12 +00002362
Douglas Gregor29c42f22012-02-24 07:38:34 +00002363 /// \brief Build a new type trait expression.
2364 ///
2365 /// By default, performs semantic analysis to build the new expression.
2366 /// Subclasses may override this routine to provide different behavior.
2367 ExprResult RebuildTypeTrait(TypeTrait Trait,
2368 SourceLocation StartLoc,
2369 ArrayRef<TypeSourceInfo *> Args,
2370 SourceLocation RParenLoc) {
2371 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2372 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002373
John Wiegley6242b6a2011-04-28 00:16:57 +00002374 /// \brief Build a new array type trait expression.
2375 ///
2376 /// By default, performs semantic analysis to build the new expression.
2377 /// Subclasses may override this routine to provide different behavior.
2378 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2379 SourceLocation StartLoc,
2380 TypeSourceInfo *TSInfo,
2381 Expr *DimExpr,
2382 SourceLocation RParenLoc) {
2383 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2384 }
2385
John Wiegleyf9f65842011-04-25 06:54:41 +00002386 /// \brief Build a new expression trait expression.
2387 ///
2388 /// By default, performs semantic analysis to build the new expression.
2389 /// Subclasses may override this routine to provide different behavior.
2390 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2391 SourceLocation StartLoc,
2392 Expr *Queried,
2393 SourceLocation RParenLoc) {
2394 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2395 }
2396
Mike Stump11289f42009-09-09 15:08:12 +00002397 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002398 /// expression.
2399 ///
2400 /// By default, performs semantic analysis to build the new expression.
2401 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002402 ExprResult RebuildDependentScopeDeclRefExpr(
2403 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002404 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002405 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002406 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002407 bool IsAddressOfOperand,
2408 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002409 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002410 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002411
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002412 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002413 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2414 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002415
Reid Kleckner32506ed2014-06-12 23:03:48 +00002416 return getSema().BuildQualifiedDeclarationNameExpr(
2417 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002418 }
2419
2420 /// \brief Build a new template-id expression.
2421 ///
2422 /// By default, performs semantic analysis to build the new expression.
2423 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002424 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002425 SourceLocation TemplateKWLoc,
2426 LookupResult &R,
2427 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002428 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002429 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2430 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002431 }
2432
2433 /// \brief Build a new object-construction expression.
2434 ///
2435 /// By default, performs semantic analysis to build the new expression.
2436 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002437 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002438 SourceLocation Loc,
2439 CXXConstructorDecl *Constructor,
2440 bool IsElidable,
2441 MultiExprArg Args,
2442 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002443 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002444 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002445 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002446 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002447 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002448 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002449 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002450 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002451 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002452
Douglas Gregordb121ba2009-12-14 16:27:04 +00002453 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002454 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002455 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002456 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002457 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002458 RequiresZeroInit, ConstructKind,
2459 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002460 }
2461
2462 /// \brief Build a new object-construction expression.
2463 ///
2464 /// By default, performs semantic analysis to build the new expression.
2465 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002466 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2467 SourceLocation LParenLoc,
2468 MultiExprArg Args,
2469 SourceLocation RParenLoc) {
2470 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002471 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002472 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002473 RParenLoc);
2474 }
2475
2476 /// \brief Build a new object-construction expression.
2477 ///
2478 /// By default, performs semantic analysis to build the new expression.
2479 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002480 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2481 SourceLocation LParenLoc,
2482 MultiExprArg Args,
2483 SourceLocation RParenLoc) {
2484 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002485 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002486 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002487 RParenLoc);
2488 }
Mike Stump11289f42009-09-09 15:08:12 +00002489
Douglas Gregora16548e2009-08-11 05:31:07 +00002490 /// \brief Build a new member reference expression.
2491 ///
2492 /// By default, performs semantic analysis to build the new expression.
2493 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002494 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002495 QualType BaseType,
2496 bool IsArrow,
2497 SourceLocation OperatorLoc,
2498 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002499 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002500 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002501 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002502 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002503 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002504 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002505
John McCallb268a282010-08-23 23:25:46 +00002506 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002507 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002508 SS, TemplateKWLoc,
2509 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002510 MemberNameInfo,
2511 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002512 }
2513
John McCall10eae182009-11-30 22:42:35 +00002514 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002515 ///
2516 /// By default, performs semantic analysis to build the new expression.
2517 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002518 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2519 SourceLocation OperatorLoc,
2520 bool IsArrow,
2521 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002522 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002523 NamedDecl *FirstQualifierInScope,
2524 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002525 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002526 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002527 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002528
John McCallb268a282010-08-23 23:25:46 +00002529 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002530 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002531 SS, TemplateKWLoc,
2532 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002533 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002534 }
Mike Stump11289f42009-09-09 15:08:12 +00002535
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002536 /// \brief Build a new noexcept expression.
2537 ///
2538 /// By default, performs semantic analysis to build the new expression.
2539 /// Subclasses may override this routine to provide different behavior.
2540 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2541 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2542 }
2543
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002544 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002545 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2546 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002547 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002548 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002549 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002550 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2551 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002552 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002553
2554 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2555 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002556 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002557 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002558
Patrick Beard0caa3942012-04-19 00:25:12 +00002559 /// \brief Build a new Objective-C boxed expression.
2560 ///
2561 /// By default, performs semantic analysis to build the new expression.
2562 /// Subclasses may override this routine to provide different behavior.
2563 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2564 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2565 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002566
Ted Kremeneke65b0862012-03-06 20:05:56 +00002567 /// \brief Build a new Objective-C array literal.
2568 ///
2569 /// By default, performs semantic analysis to build the new expression.
2570 /// Subclasses may override this routine to provide different behavior.
2571 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2572 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002573 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002574 MultiExprArg(Elements, NumElements));
2575 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002576
2577 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002578 Expr *Base, Expr *Key,
2579 ObjCMethodDecl *getterMethod,
2580 ObjCMethodDecl *setterMethod) {
2581 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2582 getterMethod, setterMethod);
2583 }
2584
2585 /// \brief Build a new Objective-C dictionary literal.
2586 ///
2587 /// By default, performs semantic analysis to build the new expression.
2588 /// Subclasses may override this routine to provide different behavior.
2589 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2590 ObjCDictionaryElement *Elements,
2591 unsigned NumElements) {
2592 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2593 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002594
James Dennett2a4d13c2012-06-15 07:13:21 +00002595 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002596 ///
2597 /// By default, performs semantic analysis to build the new expression.
2598 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002599 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002600 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002601 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002602 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002603 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002604
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002605 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002606 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002607 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002608 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002609 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002610 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002611 MultiExprArg Args,
2612 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002613 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2614 ReceiverTypeInfo->getType(),
2615 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002616 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002617 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002618 }
2619
2620 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002621 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002622 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002623 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002624 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002625 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002626 MultiExprArg Args,
2627 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002628 return SemaRef.BuildInstanceMessage(Receiver,
2629 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002630 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002631 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002632 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002633 }
2634
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002635 /// \brief Build a new Objective-C instance/class message to 'super'.
2636 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2637 Selector Sel,
2638 ArrayRef<SourceLocation> SelectorLocs,
2639 ObjCMethodDecl *Method,
2640 SourceLocation LBracLoc,
2641 MultiExprArg Args,
2642 SourceLocation RBracLoc) {
2643 ObjCInterfaceDecl *Class = Method->getClassInterface();
2644 QualType ReceiverTy = SemaRef.Context.getObjCInterfaceType(Class);
2645
2646 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
2647 ReceiverTy,
2648 SuperLoc,
2649 Sel, Method, LBracLoc, SelectorLocs,
2650 RBracLoc, Args)
2651 : SemaRef.BuildClassMessage(nullptr,
2652 ReceiverTy,
2653 SuperLoc,
2654 Sel, Method, LBracLoc, SelectorLocs,
2655 RBracLoc, Args);
2656
2657
2658 }
2659
Douglas Gregord51d90d2010-04-26 20:11:03 +00002660 /// \brief Build a new Objective-C ivar reference expression.
2661 ///
2662 /// By default, performs semantic analysis to build the new expression.
2663 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002664 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002665 SourceLocation IvarLoc,
2666 bool IsArrow, bool IsFreeIvar) {
2667 // FIXME: We lose track of the IsFreeIvar bit.
2668 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002669 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2670 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002671 /*FIXME:*/IvarLoc, IsArrow,
2672 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002673 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002674 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002675 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002676 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002677
2678 /// \brief Build a new Objective-C property reference expression.
2679 ///
2680 /// By default, performs semantic analysis to build the new expression.
2681 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002682 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002683 ObjCPropertyDecl *Property,
2684 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002685 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002686 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2687 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2688 /*FIXME:*/PropertyLoc,
2689 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002690 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002691 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002692 NameInfo,
2693 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002694 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002695
John McCallb7bd14f2010-12-02 01:19:52 +00002696 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002697 ///
2698 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002699 /// Subclasses may override this routine to provide different behavior.
2700 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2701 ObjCMethodDecl *Getter,
2702 ObjCMethodDecl *Setter,
2703 SourceLocation PropertyLoc) {
2704 // Since these expressions can only be value-dependent, we do not
2705 // need to perform semantic analysis again.
2706 return Owned(
2707 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2708 VK_LValue, OK_ObjCProperty,
2709 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002710 }
2711
Douglas Gregord51d90d2010-04-26 20:11:03 +00002712 /// \brief Build a new Objective-C "isa" expression.
2713 ///
2714 /// By default, performs semantic analysis to build the new expression.
2715 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002716 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002717 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002718 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002719 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2720 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002721 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002722 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002723 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002724 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002725 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002726 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002727
Douglas Gregora16548e2009-08-11 05:31:07 +00002728 /// \brief Build a new shuffle vector expression.
2729 ///
2730 /// By default, performs semantic analysis to build the new expression.
2731 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002732 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002733 MultiExprArg SubExprs,
2734 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002735 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002736 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002737 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2738 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2739 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002740 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002741
Douglas Gregora16548e2009-08-11 05:31:07 +00002742 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002743 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002744 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2745 SemaRef.Context.BuiltinFnTy,
2746 VK_RValue, BuiltinLoc);
2747 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2748 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002749 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002750
2751 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002752 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002753 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002754 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002755
Douglas Gregora16548e2009-08-11 05:31:07 +00002756 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002757 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002758 }
John McCall31f82722010-11-12 08:19:04 +00002759
Hal Finkelc4d7c822013-09-18 03:29:45 +00002760 /// \brief Build a new convert vector expression.
2761 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2762 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2763 SourceLocation RParenLoc) {
2764 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2765 BuiltinLoc, RParenLoc);
2766 }
2767
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002768 /// \brief Build a new template argument pack expansion.
2769 ///
2770 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002771 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002772 /// different behavior.
2773 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002774 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002775 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002776 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002777 case TemplateArgument::Expression: {
2778 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002779 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2780 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002781 if (Result.isInvalid())
2782 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002783
Douglas Gregor98318c22011-01-03 21:37:45 +00002784 return TemplateArgumentLoc(Result.get(), Result.get());
2785 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002786
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002787 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002788 return TemplateArgumentLoc(TemplateArgument(
2789 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002790 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002791 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002792 Pattern.getTemplateNameLoc(),
2793 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002794
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002795 case TemplateArgument::Null:
2796 case TemplateArgument::Integral:
2797 case TemplateArgument::Declaration:
2798 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002799 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002800 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002801 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002802
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002803 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002804 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002805 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002806 EllipsisLoc,
2807 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002808 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2809 Expansion);
2810 break;
2811 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002812
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002813 return TemplateArgumentLoc();
2814 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002815
Douglas Gregor968f23a2011-01-03 19:31:53 +00002816 /// \brief Build a new expression pack expansion.
2817 ///
2818 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002819 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002820 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002821 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002822 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002823 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002824 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002825
Richard Smith0f0af192014-11-08 05:07:16 +00002826 /// \brief Build a new C++1z fold-expression.
2827 ///
2828 /// By default, performs semantic analysis in order to build a new fold
2829 /// expression.
2830 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
2831 BinaryOperatorKind Operator,
2832 SourceLocation EllipsisLoc, Expr *RHS,
2833 SourceLocation RParenLoc) {
2834 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
2835 RHS, RParenLoc);
2836 }
2837
2838 /// \brief Build an empty C++1z fold-expression with the given operator.
2839 ///
2840 /// By default, produces the fallback value for the fold-expression, or
2841 /// produce an error if there is no fallback value.
2842 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
2843 BinaryOperatorKind Operator) {
2844 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
2845 }
2846
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002847 /// \brief Build a new atomic operation expression.
2848 ///
2849 /// By default, performs semantic analysis to build the new expression.
2850 /// Subclasses may override this routine to provide different behavior.
2851 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2852 MultiExprArg SubExprs,
2853 QualType RetTy,
2854 AtomicExpr::AtomicOp Op,
2855 SourceLocation RParenLoc) {
2856 // Just create the expression; there is not any interesting semantic
2857 // analysis here because we can't actually build an AtomicExpr until
2858 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002859 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002860 RParenLoc);
2861 }
2862
John McCall31f82722010-11-12 08:19:04 +00002863private:
Douglas Gregor14454802011-02-25 02:25:35 +00002864 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2865 QualType ObjectType,
2866 NamedDecl *FirstQualifierInScope,
2867 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002868
2869 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2870 QualType ObjectType,
2871 NamedDecl *FirstQualifierInScope,
2872 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002873
2874 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2875 NamedDecl *FirstQualifierInScope,
2876 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002877};
Douglas Gregora16548e2009-08-11 05:31:07 +00002878
Douglas Gregorebe10102009-08-20 07:17:43 +00002879template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002880StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002881 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002882 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002883
Douglas Gregorebe10102009-08-20 07:17:43 +00002884 switch (S->getStmtClass()) {
2885 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002886
Douglas Gregorebe10102009-08-20 07:17:43 +00002887 // Transform individual statement nodes
2888#define STMT(Node, Parent) \
2889 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002890#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002891#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002892#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002893
Douglas Gregorebe10102009-08-20 07:17:43 +00002894 // Transform expressions by calling TransformExpr.
2895#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002896#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002897#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002898#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002899 {
John McCalldadc5752010-08-24 06:29:42 +00002900 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002901 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002902 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002903
Richard Smith945f8d32013-01-14 22:39:08 +00002904 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002905 }
Mike Stump11289f42009-09-09 15:08:12 +00002906 }
2907
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002908 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002909}
Mike Stump11289f42009-09-09 15:08:12 +00002910
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002911template<typename Derived>
2912OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2913 if (!S)
2914 return S;
2915
2916 switch (S->getClauseKind()) {
2917 default: break;
2918 // Transform individual clause nodes
2919#define OPENMP_CLAUSE(Name, Class) \
2920 case OMPC_ ## Name : \
2921 return getDerived().Transform ## Class(cast<Class>(S));
2922#include "clang/Basic/OpenMPKinds.def"
2923 }
2924
2925 return S;
2926}
2927
Mike Stump11289f42009-09-09 15:08:12 +00002928
Douglas Gregore922c772009-08-04 22:27:00 +00002929template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002930ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002931 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002932 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002933
2934 switch (E->getStmtClass()) {
2935 case Stmt::NoStmtClass: break;
2936#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002937#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002938#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002939 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002940#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002941 }
2942
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002943 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002944}
2945
2946template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002947ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00002948 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00002949 // Initializers are instantiated like expressions, except that various outer
2950 // layers are stripped.
2951 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002952 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002953
2954 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2955 Init = ExprTemp->getSubExpr();
2956
Richard Smithe6ca4752013-05-30 22:40:16 +00002957 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2958 Init = MTE->GetTemporaryExpr();
2959
Richard Smithd59b8322012-12-19 01:39:02 +00002960 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2961 Init = Binder->getSubExpr();
2962
2963 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2964 Init = ICE->getSubExprAsWritten();
2965
Richard Smithcc1b96d2013-06-12 22:31:48 +00002966 if (CXXStdInitializerListExpr *ILE =
2967 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00002968 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00002969
Richard Smithc6abd962014-07-25 01:12:44 +00002970 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00002971 // InitListExprs. Other forms of copy-initialization will be a no-op if
2972 // the initializer is already the right type.
2973 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00002974 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00002975 return getDerived().TransformExpr(Init);
2976
2977 // Revert value-initialization back to empty parens.
2978 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2979 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002980 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002981 Parens.getEnd());
2982 }
2983
2984 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2985 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002986 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002987 SourceLocation());
2988
2989 // Revert initialization by constructor back to a parenthesized or braced list
2990 // of expressions. Any other form of initializer can just be reused directly.
2991 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002992 return getDerived().TransformExpr(Init);
2993
Richard Smithf8adcdc2014-07-17 05:12:35 +00002994 // If the initialization implicitly converted an initializer list to a
2995 // std::initializer_list object, unwrap the std::initializer_list too.
2996 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00002997 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00002998
Richard Smithd59b8322012-12-19 01:39:02 +00002999 SmallVector<Expr*, 8> NewArgs;
3000 bool ArgChanged = false;
3001 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003002 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003003 return ExprError();
3004
3005 // If this was list initialization, revert to list form.
3006 if (Construct->isListInitialization())
3007 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3008 Construct->getLocEnd(),
3009 Construct->getType());
3010
Richard Smithd59b8322012-12-19 01:39:02 +00003011 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003012 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003013 if (Parens.isInvalid()) {
3014 // This was a variable declaration's initialization for which no initializer
3015 // was specified.
3016 assert(NewArgs.empty() &&
3017 "no parens or braces but have direct init with arguments?");
3018 return ExprEmpty();
3019 }
Richard Smithd59b8322012-12-19 01:39:02 +00003020 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3021 Parens.getEnd());
3022}
3023
3024template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00003025bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
3026 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003027 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003028 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003029 bool *ArgChanged) {
3030 for (unsigned I = 0; I != NumInputs; ++I) {
3031 // If requested, drop call arguments that need to be dropped.
3032 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3033 if (ArgChanged)
3034 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003035
Douglas Gregora3efea12011-01-03 19:04:46 +00003036 break;
3037 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003038
Douglas Gregor968f23a2011-01-03 19:31:53 +00003039 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3040 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003041
Chris Lattner01cf8db2011-07-20 06:58:45 +00003042 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003043 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3044 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003045
Douglas Gregor968f23a2011-01-03 19:31:53 +00003046 // Determine whether the set of unexpanded parameter packs can and should
3047 // be expanded.
3048 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003049 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003050 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3051 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003052 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3053 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003054 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003055 Expand, RetainExpansion,
3056 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003057 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003058
Douglas Gregor968f23a2011-01-03 19:31:53 +00003059 if (!Expand) {
3060 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003061 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003062 // expansion.
3063 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3064 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3065 if (OutPattern.isInvalid())
3066 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003067
3068 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003069 Expansion->getEllipsisLoc(),
3070 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003071 if (Out.isInvalid())
3072 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003073
Douglas Gregor968f23a2011-01-03 19:31:53 +00003074 if (ArgChanged)
3075 *ArgChanged = true;
3076 Outputs.push_back(Out.get());
3077 continue;
3078 }
John McCall542e7c62011-07-06 07:30:07 +00003079
3080 // Record right away that the argument was changed. This needs
3081 // to happen even if the array expands to nothing.
3082 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003083
Douglas Gregor968f23a2011-01-03 19:31:53 +00003084 // The transform has determined that we should perform an elementwise
3085 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003086 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003087 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3088 ExprResult Out = getDerived().TransformExpr(Pattern);
3089 if (Out.isInvalid())
3090 return true;
3091
Richard Smith9467be42014-06-06 17:33:35 +00003092 // FIXME: Can this happen? We should not try to expand the pack
3093 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003094 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003095 Out = getDerived().RebuildPackExpansion(
3096 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003097 if (Out.isInvalid())
3098 return true;
3099 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003100
Douglas Gregor968f23a2011-01-03 19:31:53 +00003101 Outputs.push_back(Out.get());
3102 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003103
Richard Smith9467be42014-06-06 17:33:35 +00003104 // If we're supposed to retain a pack expansion, do so by temporarily
3105 // forgetting the partially-substituted parameter pack.
3106 if (RetainExpansion) {
3107 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3108
3109 ExprResult Out = getDerived().TransformExpr(Pattern);
3110 if (Out.isInvalid())
3111 return true;
3112
3113 Out = getDerived().RebuildPackExpansion(
3114 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3115 if (Out.isInvalid())
3116 return true;
3117
3118 Outputs.push_back(Out.get());
3119 }
3120
Douglas Gregor968f23a2011-01-03 19:31:53 +00003121 continue;
3122 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003123
Richard Smithd59b8322012-12-19 01:39:02 +00003124 ExprResult Result =
3125 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3126 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003127 if (Result.isInvalid())
3128 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003129
Douglas Gregora3efea12011-01-03 19:04:46 +00003130 if (Result.get() != Inputs[I] && ArgChanged)
3131 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003132
3133 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003134 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003135
Douglas Gregora3efea12011-01-03 19:04:46 +00003136 return false;
3137}
3138
3139template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003140NestedNameSpecifierLoc
3141TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3142 NestedNameSpecifierLoc NNS,
3143 QualType ObjectType,
3144 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003145 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003146 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003147 Qualifier = Qualifier.getPrefix())
3148 Qualifiers.push_back(Qualifier);
3149
3150 CXXScopeSpec SS;
3151 while (!Qualifiers.empty()) {
3152 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3153 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003154
Douglas Gregor14454802011-02-25 02:25:35 +00003155 switch (QNNS->getKind()) {
3156 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003157 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003158 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003159 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003160 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003161 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003162 FirstQualifierInScope, false))
3163 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003164
Douglas Gregor14454802011-02-25 02:25:35 +00003165 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003166
Douglas Gregor14454802011-02-25 02:25:35 +00003167 case NestedNameSpecifier::Namespace: {
3168 NamespaceDecl *NS
3169 = cast_or_null<NamespaceDecl>(
3170 getDerived().TransformDecl(
3171 Q.getLocalBeginLoc(),
3172 QNNS->getAsNamespace()));
3173 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3174 break;
3175 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003176
Douglas Gregor14454802011-02-25 02:25:35 +00003177 case NestedNameSpecifier::NamespaceAlias: {
3178 NamespaceAliasDecl *Alias
3179 = cast_or_null<NamespaceAliasDecl>(
3180 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3181 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003182 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003183 Q.getLocalEndLoc());
3184 break;
3185 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003186
Douglas Gregor14454802011-02-25 02:25:35 +00003187 case NestedNameSpecifier::Global:
3188 // There is no meaningful transformation that one could perform on the
3189 // global scope.
3190 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3191 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003192
Nikola Smiljanic67860242014-09-26 00:28:20 +00003193 case NestedNameSpecifier::Super: {
3194 CXXRecordDecl *RD =
3195 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3196 SourceLocation(), QNNS->getAsRecordDecl()));
3197 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3198 break;
3199 }
3200
Douglas Gregor14454802011-02-25 02:25:35 +00003201 case NestedNameSpecifier::TypeSpecWithTemplate:
3202 case NestedNameSpecifier::TypeSpec: {
3203 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3204 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003205
Douglas Gregor14454802011-02-25 02:25:35 +00003206 if (!TL)
3207 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003208
Douglas Gregor14454802011-02-25 02:25:35 +00003209 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003210 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003211 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003212 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003213 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003214 if (TL.getType()->isEnumeralType())
3215 SemaRef.Diag(TL.getBeginLoc(),
3216 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003217 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3218 Q.getLocalEndLoc());
3219 break;
3220 }
Richard Trieude756fb2011-05-07 01:36:37 +00003221 // If the nested-name-specifier is an invalid type def, don't emit an
3222 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003223 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3224 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003225 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003226 << TL.getType() << SS.getRange();
3227 }
Douglas Gregor14454802011-02-25 02:25:35 +00003228 return NestedNameSpecifierLoc();
3229 }
Douglas Gregore16af532011-02-28 18:50:33 +00003230 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003231
Douglas Gregore16af532011-02-28 18:50:33 +00003232 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003233 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003234 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003235 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003236
Douglas Gregor14454802011-02-25 02:25:35 +00003237 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003238 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003239 !getDerived().AlwaysRebuild())
3240 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003241
3242 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003243 // nested-name-specifier, do so.
3244 if (SS.location_size() == NNS.getDataLength() &&
3245 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3246 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3247
3248 // Allocate new nested-name-specifier location information.
3249 return SS.getWithLocInContext(SemaRef.Context);
3250}
3251
3252template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003253DeclarationNameInfo
3254TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003255::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003256 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003257 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003258 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003259
3260 switch (Name.getNameKind()) {
3261 case DeclarationName::Identifier:
3262 case DeclarationName::ObjCZeroArgSelector:
3263 case DeclarationName::ObjCOneArgSelector:
3264 case DeclarationName::ObjCMultiArgSelector:
3265 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003266 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003267 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003268 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003269
Douglas Gregorf816bd72009-09-03 22:13:48 +00003270 case DeclarationName::CXXConstructorName:
3271 case DeclarationName::CXXDestructorName:
3272 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003273 TypeSourceInfo *NewTInfo;
3274 CanQualType NewCanTy;
3275 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003276 NewTInfo = getDerived().TransformType(OldTInfo);
3277 if (!NewTInfo)
3278 return DeclarationNameInfo();
3279 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003280 }
3281 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003282 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003283 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003284 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003285 if (NewT.isNull())
3286 return DeclarationNameInfo();
3287 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3288 }
Mike Stump11289f42009-09-09 15:08:12 +00003289
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003290 DeclarationName NewName
3291 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3292 NewCanTy);
3293 DeclarationNameInfo NewNameInfo(NameInfo);
3294 NewNameInfo.setName(NewName);
3295 NewNameInfo.setNamedTypeInfo(NewTInfo);
3296 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003297 }
Mike Stump11289f42009-09-09 15:08:12 +00003298 }
3299
David Blaikie83d382b2011-09-23 05:06:16 +00003300 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003301}
3302
3303template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003304TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003305TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3306 TemplateName Name,
3307 SourceLocation NameLoc,
3308 QualType ObjectType,
3309 NamedDecl *FirstQualifierInScope) {
3310 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3311 TemplateDecl *Template = QTN->getTemplateDecl();
3312 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003313
Douglas Gregor9db53502011-03-02 18:07:45 +00003314 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003315 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003316 Template));
3317 if (!TransTemplate)
3318 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003319
Douglas Gregor9db53502011-03-02 18:07:45 +00003320 if (!getDerived().AlwaysRebuild() &&
3321 SS.getScopeRep() == QTN->getQualifier() &&
3322 TransTemplate == Template)
3323 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003324
Douglas Gregor9db53502011-03-02 18:07:45 +00003325 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3326 TransTemplate);
3327 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003328
Douglas Gregor9db53502011-03-02 18:07:45 +00003329 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3330 if (SS.getScopeRep()) {
3331 // These apply to the scope specifier, not the template.
3332 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003333 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003334 }
3335
Douglas Gregor9db53502011-03-02 18:07:45 +00003336 if (!getDerived().AlwaysRebuild() &&
3337 SS.getScopeRep() == DTN->getQualifier() &&
3338 ObjectType.isNull())
3339 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003340
Douglas Gregor9db53502011-03-02 18:07:45 +00003341 if (DTN->isIdentifier()) {
3342 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003343 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003344 NameLoc,
3345 ObjectType,
3346 FirstQualifierInScope);
3347 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003348
Douglas Gregor9db53502011-03-02 18:07:45 +00003349 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3350 ObjectType);
3351 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003352
Douglas Gregor9db53502011-03-02 18:07:45 +00003353 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3354 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003355 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003356 Template));
3357 if (!TransTemplate)
3358 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003359
Douglas Gregor9db53502011-03-02 18:07:45 +00003360 if (!getDerived().AlwaysRebuild() &&
3361 TransTemplate == Template)
3362 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003363
Douglas Gregor9db53502011-03-02 18:07:45 +00003364 return TemplateName(TransTemplate);
3365 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003366
Douglas Gregor9db53502011-03-02 18:07:45 +00003367 if (SubstTemplateTemplateParmPackStorage *SubstPack
3368 = Name.getAsSubstTemplateTemplateParmPack()) {
3369 TemplateTemplateParmDecl *TransParam
3370 = cast_or_null<TemplateTemplateParmDecl>(
3371 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3372 if (!TransParam)
3373 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003374
Douglas Gregor9db53502011-03-02 18:07:45 +00003375 if (!getDerived().AlwaysRebuild() &&
3376 TransParam == SubstPack->getParameterPack())
3377 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003378
3379 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003380 SubstPack->getArgumentPack());
3381 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003382
Douglas Gregor9db53502011-03-02 18:07:45 +00003383 // These should be getting filtered out before they reach the AST.
3384 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003385}
3386
3387template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003388void TreeTransform<Derived>::InventTemplateArgumentLoc(
3389 const TemplateArgument &Arg,
3390 TemplateArgumentLoc &Output) {
3391 SourceLocation Loc = getDerived().getBaseLocation();
3392 switch (Arg.getKind()) {
3393 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003394 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003395 break;
3396
3397 case TemplateArgument::Type:
3398 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003399 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003400
John McCall0ad16662009-10-29 08:12:44 +00003401 break;
3402
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003403 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003404 case TemplateArgument::TemplateExpansion: {
3405 NestedNameSpecifierLocBuilder Builder;
3406 TemplateName Template = Arg.getAsTemplate();
3407 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3408 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3409 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3410 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003411
Douglas Gregor9d802122011-03-02 17:09:35 +00003412 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003413 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003414 Builder.getWithLocInContext(SemaRef.Context),
3415 Loc);
3416 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003417 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003418 Builder.getWithLocInContext(SemaRef.Context),
3419 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003420
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003421 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003422 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003423
John McCall0ad16662009-10-29 08:12:44 +00003424 case TemplateArgument::Expression:
3425 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3426 break;
3427
3428 case TemplateArgument::Declaration:
3429 case TemplateArgument::Integral:
3430 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003431 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003432 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003433 break;
3434 }
3435}
3436
3437template<typename Derived>
3438bool TreeTransform<Derived>::TransformTemplateArgument(
3439 const TemplateArgumentLoc &Input,
3440 TemplateArgumentLoc &Output) {
3441 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003442 switch (Arg.getKind()) {
3443 case TemplateArgument::Null:
3444 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003445 case TemplateArgument::Pack:
3446 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003447 case TemplateArgument::NullPtr:
3448 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003449
Douglas Gregore922c772009-08-04 22:27:00 +00003450 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003451 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003452 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003453 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003454
3455 DI = getDerived().TransformType(DI);
3456 if (!DI) return true;
3457
3458 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3459 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003460 }
Mike Stump11289f42009-09-09 15:08:12 +00003461
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003462 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003463 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3464 if (QualifierLoc) {
3465 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3466 if (!QualifierLoc)
3467 return true;
3468 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003469
Douglas Gregordf846d12011-03-02 18:46:51 +00003470 CXXScopeSpec SS;
3471 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003472 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003473 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3474 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003475 if (Template.isNull())
3476 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003477
Douglas Gregor9d802122011-03-02 17:09:35 +00003478 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003479 Input.getTemplateNameLoc());
3480 return false;
3481 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003482
3483 case TemplateArgument::TemplateExpansion:
3484 llvm_unreachable("Caller should expand pack expansions");
3485
Douglas Gregore922c772009-08-04 22:27:00 +00003486 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003487 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003488 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003489 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003490
John McCall0ad16662009-10-29 08:12:44 +00003491 Expr *InputExpr = Input.getSourceExpression();
3492 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3493
Chris Lattnercdb591a2011-04-25 20:37:58 +00003494 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003495 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003496 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003497 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003498 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003499 }
Douglas Gregore922c772009-08-04 22:27:00 +00003500 }
Mike Stump11289f42009-09-09 15:08:12 +00003501
Douglas Gregore922c772009-08-04 22:27:00 +00003502 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003503 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003504}
3505
Douglas Gregorfe921a72010-12-20 23:36:19 +00003506/// \brief Iterator adaptor that invents template argument location information
3507/// for each of the template arguments in its underlying iterator.
3508template<typename Derived, typename InputIterator>
3509class TemplateArgumentLocInventIterator {
3510 TreeTransform<Derived> &Self;
3511 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003512
Douglas Gregorfe921a72010-12-20 23:36:19 +00003513public:
3514 typedef TemplateArgumentLoc value_type;
3515 typedef TemplateArgumentLoc reference;
3516 typedef typename std::iterator_traits<InputIterator>::difference_type
3517 difference_type;
3518 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003519
Douglas Gregorfe921a72010-12-20 23:36:19 +00003520 class pointer {
3521 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003522
Douglas Gregorfe921a72010-12-20 23:36:19 +00003523 public:
3524 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003525
Douglas Gregorfe921a72010-12-20 23:36:19 +00003526 const TemplateArgumentLoc *operator->() const { return &Arg; }
3527 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003528
Douglas Gregorfe921a72010-12-20 23:36:19 +00003529 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003530
Douglas Gregorfe921a72010-12-20 23:36:19 +00003531 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3532 InputIterator Iter)
3533 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003534
Douglas Gregorfe921a72010-12-20 23:36:19 +00003535 TemplateArgumentLocInventIterator &operator++() {
3536 ++Iter;
3537 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003538 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003539
Douglas Gregorfe921a72010-12-20 23:36:19 +00003540 TemplateArgumentLocInventIterator operator++(int) {
3541 TemplateArgumentLocInventIterator Old(*this);
3542 ++(*this);
3543 return Old;
3544 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003545
Douglas Gregorfe921a72010-12-20 23:36:19 +00003546 reference operator*() const {
3547 TemplateArgumentLoc Result;
3548 Self.InventTemplateArgumentLoc(*Iter, Result);
3549 return Result;
3550 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003551
Douglas Gregorfe921a72010-12-20 23:36:19 +00003552 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003553
Douglas Gregorfe921a72010-12-20 23:36:19 +00003554 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3555 const TemplateArgumentLocInventIterator &Y) {
3556 return X.Iter == Y.Iter;
3557 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003558
Douglas Gregorfe921a72010-12-20 23:36:19 +00003559 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3560 const TemplateArgumentLocInventIterator &Y) {
3561 return X.Iter != Y.Iter;
3562 }
3563};
Chad Rosier1dcde962012-08-08 18:46:20 +00003564
Douglas Gregor42cafa82010-12-20 17:42:22 +00003565template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003566template<typename InputIterator>
3567bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3568 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003569 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003570 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003571 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003572 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003573
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003574 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3575 // Unpack argument packs, which we translate them into separate
3576 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003577 // FIXME: We could do much better if we could guarantee that the
3578 // TemplateArgumentLocInfo for the pack expansion would be usable for
3579 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003580 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003581 TemplateArgument::pack_iterator>
3582 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003583 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003584 In.getArgument().pack_begin()),
3585 PackLocIterator(*this,
3586 In.getArgument().pack_end()),
3587 Outputs))
3588 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003589
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003590 continue;
3591 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003592
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003593 if (In.getArgument().isPackExpansion()) {
3594 // We have a pack expansion, for which we will be substituting into
3595 // the pattern.
3596 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003597 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003598 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003599 = getSema().getTemplateArgumentPackExpansionPattern(
3600 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003601
Chris Lattner01cf8db2011-07-20 06:58:45 +00003602 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003603 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3604 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003605
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003606 // Determine whether the set of unexpanded parameter packs can and should
3607 // be expanded.
3608 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003609 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003610 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003611 if (getDerived().TryExpandParameterPacks(Ellipsis,
3612 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003613 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003614 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003615 RetainExpansion,
3616 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003617 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003618
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003619 if (!Expand) {
3620 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003621 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003622 // expansion.
3623 TemplateArgumentLoc OutPattern;
3624 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3625 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3626 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003627
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003628 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3629 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003630 if (Out.getArgument().isNull())
3631 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003632
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003633 Outputs.addArgument(Out);
3634 continue;
3635 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003636
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003637 // The transform has determined that we should perform an elementwise
3638 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003639 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003640 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3641
3642 if (getDerived().TransformTemplateArgument(Pattern, Out))
3643 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003644
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003645 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003646 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3647 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003648 if (Out.getArgument().isNull())
3649 return true;
3650 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003651
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003652 Outputs.addArgument(Out);
3653 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003654
Douglas Gregor48d24112011-01-10 20:53:55 +00003655 // If we're supposed to retain a pack expansion, do so by temporarily
3656 // forgetting the partially-substituted parameter pack.
3657 if (RetainExpansion) {
3658 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003659
Douglas Gregor48d24112011-01-10 20:53:55 +00003660 if (getDerived().TransformTemplateArgument(Pattern, Out))
3661 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003662
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003663 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3664 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003665 if (Out.getArgument().isNull())
3666 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003667
Douglas Gregor48d24112011-01-10 20:53:55 +00003668 Outputs.addArgument(Out);
3669 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003670
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003671 continue;
3672 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003673
3674 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003675 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003676 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003677
Douglas Gregor42cafa82010-12-20 17:42:22 +00003678 Outputs.addArgument(Out);
3679 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003680
Douglas Gregor42cafa82010-12-20 17:42:22 +00003681 return false;
3682
3683}
3684
Douglas Gregord6ff3322009-08-04 16:50:30 +00003685//===----------------------------------------------------------------------===//
3686// Type transformation
3687//===----------------------------------------------------------------------===//
3688
3689template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003690QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003691 if (getDerived().AlreadyTransformed(T))
3692 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003693
John McCall550e0c22009-10-21 00:40:46 +00003694 // Temporary workaround. All of these transformations should
3695 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003696 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3697 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003698
John McCall31f82722010-11-12 08:19:04 +00003699 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003700
John McCall550e0c22009-10-21 00:40:46 +00003701 if (!NewDI)
3702 return QualType();
3703
3704 return NewDI->getType();
3705}
3706
3707template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003708TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003709 // Refine the base location to the type's location.
3710 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3711 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003712 if (getDerived().AlreadyTransformed(DI->getType()))
3713 return DI;
3714
3715 TypeLocBuilder TLB;
3716
3717 TypeLoc TL = DI->getTypeLoc();
3718 TLB.reserve(TL.getFullDataSize());
3719
John McCall31f82722010-11-12 08:19:04 +00003720 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003721 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003722 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003723
John McCallbcd03502009-12-07 02:54:59 +00003724 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003725}
3726
3727template<typename Derived>
3728QualType
John McCall31f82722010-11-12 08:19:04 +00003729TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003730 switch (T.getTypeLocClass()) {
3731#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003732#define TYPELOC(CLASS, PARENT) \
3733 case TypeLoc::CLASS: \
3734 return getDerived().Transform##CLASS##Type(TLB, \
3735 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003736#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003737 }
Mike Stump11289f42009-09-09 15:08:12 +00003738
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003739 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003740}
3741
3742/// FIXME: By default, this routine adds type qualifiers only to types
3743/// that can have qualifiers, and silently suppresses those qualifiers
3744/// that are not permitted (e.g., qualifiers on reference or function
3745/// types). This is the right thing for template instantiation, but
3746/// probably not for other clients.
3747template<typename Derived>
3748QualType
3749TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003750 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003751 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003752
John McCall31f82722010-11-12 08:19:04 +00003753 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003754 if (Result.isNull())
3755 return QualType();
3756
3757 // Silently suppress qualifiers if the result type can't be qualified.
3758 // FIXME: this is the right thing for template instantiation, but
3759 // probably not for other clients.
3760 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003761 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003762
John McCall31168b02011-06-15 23:02:42 +00003763 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003764 // resulting type.
3765 if (Quals.hasObjCLifetime()) {
3766 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3767 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003768 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003769 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003770 // A lifetime qualifier applied to a substituted template parameter
3771 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003772 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003773 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003774 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3775 QualType Replacement = SubstTypeParam->getReplacementType();
3776 Qualifiers Qs = Replacement.getQualifiers();
3777 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003778 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003779 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3780 Qs);
3781 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003782 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003783 Replacement);
3784 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003785 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3786 // 'auto' types behave the same way as template parameters.
3787 QualType Deduced = AutoTy->getDeducedType();
3788 Qualifiers Qs = Deduced.getQualifiers();
3789 Qs.removeObjCLifetime();
3790 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3791 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003792 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3793 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003794 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003795 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003796 // Otherwise, complain about the addition of a qualifier to an
3797 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003798 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003799 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003800 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003801
Douglas Gregore46db902011-06-17 22:11:49 +00003802 Quals.removeObjCLifetime();
3803 }
3804 }
3805 }
John McCallcb0f89a2010-06-05 06:41:15 +00003806 if (!Quals.empty()) {
3807 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003808 // BuildQualifiedType might not add qualifiers if they are invalid.
3809 if (Result.hasLocalQualifiers())
3810 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003811 // No location information to preserve.
3812 }
John McCall550e0c22009-10-21 00:40:46 +00003813
3814 return Result;
3815}
3816
Douglas Gregor14454802011-02-25 02:25:35 +00003817template<typename Derived>
3818TypeLoc
3819TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3820 QualType ObjectType,
3821 NamedDecl *UnqualLookup,
3822 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003823 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003824 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003825
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003826 TypeSourceInfo *TSI =
3827 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3828 if (TSI)
3829 return TSI->getTypeLoc();
3830 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003831}
3832
Douglas Gregor579c15f2011-03-02 18:32:08 +00003833template<typename Derived>
3834TypeSourceInfo *
3835TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3836 QualType ObjectType,
3837 NamedDecl *UnqualLookup,
3838 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003839 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003840 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003841
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003842 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3843 UnqualLookup, SS);
3844}
3845
3846template <typename Derived>
3847TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3848 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3849 CXXScopeSpec &SS) {
3850 QualType T = TL.getType();
3851 assert(!getDerived().AlreadyTransformed(T));
3852
Douglas Gregor579c15f2011-03-02 18:32:08 +00003853 TypeLocBuilder TLB;
3854 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003855
Douglas Gregor579c15f2011-03-02 18:32:08 +00003856 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003857 TemplateSpecializationTypeLoc SpecTL =
3858 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003859
Douglas Gregor579c15f2011-03-02 18:32:08 +00003860 TemplateName Template
3861 = getDerived().TransformTemplateName(SS,
3862 SpecTL.getTypePtr()->getTemplateName(),
3863 SpecTL.getTemplateNameLoc(),
3864 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003865 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003866 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003867
3868 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003869 Template);
3870 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003871 DependentTemplateSpecializationTypeLoc SpecTL =
3872 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003873
Douglas Gregor579c15f2011-03-02 18:32:08 +00003874 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003875 = getDerived().RebuildTemplateName(SS,
3876 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003877 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003878 ObjectType, UnqualLookup);
3879 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003880 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003881
3882 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003883 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003884 Template,
3885 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003886 } else {
3887 // Nothing special needs to be done for these.
3888 Result = getDerived().TransformType(TLB, TL);
3889 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003890
3891 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003892 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003893
Douglas Gregor579c15f2011-03-02 18:32:08 +00003894 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3895}
3896
John McCall550e0c22009-10-21 00:40:46 +00003897template <class TyLoc> static inline
3898QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3899 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3900 NewT.setNameLoc(T.getNameLoc());
3901 return T.getType();
3902}
3903
John McCall550e0c22009-10-21 00:40:46 +00003904template<typename Derived>
3905QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003906 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003907 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3908 NewT.setBuiltinLoc(T.getBuiltinLoc());
3909 if (T.needsExtraLocalData())
3910 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3911 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003912}
Mike Stump11289f42009-09-09 15:08:12 +00003913
Douglas Gregord6ff3322009-08-04 16:50:30 +00003914template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003915QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003916 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003917 // FIXME: recurse?
3918 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003919}
Mike Stump11289f42009-09-09 15:08:12 +00003920
Reid Kleckner0503a872013-12-05 01:23:43 +00003921template <typename Derived>
3922QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3923 AdjustedTypeLoc TL) {
3924 // Adjustments applied during transformation are handled elsewhere.
3925 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3926}
3927
Douglas Gregord6ff3322009-08-04 16:50:30 +00003928template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003929QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3930 DecayedTypeLoc TL) {
3931 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3932 if (OriginalType.isNull())
3933 return QualType();
3934
3935 QualType Result = TL.getType();
3936 if (getDerived().AlwaysRebuild() ||
3937 OriginalType != TL.getOriginalLoc().getType())
3938 Result = SemaRef.Context.getDecayedType(OriginalType);
3939 TLB.push<DecayedTypeLoc>(Result);
3940 // Nothing to set for DecayedTypeLoc.
3941 return Result;
3942}
3943
3944template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003945QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003946 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003947 QualType PointeeType
3948 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003949 if (PointeeType.isNull())
3950 return QualType();
3951
3952 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003953 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003954 // A dependent pointer type 'T *' has is being transformed such
3955 // that an Objective-C class type is being replaced for 'T'. The
3956 // resulting pointer type is an ObjCObjectPointerType, not a
3957 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003958 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003959
John McCall8b07ec22010-05-15 11:32:37 +00003960 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3961 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003962 return Result;
3963 }
John McCall31f82722010-11-12 08:19:04 +00003964
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003965 if (getDerived().AlwaysRebuild() ||
3966 PointeeType != TL.getPointeeLoc().getType()) {
3967 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3968 if (Result.isNull())
3969 return QualType();
3970 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003971
John McCall31168b02011-06-15 23:02:42 +00003972 // Objective-C ARC can add lifetime qualifiers to the type that we're
3973 // pointing to.
3974 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003975
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003976 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3977 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003978 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003979}
Mike Stump11289f42009-09-09 15:08:12 +00003980
3981template<typename Derived>
3982QualType
John McCall550e0c22009-10-21 00:40:46 +00003983TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003984 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003985 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003986 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3987 if (PointeeType.isNull())
3988 return QualType();
3989
3990 QualType Result = TL.getType();
3991 if (getDerived().AlwaysRebuild() ||
3992 PointeeType != TL.getPointeeLoc().getType()) {
3993 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003994 TL.getSigilLoc());
3995 if (Result.isNull())
3996 return QualType();
3997 }
3998
Douglas Gregor049211a2010-04-22 16:50:51 +00003999 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004000 NewT.setSigilLoc(TL.getSigilLoc());
4001 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004002}
4003
John McCall70dd5f62009-10-30 00:06:24 +00004004/// Transforms a reference type. Note that somewhat paradoxically we
4005/// don't care whether the type itself is an l-value type or an r-value
4006/// type; we only care if the type was *written* as an l-value type
4007/// or an r-value type.
4008template<typename Derived>
4009QualType
4010TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004011 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004012 const ReferenceType *T = TL.getTypePtr();
4013
4014 // Note that this works with the pointee-as-written.
4015 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4016 if (PointeeType.isNull())
4017 return QualType();
4018
4019 QualType Result = TL.getType();
4020 if (getDerived().AlwaysRebuild() ||
4021 PointeeType != T->getPointeeTypeAsWritten()) {
4022 Result = getDerived().RebuildReferenceType(PointeeType,
4023 T->isSpelledAsLValue(),
4024 TL.getSigilLoc());
4025 if (Result.isNull())
4026 return QualType();
4027 }
4028
John McCall31168b02011-06-15 23:02:42 +00004029 // Objective-C ARC can add lifetime qualifiers to the type that we're
4030 // referring to.
4031 TLB.TypeWasModifiedSafely(
4032 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4033
John McCall70dd5f62009-10-30 00:06:24 +00004034 // r-value references can be rebuilt as l-value references.
4035 ReferenceTypeLoc NewTL;
4036 if (isa<LValueReferenceType>(Result))
4037 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4038 else
4039 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4040 NewTL.setSigilLoc(TL.getSigilLoc());
4041
4042 return Result;
4043}
4044
Mike Stump11289f42009-09-09 15:08:12 +00004045template<typename Derived>
4046QualType
John McCall550e0c22009-10-21 00:40:46 +00004047TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004048 LValueReferenceTypeLoc TL) {
4049 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004050}
4051
Mike Stump11289f42009-09-09 15:08:12 +00004052template<typename Derived>
4053QualType
John McCall550e0c22009-10-21 00:40:46 +00004054TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004055 RValueReferenceTypeLoc TL) {
4056 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004057}
Mike Stump11289f42009-09-09 15:08:12 +00004058
Douglas Gregord6ff3322009-08-04 16:50:30 +00004059template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004060QualType
John McCall550e0c22009-10-21 00:40:46 +00004061TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004062 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004063 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004064 if (PointeeType.isNull())
4065 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004066
Abramo Bagnara509357842011-03-05 14:42:21 +00004067 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004068 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004069 if (OldClsTInfo) {
4070 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4071 if (!NewClsTInfo)
4072 return QualType();
4073 }
4074
4075 const MemberPointerType *T = TL.getTypePtr();
4076 QualType OldClsType = QualType(T->getClass(), 0);
4077 QualType NewClsType;
4078 if (NewClsTInfo)
4079 NewClsType = NewClsTInfo->getType();
4080 else {
4081 NewClsType = getDerived().TransformType(OldClsType);
4082 if (NewClsType.isNull())
4083 return QualType();
4084 }
Mike Stump11289f42009-09-09 15:08:12 +00004085
John McCall550e0c22009-10-21 00:40:46 +00004086 QualType Result = TL.getType();
4087 if (getDerived().AlwaysRebuild() ||
4088 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004089 NewClsType != OldClsType) {
4090 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004091 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004092 if (Result.isNull())
4093 return QualType();
4094 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004095
Reid Kleckner0503a872013-12-05 01:23:43 +00004096 // If we had to adjust the pointee type when building a member pointer, make
4097 // sure to push TypeLoc info for it.
4098 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4099 if (MPT && PointeeType != MPT->getPointeeType()) {
4100 assert(isa<AdjustedType>(MPT->getPointeeType()));
4101 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4102 }
4103
John McCall550e0c22009-10-21 00:40:46 +00004104 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4105 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004106 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004107
4108 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004109}
4110
Mike Stump11289f42009-09-09 15:08:12 +00004111template<typename Derived>
4112QualType
John McCall550e0c22009-10-21 00:40:46 +00004113TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004114 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004115 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004116 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004117 if (ElementType.isNull())
4118 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004119
John McCall550e0c22009-10-21 00:40:46 +00004120 QualType Result = TL.getType();
4121 if (getDerived().AlwaysRebuild() ||
4122 ElementType != T->getElementType()) {
4123 Result = getDerived().RebuildConstantArrayType(ElementType,
4124 T->getSizeModifier(),
4125 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004126 T->getIndexTypeCVRQualifiers(),
4127 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004128 if (Result.isNull())
4129 return QualType();
4130 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004131
4132 // We might have either a ConstantArrayType or a VariableArrayType now:
4133 // a ConstantArrayType is allowed to have an element type which is a
4134 // VariableArrayType if the type is dependent. Fortunately, all array
4135 // types have the same location layout.
4136 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004137 NewTL.setLBracketLoc(TL.getLBracketLoc());
4138 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004139
John McCall550e0c22009-10-21 00:40:46 +00004140 Expr *Size = TL.getSizeExpr();
4141 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004142 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4143 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004144 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4145 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004146 }
4147 NewTL.setSizeExpr(Size);
4148
4149 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004150}
Mike Stump11289f42009-09-09 15:08:12 +00004151
Douglas Gregord6ff3322009-08-04 16:50:30 +00004152template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004153QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004154 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004155 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004156 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004157 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004158 if (ElementType.isNull())
4159 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004160
John McCall550e0c22009-10-21 00:40:46 +00004161 QualType Result = TL.getType();
4162 if (getDerived().AlwaysRebuild() ||
4163 ElementType != T->getElementType()) {
4164 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004165 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004166 T->getIndexTypeCVRQualifiers(),
4167 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004168 if (Result.isNull())
4169 return QualType();
4170 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004171
John McCall550e0c22009-10-21 00:40:46 +00004172 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4173 NewTL.setLBracketLoc(TL.getLBracketLoc());
4174 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004175 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004176
4177 return Result;
4178}
4179
4180template<typename Derived>
4181QualType
4182TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004183 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004184 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004185 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4186 if (ElementType.isNull())
4187 return QualType();
4188
John McCalldadc5752010-08-24 06:29:42 +00004189 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004190 = getDerived().TransformExpr(T->getSizeExpr());
4191 if (SizeResult.isInvalid())
4192 return QualType();
4193
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004194 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004195
4196 QualType Result = TL.getType();
4197 if (getDerived().AlwaysRebuild() ||
4198 ElementType != T->getElementType() ||
4199 Size != T->getSizeExpr()) {
4200 Result = getDerived().RebuildVariableArrayType(ElementType,
4201 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004202 Size,
John McCall550e0c22009-10-21 00:40:46 +00004203 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004204 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004205 if (Result.isNull())
4206 return QualType();
4207 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004208
Serge Pavlov774c6d02014-02-06 03:49:11 +00004209 // We might have constant size array now, but fortunately it has the same
4210 // location layout.
4211 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004212 NewTL.setLBracketLoc(TL.getLBracketLoc());
4213 NewTL.setRBracketLoc(TL.getRBracketLoc());
4214 NewTL.setSizeExpr(Size);
4215
4216 return Result;
4217}
4218
4219template<typename Derived>
4220QualType
4221TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004222 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004223 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004224 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4225 if (ElementType.isNull())
4226 return QualType();
4227
Richard Smith764d2fe2011-12-20 02:08:33 +00004228 // Array bounds are constant expressions.
4229 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4230 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004231
John McCall33ddac02011-01-19 10:06:00 +00004232 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4233 Expr *origSize = TL.getSizeExpr();
4234 if (!origSize) origSize = T->getSizeExpr();
4235
4236 ExprResult sizeResult
4237 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004238 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004239 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004240 return QualType();
4241
John McCall33ddac02011-01-19 10:06:00 +00004242 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004243
4244 QualType Result = TL.getType();
4245 if (getDerived().AlwaysRebuild() ||
4246 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004247 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004248 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4249 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004250 size,
John McCall550e0c22009-10-21 00:40:46 +00004251 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004252 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004253 if (Result.isNull())
4254 return QualType();
4255 }
John McCall550e0c22009-10-21 00:40:46 +00004256
4257 // We might have any sort of array type now, but fortunately they
4258 // all have the same location layout.
4259 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4260 NewTL.setLBracketLoc(TL.getLBracketLoc());
4261 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004262 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004263
4264 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004265}
Mike Stump11289f42009-09-09 15:08:12 +00004266
4267template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004268QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004269 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004270 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004271 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004272
4273 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004274 QualType ElementType = getDerived().TransformType(T->getElementType());
4275 if (ElementType.isNull())
4276 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004277
Richard Smith764d2fe2011-12-20 02:08:33 +00004278 // Vector sizes are constant expressions.
4279 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4280 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004281
John McCalldadc5752010-08-24 06:29:42 +00004282 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004283 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004284 if (Size.isInvalid())
4285 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004286
John McCall550e0c22009-10-21 00:40:46 +00004287 QualType Result = TL.getType();
4288 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004289 ElementType != T->getElementType() ||
4290 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004291 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004292 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004293 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004294 if (Result.isNull())
4295 return QualType();
4296 }
John McCall550e0c22009-10-21 00:40:46 +00004297
4298 // Result might be dependent or not.
4299 if (isa<DependentSizedExtVectorType>(Result)) {
4300 DependentSizedExtVectorTypeLoc NewTL
4301 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4302 NewTL.setNameLoc(TL.getNameLoc());
4303 } else {
4304 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4305 NewTL.setNameLoc(TL.getNameLoc());
4306 }
4307
4308 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004309}
Mike Stump11289f42009-09-09 15:08:12 +00004310
4311template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004312QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004313 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004314 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004315 QualType ElementType = getDerived().TransformType(T->getElementType());
4316 if (ElementType.isNull())
4317 return QualType();
4318
John McCall550e0c22009-10-21 00:40:46 +00004319 QualType Result = TL.getType();
4320 if (getDerived().AlwaysRebuild() ||
4321 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004322 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004323 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004324 if (Result.isNull())
4325 return QualType();
4326 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004327
John McCall550e0c22009-10-21 00:40:46 +00004328 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4329 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004330
John McCall550e0c22009-10-21 00:40:46 +00004331 return Result;
4332}
4333
4334template<typename Derived>
4335QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004336 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004337 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004338 QualType ElementType = getDerived().TransformType(T->getElementType());
4339 if (ElementType.isNull())
4340 return QualType();
4341
4342 QualType Result = TL.getType();
4343 if (getDerived().AlwaysRebuild() ||
4344 ElementType != T->getElementType()) {
4345 Result = getDerived().RebuildExtVectorType(ElementType,
4346 T->getNumElements(),
4347 /*FIXME*/ SourceLocation());
4348 if (Result.isNull())
4349 return QualType();
4350 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004351
John McCall550e0c22009-10-21 00:40:46 +00004352 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4353 NewTL.setNameLoc(TL.getNameLoc());
4354
4355 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004356}
Mike Stump11289f42009-09-09 15:08:12 +00004357
David Blaikie05785d12013-02-20 22:23:23 +00004358template <typename Derived>
4359ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4360 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4361 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004362 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004363 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004364
Douglas Gregor715e4612011-01-14 22:40:04 +00004365 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004366 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004367 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004368 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004369 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004370
Douglas Gregor715e4612011-01-14 22:40:04 +00004371 TypeLocBuilder TLB;
4372 TypeLoc NewTL = OldDI->getTypeLoc();
4373 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004374
4375 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004376 OldExpansionTL.getPatternLoc());
4377 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004378 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004379
4380 Result = RebuildPackExpansionType(Result,
4381 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004382 OldExpansionTL.getEllipsisLoc(),
4383 NumExpansions);
4384 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004385 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004386
Douglas Gregor715e4612011-01-14 22:40:04 +00004387 PackExpansionTypeLoc NewExpansionTL
4388 = TLB.push<PackExpansionTypeLoc>(Result);
4389 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4390 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4391 } else
4392 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004393 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004394 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004395
John McCall8fb0d9d2011-05-01 22:35:37 +00004396 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004397 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004398
4399 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4400 OldParm->getDeclContext(),
4401 OldParm->getInnerLocStart(),
4402 OldParm->getLocation(),
4403 OldParm->getIdentifier(),
4404 NewDI->getType(),
4405 NewDI,
4406 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004407 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004408 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4409 OldParm->getFunctionScopeIndex() + indexAdjustment);
4410 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004411}
4412
4413template<typename Derived>
4414bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004415 TransformFunctionTypeParams(SourceLocation Loc,
4416 ParmVarDecl **Params, unsigned NumParams,
4417 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004418 SmallVectorImpl<QualType> &OutParamTypes,
4419 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004420 int indexAdjustment = 0;
4421
Douglas Gregordd472162011-01-07 00:20:55 +00004422 for (unsigned i = 0; i != NumParams; ++i) {
4423 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004424 assert(OldParm->getFunctionScopeIndex() == i);
4425
David Blaikie05785d12013-02-20 22:23:23 +00004426 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004427 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004428 if (OldParm->isParameterPack()) {
4429 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004430 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004431
Douglas Gregor5499af42011-01-05 23:12:31 +00004432 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004433 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004434 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004435 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4436 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004437 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4438
Douglas Gregor5499af42011-01-05 23:12:31 +00004439 // Determine whether we should expand the parameter packs.
4440 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004441 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004442 Optional<unsigned> OrigNumExpansions =
4443 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004444 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004445 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4446 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004447 Unexpanded,
4448 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004449 RetainExpansion,
4450 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004451 return true;
4452 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004453
Douglas Gregor5499af42011-01-05 23:12:31 +00004454 if (ShouldExpand) {
4455 // Expand the function parameter pack into multiple, separate
4456 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004457 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004458 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004459 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004460 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004461 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004462 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004463 OrigNumExpansions,
4464 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004465 if (!NewParm)
4466 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004467
Douglas Gregordd472162011-01-07 00:20:55 +00004468 OutParamTypes.push_back(NewParm->getType());
4469 if (PVars)
4470 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004471 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004472
4473 // If we're supposed to retain a pack expansion, do so by temporarily
4474 // forgetting the partially-substituted parameter pack.
4475 if (RetainExpansion) {
4476 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004477 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004478 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004479 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004480 OrigNumExpansions,
4481 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004482 if (!NewParm)
4483 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004484
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004485 OutParamTypes.push_back(NewParm->getType());
4486 if (PVars)
4487 PVars->push_back(NewParm);
4488 }
4489
John McCall8fb0d9d2011-05-01 22:35:37 +00004490 // The next parameter should have the same adjustment as the
4491 // last thing we pushed, but we post-incremented indexAdjustment
4492 // on every push. Also, if we push nothing, the adjustment should
4493 // go down by one.
4494 indexAdjustment--;
4495
Douglas Gregor5499af42011-01-05 23:12:31 +00004496 // We're done with the pack expansion.
4497 continue;
4498 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004499
4500 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004501 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004502 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4503 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004504 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004505 NumExpansions,
4506 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004507 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004508 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004509 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004510 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004511
John McCall58f10c32010-03-11 09:03:00 +00004512 if (!NewParm)
4513 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004514
Douglas Gregordd472162011-01-07 00:20:55 +00004515 OutParamTypes.push_back(NewParm->getType());
4516 if (PVars)
4517 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004518 continue;
4519 }
John McCall58f10c32010-03-11 09:03:00 +00004520
4521 // Deal with the possibility that we don't have a parameter
4522 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004523 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004524 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004525 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004526 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004527 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004528 = dyn_cast<PackExpansionType>(OldType)) {
4529 // We have a function parameter pack that may need to be expanded.
4530 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004531 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004532 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004533
Douglas Gregor5499af42011-01-05 23:12:31 +00004534 // Determine whether we should expand the parameter packs.
4535 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004536 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004537 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004538 Unexpanded,
4539 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004540 RetainExpansion,
4541 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004542 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004543 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004544
Douglas Gregor5499af42011-01-05 23:12:31 +00004545 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004546 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004547 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004548 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004549 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4550 QualType NewType = getDerived().TransformType(Pattern);
4551 if (NewType.isNull())
4552 return true;
John McCall58f10c32010-03-11 09:03:00 +00004553
Douglas Gregordd472162011-01-07 00:20:55 +00004554 OutParamTypes.push_back(NewType);
4555 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004556 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004557 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004558
Douglas Gregor5499af42011-01-05 23:12:31 +00004559 // We're done with the pack expansion.
4560 continue;
4561 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004562
Douglas Gregor48d24112011-01-10 20:53:55 +00004563 // If we're supposed to retain a pack expansion, do so by temporarily
4564 // forgetting the partially-substituted parameter pack.
4565 if (RetainExpansion) {
4566 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4567 QualType NewType = getDerived().TransformType(Pattern);
4568 if (NewType.isNull())
4569 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004570
Douglas Gregor48d24112011-01-10 20:53:55 +00004571 OutParamTypes.push_back(NewType);
4572 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004573 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004574 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004575
Chad Rosier1dcde962012-08-08 18:46:20 +00004576 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004577 // expansion.
4578 OldType = Expansion->getPattern();
4579 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004580 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4581 NewType = getDerived().TransformType(OldType);
4582 } else {
4583 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004584 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004585
Douglas Gregor5499af42011-01-05 23:12:31 +00004586 if (NewType.isNull())
4587 return true;
4588
4589 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004590 NewType = getSema().Context.getPackExpansionType(NewType,
4591 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004592
Douglas Gregordd472162011-01-07 00:20:55 +00004593 OutParamTypes.push_back(NewType);
4594 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004595 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004596 }
4597
John McCall8fb0d9d2011-05-01 22:35:37 +00004598#ifndef NDEBUG
4599 if (PVars) {
4600 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4601 if (ParmVarDecl *parm = (*PVars)[i])
4602 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004603 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004604#endif
4605
4606 return false;
4607}
John McCall58f10c32010-03-11 09:03:00 +00004608
4609template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004610QualType
John McCall550e0c22009-10-21 00:40:46 +00004611TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004612 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004613 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004614 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004615 return getDerived().TransformFunctionProtoType(
4616 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004617 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4618 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4619 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004620 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004621}
4622
Richard Smith2e321552014-11-12 02:00:47 +00004623template<typename Derived> template<typename Fn>
4624QualType TreeTransform<Derived>::TransformFunctionProtoType(
4625 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4626 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004627 // Transform the parameters and return type.
4628 //
Richard Smithf623c962012-04-17 00:58:00 +00004629 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004630 // When the function has a trailing return type, we instantiate the
4631 // parameters before the return type, since the return type can then refer
4632 // to the parameters themselves (via decltype, sizeof, etc.).
4633 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004634 SmallVector<QualType, 4> ParamTypes;
4635 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004636 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004637
Douglas Gregor7fb25412010-10-01 18:44:50 +00004638 QualType ResultType;
4639
Richard Smith1226c602012-08-14 22:51:13 +00004640 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004641 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004642 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004643 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004644 return QualType();
4645
Douglas Gregor3024f072012-04-16 07:05:22 +00004646 {
4647 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004648 // If a declaration declares a member function or member function
4649 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004650 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004651 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004652 // declarator.
4653 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004654
Alp Toker42a16a62014-01-25 23:51:36 +00004655 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004656 if (ResultType.isNull())
4657 return QualType();
4658 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004659 }
4660 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004661 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004662 if (ResultType.isNull())
4663 return QualType();
4664
Alp Toker9cacbab2014-01-20 20:26:09 +00004665 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004666 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004667 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004668 return QualType();
4669 }
4670
Richard Smith2e321552014-11-12 02:00:47 +00004671 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4672
4673 bool EPIChanged = false;
4674 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4675 return QualType();
4676
4677 // FIXME: Need to transform ConsumedParameters for variadic template
4678 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004679
John McCall550e0c22009-10-21 00:40:46 +00004680 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004681 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004682 T->getNumParams() != ParamTypes.size() ||
4683 !std::equal(T->param_type_begin(), T->param_type_end(),
Richard Smith2e321552014-11-12 02:00:47 +00004684 ParamTypes.begin()) || EPIChanged) {
4685 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004686 if (Result.isNull())
4687 return QualType();
4688 }
Mike Stump11289f42009-09-09 15:08:12 +00004689
John McCall550e0c22009-10-21 00:40:46 +00004690 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004691 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004692 NewTL.setLParenLoc(TL.getLParenLoc());
4693 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004694 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004695 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4696 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004697
4698 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004699}
Mike Stump11289f42009-09-09 15:08:12 +00004700
Douglas Gregord6ff3322009-08-04 16:50:30 +00004701template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004702bool TreeTransform<Derived>::TransformExceptionSpec(
4703 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4704 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4705 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4706
4707 // Instantiate a dynamic noexcept expression, if any.
4708 if (ESI.Type == EST_ComputedNoexcept) {
4709 EnterExpressionEvaluationContext Unevaluated(getSema(),
4710 Sema::ConstantEvaluated);
4711 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4712 if (NoexceptExpr.isInvalid())
4713 return true;
4714
4715 NoexceptExpr = getSema().CheckBooleanCondition(
4716 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4717 if (NoexceptExpr.isInvalid())
4718 return true;
4719
4720 if (!NoexceptExpr.get()->isValueDependent()) {
4721 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4722 NoexceptExpr.get(), nullptr,
4723 diag::err_noexcept_needs_constant_expression,
4724 /*AllowFold*/false);
4725 if (NoexceptExpr.isInvalid())
4726 return true;
4727 }
4728
4729 if (ESI.NoexceptExpr != NoexceptExpr.get())
4730 Changed = true;
4731 ESI.NoexceptExpr = NoexceptExpr.get();
4732 }
4733
4734 if (ESI.Type != EST_Dynamic)
4735 return false;
4736
4737 // Instantiate a dynamic exception specification's type.
4738 for (QualType T : ESI.Exceptions) {
4739 if (const PackExpansionType *PackExpansion =
4740 T->getAs<PackExpansionType>()) {
4741 Changed = true;
4742
4743 // We have a pack expansion. Instantiate it.
4744 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4745 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4746 Unexpanded);
4747 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4748
4749 // Determine whether the set of unexpanded parameter packs can and
4750 // should
4751 // be expanded.
4752 bool Expand = false;
4753 bool RetainExpansion = false;
4754 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4755 // FIXME: Track the location of the ellipsis (and track source location
4756 // information for the types in the exception specification in general).
4757 if (getDerived().TryExpandParameterPacks(
4758 Loc, SourceRange(), Unexpanded, Expand,
4759 RetainExpansion, NumExpansions))
4760 return true;
4761
4762 if (!Expand) {
4763 // We can't expand this pack expansion into separate arguments yet;
4764 // just substitute into the pattern and create a new pack expansion
4765 // type.
4766 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4767 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4768 if (U.isNull())
4769 return true;
4770
4771 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4772 Exceptions.push_back(U);
4773 continue;
4774 }
4775
4776 // Substitute into the pack expansion pattern for each slice of the
4777 // pack.
4778 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4779 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4780
4781 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4782 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4783 return true;
4784
4785 Exceptions.push_back(U);
4786 }
4787 } else {
4788 QualType U = getDerived().TransformType(T);
4789 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4790 return true;
4791 if (T != U)
4792 Changed = true;
4793
4794 Exceptions.push_back(U);
4795 }
4796 }
4797
4798 ESI.Exceptions = Exceptions;
4799 return false;
4800}
4801
4802template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004803QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004804 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004805 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004806 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004807 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004808 if (ResultType.isNull())
4809 return QualType();
4810
4811 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004812 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004813 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4814
4815 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004816 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004817 NewTL.setLParenLoc(TL.getLParenLoc());
4818 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004819 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004820
4821 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004822}
Mike Stump11289f42009-09-09 15:08:12 +00004823
John McCallb96ec562009-12-04 22:46:56 +00004824template<typename Derived> QualType
4825TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004826 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004827 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004828 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004829 if (!D)
4830 return QualType();
4831
4832 QualType Result = TL.getType();
4833 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4834 Result = getDerived().RebuildUnresolvedUsingType(D);
4835 if (Result.isNull())
4836 return QualType();
4837 }
4838
4839 // We might get an arbitrary type spec type back. We should at
4840 // least always get a type spec type, though.
4841 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4842 NewTL.setNameLoc(TL.getNameLoc());
4843
4844 return Result;
4845}
4846
Douglas Gregord6ff3322009-08-04 16:50:30 +00004847template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004848QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004849 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004850 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004851 TypedefNameDecl *Typedef
4852 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4853 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004854 if (!Typedef)
4855 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004856
John McCall550e0c22009-10-21 00:40:46 +00004857 QualType Result = TL.getType();
4858 if (getDerived().AlwaysRebuild() ||
4859 Typedef != T->getDecl()) {
4860 Result = getDerived().RebuildTypedefType(Typedef);
4861 if (Result.isNull())
4862 return QualType();
4863 }
Mike Stump11289f42009-09-09 15:08:12 +00004864
John McCall550e0c22009-10-21 00:40:46 +00004865 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4866 NewTL.setNameLoc(TL.getNameLoc());
4867
4868 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004869}
Mike Stump11289f42009-09-09 15:08:12 +00004870
Douglas Gregord6ff3322009-08-04 16:50:30 +00004871template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004872QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004873 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004874 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004875 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4876 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004877
John McCalldadc5752010-08-24 06:29:42 +00004878 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004879 if (E.isInvalid())
4880 return QualType();
4881
Eli Friedmane4f22df2012-02-29 04:03:55 +00004882 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4883 if (E.isInvalid())
4884 return QualType();
4885
John McCall550e0c22009-10-21 00:40:46 +00004886 QualType Result = TL.getType();
4887 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004888 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004889 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004890 if (Result.isNull())
4891 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004892 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004893 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004894
John McCall550e0c22009-10-21 00:40:46 +00004895 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004896 NewTL.setTypeofLoc(TL.getTypeofLoc());
4897 NewTL.setLParenLoc(TL.getLParenLoc());
4898 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004899
4900 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004901}
Mike Stump11289f42009-09-09 15:08:12 +00004902
4903template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004904QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004905 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004906 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4907 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4908 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004909 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004910
John McCall550e0c22009-10-21 00:40:46 +00004911 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004912 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4913 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004914 if (Result.isNull())
4915 return QualType();
4916 }
Mike Stump11289f42009-09-09 15:08:12 +00004917
John McCall550e0c22009-10-21 00:40:46 +00004918 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004919 NewTL.setTypeofLoc(TL.getTypeofLoc());
4920 NewTL.setLParenLoc(TL.getLParenLoc());
4921 NewTL.setRParenLoc(TL.getRParenLoc());
4922 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004923
4924 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004925}
Mike Stump11289f42009-09-09 15:08:12 +00004926
4927template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004928QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004929 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004930 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004931
Douglas Gregore922c772009-08-04 22:27:00 +00004932 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004933 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4934 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004935
John McCalldadc5752010-08-24 06:29:42 +00004936 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004937 if (E.isInvalid())
4938 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004939
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004940 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004941 if (E.isInvalid())
4942 return QualType();
4943
John McCall550e0c22009-10-21 00:40:46 +00004944 QualType Result = TL.getType();
4945 if (getDerived().AlwaysRebuild() ||
4946 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004947 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004948 if (Result.isNull())
4949 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004950 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004951 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004952
John McCall550e0c22009-10-21 00:40:46 +00004953 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4954 NewTL.setNameLoc(TL.getNameLoc());
4955
4956 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004957}
4958
4959template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004960QualType TreeTransform<Derived>::TransformUnaryTransformType(
4961 TypeLocBuilder &TLB,
4962 UnaryTransformTypeLoc TL) {
4963 QualType Result = TL.getType();
4964 if (Result->isDependentType()) {
4965 const UnaryTransformType *T = TL.getTypePtr();
4966 QualType NewBase =
4967 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4968 Result = getDerived().RebuildUnaryTransformType(NewBase,
4969 T->getUTTKind(),
4970 TL.getKWLoc());
4971 if (Result.isNull())
4972 return QualType();
4973 }
4974
4975 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4976 NewTL.setKWLoc(TL.getKWLoc());
4977 NewTL.setParensRange(TL.getParensRange());
4978 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4979 return Result;
4980}
4981
4982template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004983QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4984 AutoTypeLoc TL) {
4985 const AutoType *T = TL.getTypePtr();
4986 QualType OldDeduced = T->getDeducedType();
4987 QualType NewDeduced;
4988 if (!OldDeduced.isNull()) {
4989 NewDeduced = getDerived().TransformType(OldDeduced);
4990 if (NewDeduced.isNull())
4991 return QualType();
4992 }
4993
4994 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004995 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4996 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004997 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004998 if (Result.isNull())
4999 return QualType();
5000 }
5001
5002 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5003 NewTL.setNameLoc(TL.getNameLoc());
5004
5005 return Result;
5006}
5007
5008template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005009QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005010 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005011 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005012 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005013 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5014 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005015 if (!Record)
5016 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005017
John McCall550e0c22009-10-21 00:40:46 +00005018 QualType Result = TL.getType();
5019 if (getDerived().AlwaysRebuild() ||
5020 Record != T->getDecl()) {
5021 Result = getDerived().RebuildRecordType(Record);
5022 if (Result.isNull())
5023 return QualType();
5024 }
Mike Stump11289f42009-09-09 15:08:12 +00005025
John McCall550e0c22009-10-21 00:40:46 +00005026 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5027 NewTL.setNameLoc(TL.getNameLoc());
5028
5029 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005030}
Mike Stump11289f42009-09-09 15:08:12 +00005031
5032template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005033QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005034 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005035 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005036 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005037 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5038 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005039 if (!Enum)
5040 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005041
John McCall550e0c22009-10-21 00:40:46 +00005042 QualType Result = TL.getType();
5043 if (getDerived().AlwaysRebuild() ||
5044 Enum != T->getDecl()) {
5045 Result = getDerived().RebuildEnumType(Enum);
5046 if (Result.isNull())
5047 return QualType();
5048 }
Mike Stump11289f42009-09-09 15:08:12 +00005049
John McCall550e0c22009-10-21 00:40:46 +00005050 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5051 NewTL.setNameLoc(TL.getNameLoc());
5052
5053 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005054}
John McCallfcc33b02009-09-05 00:15:47 +00005055
John McCalle78aac42010-03-10 03:28:59 +00005056template<typename Derived>
5057QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5058 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005059 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005060 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5061 TL.getTypePtr()->getDecl());
5062 if (!D) return QualType();
5063
5064 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5065 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5066 return T;
5067}
5068
Douglas Gregord6ff3322009-08-04 16:50:30 +00005069template<typename Derived>
5070QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005071 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005072 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005073 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005074}
5075
Mike Stump11289f42009-09-09 15:08:12 +00005076template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005077QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005078 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005079 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005080 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005081
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005082 // Substitute into the replacement type, which itself might involve something
5083 // that needs to be transformed. This only tends to occur with default
5084 // template arguments of template template parameters.
5085 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5086 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5087 if (Replacement.isNull())
5088 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005089
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005090 // Always canonicalize the replacement type.
5091 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5092 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005093 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005094 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005095
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005096 // Propagate type-source information.
5097 SubstTemplateTypeParmTypeLoc NewTL
5098 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5099 NewTL.setNameLoc(TL.getNameLoc());
5100 return Result;
5101
John McCallcebee162009-10-18 09:09:24 +00005102}
5103
5104template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005105QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5106 TypeLocBuilder &TLB,
5107 SubstTemplateTypeParmPackTypeLoc TL) {
5108 return TransformTypeSpecType(TLB, TL);
5109}
5110
5111template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005112QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005113 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005114 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005115 const TemplateSpecializationType *T = TL.getTypePtr();
5116
Douglas Gregordf846d12011-03-02 18:46:51 +00005117 // The nested-name-specifier never matters in a TemplateSpecializationType,
5118 // because we can't have a dependent nested-name-specifier anyway.
5119 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005120 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005121 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5122 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005123 if (Template.isNull())
5124 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005125
John McCall31f82722010-11-12 08:19:04 +00005126 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5127}
5128
Eli Friedman0dfb8892011-10-06 23:00:33 +00005129template<typename Derived>
5130QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5131 AtomicTypeLoc TL) {
5132 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5133 if (ValueType.isNull())
5134 return QualType();
5135
5136 QualType Result = TL.getType();
5137 if (getDerived().AlwaysRebuild() ||
5138 ValueType != TL.getValueLoc().getType()) {
5139 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5140 if (Result.isNull())
5141 return QualType();
5142 }
5143
5144 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5145 NewTL.setKWLoc(TL.getKWLoc());
5146 NewTL.setLParenLoc(TL.getLParenLoc());
5147 NewTL.setRParenLoc(TL.getRParenLoc());
5148
5149 return Result;
5150}
5151
Chad Rosier1dcde962012-08-08 18:46:20 +00005152 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005153 /// container that provides a \c getArgLoc() member function.
5154 ///
5155 /// This iterator is intended to be used with the iterator form of
5156 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5157 template<typename ArgLocContainer>
5158 class TemplateArgumentLocContainerIterator {
5159 ArgLocContainer *Container;
5160 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005161
Douglas Gregorfe921a72010-12-20 23:36:19 +00005162 public:
5163 typedef TemplateArgumentLoc value_type;
5164 typedef TemplateArgumentLoc reference;
5165 typedef int difference_type;
5166 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005167
Douglas Gregorfe921a72010-12-20 23:36:19 +00005168 class pointer {
5169 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005170
Douglas Gregorfe921a72010-12-20 23:36:19 +00005171 public:
5172 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005173
Douglas Gregorfe921a72010-12-20 23:36:19 +00005174 const TemplateArgumentLoc *operator->() const {
5175 return &Arg;
5176 }
5177 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005178
5179
Douglas Gregorfe921a72010-12-20 23:36:19 +00005180 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005181
Douglas Gregorfe921a72010-12-20 23:36:19 +00005182 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5183 unsigned Index)
5184 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005185
Douglas Gregorfe921a72010-12-20 23:36:19 +00005186 TemplateArgumentLocContainerIterator &operator++() {
5187 ++Index;
5188 return *this;
5189 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005190
Douglas Gregorfe921a72010-12-20 23:36:19 +00005191 TemplateArgumentLocContainerIterator operator++(int) {
5192 TemplateArgumentLocContainerIterator Old(*this);
5193 ++(*this);
5194 return Old;
5195 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005196
Douglas Gregorfe921a72010-12-20 23:36:19 +00005197 TemplateArgumentLoc operator*() const {
5198 return Container->getArgLoc(Index);
5199 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005200
Douglas Gregorfe921a72010-12-20 23:36:19 +00005201 pointer operator->() const {
5202 return pointer(Container->getArgLoc(Index));
5203 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005204
Douglas Gregorfe921a72010-12-20 23:36:19 +00005205 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005206 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005207 return X.Container == Y.Container && X.Index == Y.Index;
5208 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005209
Douglas Gregorfe921a72010-12-20 23:36:19 +00005210 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005211 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005212 return !(X == Y);
5213 }
5214 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005215
5216
John McCall31f82722010-11-12 08:19:04 +00005217template <typename Derived>
5218QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5219 TypeLocBuilder &TLB,
5220 TemplateSpecializationTypeLoc TL,
5221 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005222 TemplateArgumentListInfo NewTemplateArgs;
5223 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5224 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005225 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5226 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005227 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005228 ArgIterator(TL, TL.getNumArgs()),
5229 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005230 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005231
John McCall0ad16662009-10-29 08:12:44 +00005232 // FIXME: maybe don't rebuild if all the template arguments are the same.
5233
5234 QualType Result =
5235 getDerived().RebuildTemplateSpecializationType(Template,
5236 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005237 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005238
5239 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005240 // Specializations of template template parameters are represented as
5241 // TemplateSpecializationTypes, and substitution of type alias templates
5242 // within a dependent context can transform them into
5243 // DependentTemplateSpecializationTypes.
5244 if (isa<DependentTemplateSpecializationType>(Result)) {
5245 DependentTemplateSpecializationTypeLoc NewTL
5246 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005247 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005248 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005249 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005250 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005251 NewTL.setLAngleLoc(TL.getLAngleLoc());
5252 NewTL.setRAngleLoc(TL.getRAngleLoc());
5253 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5254 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5255 return Result;
5256 }
5257
John McCall0ad16662009-10-29 08:12:44 +00005258 TemplateSpecializationTypeLoc NewTL
5259 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005260 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005261 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5262 NewTL.setLAngleLoc(TL.getLAngleLoc());
5263 NewTL.setRAngleLoc(TL.getRAngleLoc());
5264 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5265 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005266 }
Mike Stump11289f42009-09-09 15:08:12 +00005267
John McCall0ad16662009-10-29 08:12:44 +00005268 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005269}
Mike Stump11289f42009-09-09 15:08:12 +00005270
Douglas Gregor5a064722011-02-28 17:23:35 +00005271template <typename Derived>
5272QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5273 TypeLocBuilder &TLB,
5274 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005275 TemplateName Template,
5276 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005277 TemplateArgumentListInfo NewTemplateArgs;
5278 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5279 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5280 typedef TemplateArgumentLocContainerIterator<
5281 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005282 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005283 ArgIterator(TL, TL.getNumArgs()),
5284 NewTemplateArgs))
5285 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005286
Douglas Gregor5a064722011-02-28 17:23:35 +00005287 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005288
Douglas Gregor5a064722011-02-28 17:23:35 +00005289 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5290 QualType Result
5291 = getSema().Context.getDependentTemplateSpecializationType(
5292 TL.getTypePtr()->getKeyword(),
5293 DTN->getQualifier(),
5294 DTN->getIdentifier(),
5295 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005296
Douglas Gregor5a064722011-02-28 17:23:35 +00005297 DependentTemplateSpecializationTypeLoc NewTL
5298 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005299 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005300 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005301 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005302 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005303 NewTL.setLAngleLoc(TL.getLAngleLoc());
5304 NewTL.setRAngleLoc(TL.getRAngleLoc());
5305 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5306 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5307 return Result;
5308 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005309
5310 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005311 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005312 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005313 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005314
Douglas Gregor5a064722011-02-28 17:23:35 +00005315 if (!Result.isNull()) {
5316 /// FIXME: Wrap this in an elaborated-type-specifier?
5317 TemplateSpecializationTypeLoc NewTL
5318 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005319 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005320 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005321 NewTL.setLAngleLoc(TL.getLAngleLoc());
5322 NewTL.setRAngleLoc(TL.getRAngleLoc());
5323 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5324 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5325 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005326
Douglas Gregor5a064722011-02-28 17:23:35 +00005327 return Result;
5328}
5329
Mike Stump11289f42009-09-09 15:08:12 +00005330template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005331QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005332TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005333 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005334 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005335
Douglas Gregor844cb502011-03-01 18:12:44 +00005336 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005337 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005338 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005339 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005340 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5341 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005342 return QualType();
5343 }
Mike Stump11289f42009-09-09 15:08:12 +00005344
John McCall31f82722010-11-12 08:19:04 +00005345 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5346 if (NamedT.isNull())
5347 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005348
Richard Smith3f1b5d02011-05-05 21:57:07 +00005349 // C++0x [dcl.type.elab]p2:
5350 // If the identifier resolves to a typedef-name or the simple-template-id
5351 // resolves to an alias template specialization, the
5352 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005353 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5354 if (const TemplateSpecializationType *TST =
5355 NamedT->getAs<TemplateSpecializationType>()) {
5356 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005357 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5358 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005359 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5360 diag::err_tag_reference_non_tag) << 4;
5361 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5362 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005363 }
5364 }
5365
John McCall550e0c22009-10-21 00:40:46 +00005366 QualType Result = TL.getType();
5367 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005368 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005369 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005370 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005371 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005372 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005373 if (Result.isNull())
5374 return QualType();
5375 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005376
Abramo Bagnara6150c882010-05-11 21:36:43 +00005377 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005378 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005379 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005380 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005381}
Mike Stump11289f42009-09-09 15:08:12 +00005382
5383template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005384QualType TreeTransform<Derived>::TransformAttributedType(
5385 TypeLocBuilder &TLB,
5386 AttributedTypeLoc TL) {
5387 const AttributedType *oldType = TL.getTypePtr();
5388 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5389 if (modifiedType.isNull())
5390 return QualType();
5391
5392 QualType result = TL.getType();
5393
5394 // FIXME: dependent operand expressions?
5395 if (getDerived().AlwaysRebuild() ||
5396 modifiedType != oldType->getModifiedType()) {
5397 // TODO: this is really lame; we should really be rebuilding the
5398 // equivalent type from first principles.
5399 QualType equivalentType
5400 = getDerived().TransformType(oldType->getEquivalentType());
5401 if (equivalentType.isNull())
5402 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005403
5404 // Check whether we can add nullability; it is only represented as
5405 // type sugar, and therefore cannot be diagnosed in any other way.
5406 if (auto nullability = oldType->getImmediateNullability()) {
5407 if (!modifiedType->canHaveNullability()) {
5408 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005409 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005410 return QualType();
5411 }
5412 }
5413
John McCall81904512011-01-06 01:58:22 +00005414 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5415 modifiedType,
5416 equivalentType);
5417 }
5418
5419 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5420 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5421 if (TL.hasAttrOperand())
5422 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5423 if (TL.hasAttrExprOperand())
5424 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5425 else if (TL.hasAttrEnumOperand())
5426 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5427
5428 return result;
5429}
5430
5431template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005432QualType
5433TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5434 ParenTypeLoc TL) {
5435 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5436 if (Inner.isNull())
5437 return QualType();
5438
5439 QualType Result = TL.getType();
5440 if (getDerived().AlwaysRebuild() ||
5441 Inner != TL.getInnerLoc().getType()) {
5442 Result = getDerived().RebuildParenType(Inner);
5443 if (Result.isNull())
5444 return QualType();
5445 }
5446
5447 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5448 NewTL.setLParenLoc(TL.getLParenLoc());
5449 NewTL.setRParenLoc(TL.getRParenLoc());
5450 return Result;
5451}
5452
5453template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005454QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005455 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005456 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005457
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005458 NestedNameSpecifierLoc QualifierLoc
5459 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5460 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005461 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005462
John McCallc392f372010-06-11 00:33:02 +00005463 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005464 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005465 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005466 QualifierLoc,
5467 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005468 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005469 if (Result.isNull())
5470 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005471
Abramo Bagnarad7548482010-05-19 21:37:53 +00005472 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5473 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005474 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5475
Abramo Bagnarad7548482010-05-19 21:37:53 +00005476 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005477 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005478 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005479 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005480 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005481 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005482 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005483 NewTL.setNameLoc(TL.getNameLoc());
5484 }
John McCall550e0c22009-10-21 00:40:46 +00005485 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005486}
Mike Stump11289f42009-09-09 15:08:12 +00005487
Douglas Gregord6ff3322009-08-04 16:50:30 +00005488template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005489QualType TreeTransform<Derived>::
5490 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005491 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005492 NestedNameSpecifierLoc QualifierLoc;
5493 if (TL.getQualifierLoc()) {
5494 QualifierLoc
5495 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5496 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005497 return QualType();
5498 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005499
John McCall31f82722010-11-12 08:19:04 +00005500 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005501 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005502}
5503
5504template<typename Derived>
5505QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005506TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5507 DependentTemplateSpecializationTypeLoc TL,
5508 NestedNameSpecifierLoc QualifierLoc) {
5509 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005510
Douglas Gregora7a795b2011-03-01 20:11:18 +00005511 TemplateArgumentListInfo NewTemplateArgs;
5512 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5513 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005514
Douglas Gregora7a795b2011-03-01 20:11:18 +00005515 typedef TemplateArgumentLocContainerIterator<
5516 DependentTemplateSpecializationTypeLoc> ArgIterator;
5517 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5518 ArgIterator(TL, TL.getNumArgs()),
5519 NewTemplateArgs))
5520 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005521
Douglas Gregora7a795b2011-03-01 20:11:18 +00005522 QualType Result
5523 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5524 QualifierLoc,
5525 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005526 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005527 NewTemplateArgs);
5528 if (Result.isNull())
5529 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005530
Douglas Gregora7a795b2011-03-01 20:11:18 +00005531 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5532 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005533
Douglas Gregora7a795b2011-03-01 20:11:18 +00005534 // Copy information relevant to the template specialization.
5535 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005536 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005537 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005538 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005539 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5540 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005541 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005542 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005543
Douglas Gregora7a795b2011-03-01 20:11:18 +00005544 // Copy information relevant to the elaborated type.
5545 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005546 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005547 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005548 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5549 DependentTemplateSpecializationTypeLoc SpecTL
5550 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005551 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005552 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005553 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005554 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005555 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5556 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005557 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005558 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005559 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005560 TemplateSpecializationTypeLoc SpecTL
5561 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005562 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005563 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005564 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5565 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005566 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005567 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005568 }
5569 return Result;
5570}
5571
5572template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005573QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5574 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005575 QualType Pattern
5576 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005577 if (Pattern.isNull())
5578 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005579
5580 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005581 if (getDerived().AlwaysRebuild() ||
5582 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005583 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005584 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005585 TL.getEllipsisLoc(),
5586 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005587 if (Result.isNull())
5588 return QualType();
5589 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005590
Douglas Gregor822d0302011-01-12 17:07:58 +00005591 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5592 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5593 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005594}
5595
5596template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005597QualType
5598TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005599 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005600 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005601 TLB.pushFullCopy(TL);
5602 return TL.getType();
5603}
5604
5605template<typename Derived>
5606QualType
5607TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005608 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005609 // ObjCObjectType is never dependent.
5610 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005611 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005612}
Mike Stump11289f42009-09-09 15:08:12 +00005613
5614template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005615QualType
5616TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005617 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005618 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005619 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005620 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005621}
5622
Douglas Gregord6ff3322009-08-04 16:50:30 +00005623//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005624// Statement transformation
5625//===----------------------------------------------------------------------===//
5626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005627StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005628TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005629 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005630}
5631
5632template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005633StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005634TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5635 return getDerived().TransformCompoundStmt(S, false);
5636}
5637
5638template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005639StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005640TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005641 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005642 Sema::CompoundScopeRAII CompoundScope(getSema());
5643
John McCall1ababa62010-08-27 19:56:05 +00005644 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005645 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005646 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005647 for (auto *B : S->body()) {
5648 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005649 if (Result.isInvalid()) {
5650 // Immediately fail if this was a DeclStmt, since it's very
5651 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005652 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005653 return StmtError();
5654
5655 // Otherwise, just keep processing substatements and fail later.
5656 SubStmtInvalid = true;
5657 continue;
5658 }
Mike Stump11289f42009-09-09 15:08:12 +00005659
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005660 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005661 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005662 }
Mike Stump11289f42009-09-09 15:08:12 +00005663
John McCall1ababa62010-08-27 19:56:05 +00005664 if (SubStmtInvalid)
5665 return StmtError();
5666
Douglas Gregorebe10102009-08-20 07:17:43 +00005667 if (!getDerived().AlwaysRebuild() &&
5668 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005669 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005670
5671 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005672 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005673 S->getRBracLoc(),
5674 IsStmtExpr);
5675}
Mike Stump11289f42009-09-09 15:08:12 +00005676
Douglas Gregorebe10102009-08-20 07:17:43 +00005677template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005678StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005679TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005680 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005681 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005682 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5683 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005684
Eli Friedman06577382009-11-19 03:14:00 +00005685 // Transform the left-hand case value.
5686 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005687 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005688 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005689 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005690
Eli Friedman06577382009-11-19 03:14:00 +00005691 // Transform the right-hand case value (for the GNU case-range extension).
5692 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005693 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005694 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005695 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005696 }
Mike Stump11289f42009-09-09 15:08:12 +00005697
Douglas Gregorebe10102009-08-20 07:17:43 +00005698 // Build the case statement.
5699 // Case statements are always rebuilt so that they will attached to their
5700 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005701 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005702 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005703 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005704 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005705 S->getColonLoc());
5706 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005707 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005708
Douglas Gregorebe10102009-08-20 07:17:43 +00005709 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005710 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005711 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005712 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005713
Douglas Gregorebe10102009-08-20 07:17:43 +00005714 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005715 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005716}
5717
5718template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005719StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005720TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005721 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005722 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005723 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005724 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005725
Douglas Gregorebe10102009-08-20 07:17:43 +00005726 // Default statements are always rebuilt
5727 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005728 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005729}
Mike Stump11289f42009-09-09 15:08:12 +00005730
Douglas Gregorebe10102009-08-20 07:17:43 +00005731template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005732StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005733TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005734 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005735 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005736 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005737
Chris Lattnercab02a62011-02-17 20:34:02 +00005738 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5739 S->getDecl());
5740 if (!LD)
5741 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005742
5743
Douglas Gregorebe10102009-08-20 07:17:43 +00005744 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005745 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005746 cast<LabelDecl>(LD), SourceLocation(),
5747 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005748}
Mike Stump11289f42009-09-09 15:08:12 +00005749
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005750template <typename Derived>
5751const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
5752 if (!R)
5753 return R;
5754
5755 switch (R->getKind()) {
5756// Transform attributes with a pragma spelling by calling TransformXXXAttr.
5757#define ATTR(X)
5758#define PRAGMA_SPELLING_ATTR(X) \
5759 case attr::X: \
5760 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
5761#include "clang/Basic/AttrList.inc"
5762 default:
5763 return R;
5764 }
5765}
5766
5767template <typename Derived>
5768StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5769 bool AttrsChanged = false;
5770 SmallVector<const Attr *, 1> Attrs;
5771
5772 // Visit attributes and keep track if any are transformed.
5773 for (const auto *I : S->getAttrs()) {
5774 const Attr *R = getDerived().TransformAttr(I);
5775 AttrsChanged |= (I != R);
5776 Attrs.push_back(R);
5777 }
5778
Richard Smithc202b282012-04-14 00:33:13 +00005779 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5780 if (SubStmt.isInvalid())
5781 return StmtError();
5782
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005783 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00005784 return S;
5785
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005786 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00005787 SubStmt.get());
5788}
5789
5790template<typename Derived>
5791StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005792TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005793 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005794 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005795 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005796 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005797 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005798 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005799 getDerived().TransformDefinition(
5800 S->getConditionVariable()->getLocation(),
5801 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005802 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005803 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005804 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005805 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005806
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005807 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005808 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005809
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005810 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005811 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005812 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005813 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005814 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005815 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005816
John McCallb268a282010-08-23 23:25:46 +00005817 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005818 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005819 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005820
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005821 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005822 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005823 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005824
Douglas Gregorebe10102009-08-20 07:17:43 +00005825 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005826 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005827 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005828 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005829
Douglas Gregorebe10102009-08-20 07:17:43 +00005830 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005831 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005832 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005833 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005834
Douglas Gregorebe10102009-08-20 07:17:43 +00005835 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005836 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005837 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005838 Then.get() == S->getThen() &&
5839 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005840 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005841
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005842 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005843 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005844 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005845}
5846
5847template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005848StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005849TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005850 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005851 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005852 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005853 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005854 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005855 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005856 getDerived().TransformDefinition(
5857 S->getConditionVariable()->getLocation(),
5858 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005859 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005860 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005861 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005862 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005863
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005864 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005865 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005866 }
Mike Stump11289f42009-09-09 15:08:12 +00005867
Douglas Gregorebe10102009-08-20 07:17:43 +00005868 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005869 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005870 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005871 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005872 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005873 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005874
Douglas Gregorebe10102009-08-20 07:17:43 +00005875 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005876 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005877 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005878 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005879
Douglas Gregorebe10102009-08-20 07:17:43 +00005880 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005881 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5882 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005883}
Mike Stump11289f42009-09-09 15:08:12 +00005884
Douglas Gregorebe10102009-08-20 07:17:43 +00005885template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005886StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005887TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005888 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005889 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005890 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005891 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005892 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005893 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005894 getDerived().TransformDefinition(
5895 S->getConditionVariable()->getLocation(),
5896 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005897 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005898 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005899 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005900 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005901
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005902 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005903 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005904
5905 if (S->getCond()) {
5906 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005907 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5908 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005909 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005910 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005911 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005912 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005913 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005914 }
Mike Stump11289f42009-09-09 15:08:12 +00005915
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005916 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005917 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005918 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005919
Douglas Gregorebe10102009-08-20 07:17:43 +00005920 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005921 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005922 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005923 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005924
Douglas Gregorebe10102009-08-20 07:17:43 +00005925 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005926 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005927 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005928 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005929 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005930
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005931 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005932 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005933}
Mike Stump11289f42009-09-09 15:08:12 +00005934
Douglas Gregorebe10102009-08-20 07:17:43 +00005935template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005936StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005937TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005938 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005939 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005940 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005941 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005942
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005943 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005944 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005945 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005946 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005947
Douglas Gregorebe10102009-08-20 07:17:43 +00005948 if (!getDerived().AlwaysRebuild() &&
5949 Cond.get() == S->getCond() &&
5950 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005951 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005952
John McCallb268a282010-08-23 23:25:46 +00005953 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5954 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005955 S->getRParenLoc());
5956}
Mike Stump11289f42009-09-09 15:08:12 +00005957
Douglas Gregorebe10102009-08-20 07:17:43 +00005958template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005959StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005960TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005961 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005962 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005963 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005964 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005965
Douglas Gregorebe10102009-08-20 07:17:43 +00005966 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005967 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005968 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005969 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005970 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005971 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005972 getDerived().TransformDefinition(
5973 S->getConditionVariable()->getLocation(),
5974 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005975 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005976 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005977 } else {
5978 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005979
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005980 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005981 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005982
5983 if (S->getCond()) {
5984 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005985 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5986 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005987 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005988 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005989 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005990
John McCallb268a282010-08-23 23:25:46 +00005991 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005992 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005993 }
Mike Stump11289f42009-09-09 15:08:12 +00005994
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005995 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005996 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005997 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005998
Douglas Gregorebe10102009-08-20 07:17:43 +00005999 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006000 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006001 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006002 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006003
Richard Smith945f8d32013-01-14 22:39:08 +00006004 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006005 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006006 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006007
Douglas Gregorebe10102009-08-20 07:17:43 +00006008 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006009 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006010 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006011 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006012
Douglas Gregorebe10102009-08-20 07:17:43 +00006013 if (!getDerived().AlwaysRebuild() &&
6014 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00006015 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006016 Inc.get() == S->getInc() &&
6017 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006018 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006019
Douglas Gregorebe10102009-08-20 07:17:43 +00006020 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006021 Init.get(), FullCond, ConditionVar,
6022 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006023}
6024
6025template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006026StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006027TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006028 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6029 S->getLabel());
6030 if (!LD)
6031 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006032
Douglas Gregorebe10102009-08-20 07:17:43 +00006033 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006034 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006035 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006036}
6037
6038template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006039StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006040TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006041 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006042 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006043 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006044 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006045
Douglas Gregorebe10102009-08-20 07:17:43 +00006046 if (!getDerived().AlwaysRebuild() &&
6047 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006048 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006049
6050 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006051 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006052}
6053
6054template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006055StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006056TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006057 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006058}
Mike Stump11289f42009-09-09 15:08:12 +00006059
Douglas Gregorebe10102009-08-20 07:17:43 +00006060template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006061StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006062TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006063 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006064}
Mike Stump11289f42009-09-09 15:08:12 +00006065
Douglas Gregorebe10102009-08-20 07:17:43 +00006066template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006067StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006068TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006069 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6070 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006071 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006072 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006073
Mike Stump11289f42009-09-09 15:08:12 +00006074 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006075 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006076 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006077}
Mike Stump11289f42009-09-09 15:08:12 +00006078
Douglas Gregorebe10102009-08-20 07:17:43 +00006079template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006080StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006081TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006082 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006083 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006084 for (auto *D : S->decls()) {
6085 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006086 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006087 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006088
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006089 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006090 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006091
Douglas Gregorebe10102009-08-20 07:17:43 +00006092 Decls.push_back(Transformed);
6093 }
Mike Stump11289f42009-09-09 15:08:12 +00006094
Douglas Gregorebe10102009-08-20 07:17:43 +00006095 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006096 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006097
Rafael Espindolaab417692013-07-09 12:05:01 +00006098 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006099}
Mike Stump11289f42009-09-09 15:08:12 +00006100
Douglas Gregorebe10102009-08-20 07:17:43 +00006101template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006102StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006103TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006104
Benjamin Kramerf0623432012-08-23 22:51:59 +00006105 SmallVector<Expr*, 8> Constraints;
6106 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006107 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006108
John McCalldadc5752010-08-24 06:29:42 +00006109 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006110 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006111
6112 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006113
Anders Carlssonaaeef072010-01-24 05:50:09 +00006114 // Go through the outputs.
6115 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006116 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006117
Anders Carlssonaaeef072010-01-24 05:50:09 +00006118 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006119 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006120
Anders Carlssonaaeef072010-01-24 05:50:09 +00006121 // Transform the output expr.
6122 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006123 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006124 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006125 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006126
Anders Carlssonaaeef072010-01-24 05:50:09 +00006127 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006128
John McCallb268a282010-08-23 23:25:46 +00006129 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006130 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006131
Anders Carlssonaaeef072010-01-24 05:50:09 +00006132 // Go through the inputs.
6133 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006134 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006135
Anders Carlssonaaeef072010-01-24 05:50:09 +00006136 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006137 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006138
Anders Carlssonaaeef072010-01-24 05:50:09 +00006139 // Transform the input expr.
6140 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006141 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006142 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006143 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006144
Anders Carlssonaaeef072010-01-24 05:50:09 +00006145 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006146
John McCallb268a282010-08-23 23:25:46 +00006147 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006148 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006149
Anders Carlssonaaeef072010-01-24 05:50:09 +00006150 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006151 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006152
6153 // Go through the clobbers.
6154 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006155 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006156
6157 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006158 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006159 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6160 S->isVolatile(), S->getNumOutputs(),
6161 S->getNumInputs(), Names.data(),
6162 Constraints, Exprs, AsmString.get(),
6163 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006164}
6165
Chad Rosier32503022012-06-11 20:47:18 +00006166template<typename Derived>
6167StmtResult
6168TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006169 ArrayRef<Token> AsmToks =
6170 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006171
John McCallf413f5e2013-05-03 00:10:13 +00006172 bool HadError = false, HadChange = false;
6173
6174 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6175 SmallVector<Expr*, 8> TransformedExprs;
6176 TransformedExprs.reserve(SrcExprs.size());
6177 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6178 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6179 if (!Result.isUsable()) {
6180 HadError = true;
6181 } else {
6182 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006183 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006184 }
6185 }
6186
6187 if (HadError) return StmtError();
6188 if (!HadChange && !getDerived().AlwaysRebuild())
6189 return Owned(S);
6190
Chad Rosierb6f46c12012-08-15 16:53:30 +00006191 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006192 AsmToks, S->getAsmString(),
6193 S->getNumOutputs(), S->getNumInputs(),
6194 S->getAllConstraints(), S->getClobbers(),
6195 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006196}
Douglas Gregorebe10102009-08-20 07:17:43 +00006197
6198template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006199StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006200TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006201 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006202 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006203 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006204 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006205
Douglas Gregor96c79492010-04-23 22:50:49 +00006206 // Transform the @catch statements (if present).
6207 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006208 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006209 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006210 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006211 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006212 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006213 if (Catch.get() != S->getCatchStmt(I))
6214 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006215 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006216 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006217
Douglas Gregor306de2f2010-04-22 23:59:56 +00006218 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006219 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006220 if (S->getFinallyStmt()) {
6221 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6222 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006223 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006224 }
6225
6226 // If nothing changed, just retain this statement.
6227 if (!getDerived().AlwaysRebuild() &&
6228 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006229 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006230 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006231 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006232
Douglas Gregor306de2f2010-04-22 23:59:56 +00006233 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006234 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006235 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006236}
Mike Stump11289f42009-09-09 15:08:12 +00006237
Douglas Gregorebe10102009-08-20 07:17:43 +00006238template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006239StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006240TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006241 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006242 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006243 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006244 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006245 if (FromVar->getTypeSourceInfo()) {
6246 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6247 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006248 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006249 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006250
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006251 QualType T;
6252 if (TSInfo)
6253 T = TSInfo->getType();
6254 else {
6255 T = getDerived().TransformType(FromVar->getType());
6256 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006257 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006258 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006259
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006260 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6261 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006262 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006263 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006264
John McCalldadc5752010-08-24 06:29:42 +00006265 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006266 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006267 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006268
6269 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006270 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006271 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006272}
Mike Stump11289f42009-09-09 15:08:12 +00006273
Douglas Gregorebe10102009-08-20 07:17:43 +00006274template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006275StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006276TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006277 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006278 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006279 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006280 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006281
Douglas Gregor306de2f2010-04-22 23:59:56 +00006282 // If nothing changed, just retain this statement.
6283 if (!getDerived().AlwaysRebuild() &&
6284 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006285 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006286
6287 // Build a new statement.
6288 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006289 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006290}
Mike Stump11289f42009-09-09 15:08:12 +00006291
Douglas Gregorebe10102009-08-20 07:17:43 +00006292template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006293StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006294TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006295 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006296 if (S->getThrowExpr()) {
6297 Operand = getDerived().TransformExpr(S->getThrowExpr());
6298 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006299 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006300 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006301
Douglas Gregor2900c162010-04-22 21:44:01 +00006302 if (!getDerived().AlwaysRebuild() &&
6303 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006304 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006305
John McCallb268a282010-08-23 23:25:46 +00006306 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006307}
Mike Stump11289f42009-09-09 15:08:12 +00006308
Douglas Gregorebe10102009-08-20 07:17:43 +00006309template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006310StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006311TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006312 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006313 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006314 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006315 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006316 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006317 Object =
6318 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6319 Object.get());
6320 if (Object.isInvalid())
6321 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006322
Douglas Gregor6148de72010-04-22 22:01:21 +00006323 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006324 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006325 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006326 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006327
Douglas Gregor6148de72010-04-22 22:01:21 +00006328 // If nothing change, just retain the current statement.
6329 if (!getDerived().AlwaysRebuild() &&
6330 Object.get() == S->getSynchExpr() &&
6331 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006332 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006333
6334 // Build a new statement.
6335 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006336 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006337}
6338
6339template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006340StmtResult
John McCall31168b02011-06-15 23:02:42 +00006341TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6342 ObjCAutoreleasePoolStmt *S) {
6343 // Transform the body.
6344 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6345 if (Body.isInvalid())
6346 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006347
John McCall31168b02011-06-15 23:02:42 +00006348 // If nothing changed, just retain this statement.
6349 if (!getDerived().AlwaysRebuild() &&
6350 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006351 return S;
John McCall31168b02011-06-15 23:02:42 +00006352
6353 // Build a new statement.
6354 return getDerived().RebuildObjCAutoreleasePoolStmt(
6355 S->getAtLoc(), Body.get());
6356}
6357
6358template<typename Derived>
6359StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006360TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006361 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006362 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006363 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006364 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006365 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006366
Douglas Gregorf68a5082010-04-22 23:10:45 +00006367 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006368 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006369 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006370 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006371
Douglas Gregorf68a5082010-04-22 23:10:45 +00006372 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006373 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006374 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006375 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006376
Douglas Gregorf68a5082010-04-22 23:10:45 +00006377 // If nothing changed, just retain this statement.
6378 if (!getDerived().AlwaysRebuild() &&
6379 Element.get() == S->getElement() &&
6380 Collection.get() == S->getCollection() &&
6381 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006382 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006383
Douglas Gregorf68a5082010-04-22 23:10:45 +00006384 // Build a new statement.
6385 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006386 Element.get(),
6387 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006388 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006389 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006390}
6391
David Majnemer5f7efef2013-10-15 09:50:08 +00006392template <typename Derived>
6393StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006394 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006395 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006396 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6397 TypeSourceInfo *T =
6398 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006399 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006400 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006401
David Majnemer5f7efef2013-10-15 09:50:08 +00006402 Var = getDerived().RebuildExceptionDecl(
6403 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6404 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006405 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006406 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006407 }
Mike Stump11289f42009-09-09 15:08:12 +00006408
Douglas Gregorebe10102009-08-20 07:17:43 +00006409 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006410 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006411 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006412 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006413
David Majnemer5f7efef2013-10-15 09:50:08 +00006414 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006415 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006416 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006417
David Majnemer5f7efef2013-10-15 09:50:08 +00006418 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006419}
Mike Stump11289f42009-09-09 15:08:12 +00006420
David Majnemer5f7efef2013-10-15 09:50:08 +00006421template <typename Derived>
6422StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006423 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006424 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006425 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006426 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006427
Douglas Gregorebe10102009-08-20 07:17:43 +00006428 // Transform the handlers.
6429 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006430 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006431 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006432 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006433 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006434 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006435
Douglas Gregorebe10102009-08-20 07:17:43 +00006436 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006437 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006438 }
Mike Stump11289f42009-09-09 15:08:12 +00006439
David Majnemer5f7efef2013-10-15 09:50:08 +00006440 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006441 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006442 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006443
John McCallb268a282010-08-23 23:25:46 +00006444 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006445 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006446}
Mike Stump11289f42009-09-09 15:08:12 +00006447
Richard Smith02e85f32011-04-14 22:09:26 +00006448template<typename Derived>
6449StmtResult
6450TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6451 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6452 if (Range.isInvalid())
6453 return StmtError();
6454
6455 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6456 if (BeginEnd.isInvalid())
6457 return StmtError();
6458
6459 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6460 if (Cond.isInvalid())
6461 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006462 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006463 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006464 if (Cond.isInvalid())
6465 return StmtError();
6466 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006467 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006468
6469 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6470 if (Inc.isInvalid())
6471 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006472 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006473 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006474
6475 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6476 if (LoopVar.isInvalid())
6477 return StmtError();
6478
6479 StmtResult NewStmt = S;
6480 if (getDerived().AlwaysRebuild() ||
6481 Range.get() != S->getRangeStmt() ||
6482 BeginEnd.get() != S->getBeginEndStmt() ||
6483 Cond.get() != S->getCond() ||
6484 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006485 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006486 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6487 S->getColonLoc(), Range.get(),
6488 BeginEnd.get(), Cond.get(),
6489 Inc.get(), LoopVar.get(),
6490 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006491 if (NewStmt.isInvalid())
6492 return StmtError();
6493 }
Richard Smith02e85f32011-04-14 22:09:26 +00006494
6495 StmtResult Body = getDerived().TransformStmt(S->getBody());
6496 if (Body.isInvalid())
6497 return StmtError();
6498
6499 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6500 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006501 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006502 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6503 S->getColonLoc(), Range.get(),
6504 BeginEnd.get(), Cond.get(),
6505 Inc.get(), LoopVar.get(),
6506 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006507 if (NewStmt.isInvalid())
6508 return StmtError();
6509 }
Richard Smith02e85f32011-04-14 22:09:26 +00006510
6511 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006512 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006513
6514 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6515}
6516
John Wiegley1c0675e2011-04-28 01:08:34 +00006517template<typename Derived>
6518StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006519TreeTransform<Derived>::TransformMSDependentExistsStmt(
6520 MSDependentExistsStmt *S) {
6521 // Transform the nested-name-specifier, if any.
6522 NestedNameSpecifierLoc QualifierLoc;
6523 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006524 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006525 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6526 if (!QualifierLoc)
6527 return StmtError();
6528 }
6529
6530 // Transform the declaration name.
6531 DeclarationNameInfo NameInfo = S->getNameInfo();
6532 if (NameInfo.getName()) {
6533 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6534 if (!NameInfo.getName())
6535 return StmtError();
6536 }
6537
6538 // Check whether anything changed.
6539 if (!getDerived().AlwaysRebuild() &&
6540 QualifierLoc == S->getQualifierLoc() &&
6541 NameInfo.getName() == S->getNameInfo().getName())
6542 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006543
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006544 // Determine whether this name exists, if we can.
6545 CXXScopeSpec SS;
6546 SS.Adopt(QualifierLoc);
6547 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006548 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006549 case Sema::IER_Exists:
6550 if (S->isIfExists())
6551 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006552
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006553 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6554
6555 case Sema::IER_DoesNotExist:
6556 if (S->isIfNotExists())
6557 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006558
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006559 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006560
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006561 case Sema::IER_Dependent:
6562 Dependent = true;
6563 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006564
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006565 case Sema::IER_Error:
6566 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006567 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006568
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006569 // We need to continue with the instantiation, so do so now.
6570 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6571 if (SubStmt.isInvalid())
6572 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006573
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006574 // If we have resolved the name, just transform to the substatement.
6575 if (!Dependent)
6576 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006577
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006578 // The name is still dependent, so build a dependent expression again.
6579 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6580 S->isIfExists(),
6581 QualifierLoc,
6582 NameInfo,
6583 SubStmt.get());
6584}
6585
6586template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006587ExprResult
6588TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6589 NestedNameSpecifierLoc QualifierLoc;
6590 if (E->getQualifierLoc()) {
6591 QualifierLoc
6592 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6593 if (!QualifierLoc)
6594 return ExprError();
6595 }
6596
6597 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6598 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6599 if (!PD)
6600 return ExprError();
6601
6602 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6603 if (Base.isInvalid())
6604 return ExprError();
6605
6606 return new (SemaRef.getASTContext())
6607 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6608 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6609 QualifierLoc, E->getMemberLoc());
6610}
6611
David Majnemerfad8f482013-10-15 09:33:02 +00006612template <typename Derived>
6613StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006614 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006615 if (TryBlock.isInvalid())
6616 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006617
6618 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006619 if (Handler.isInvalid())
6620 return StmtError();
6621
David Majnemerfad8f482013-10-15 09:33:02 +00006622 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6623 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006624 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006625
Warren Huntf6be4cb2014-07-25 20:52:51 +00006626 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6627 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006628}
6629
David Majnemerfad8f482013-10-15 09:33:02 +00006630template <typename Derived>
6631StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006632 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006633 if (Block.isInvalid())
6634 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006635
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006636 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006637}
6638
David Majnemerfad8f482013-10-15 09:33:02 +00006639template <typename Derived>
6640StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006641 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006642 if (FilterExpr.isInvalid())
6643 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006644
David Majnemer7e755502013-10-15 09:30:14 +00006645 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006646 if (Block.isInvalid())
6647 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006648
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006649 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6650 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006651}
6652
David Majnemerfad8f482013-10-15 09:33:02 +00006653template <typename Derived>
6654StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6655 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006656 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6657 else
6658 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6659}
6660
Nico Weber9b982072014-07-07 00:12:30 +00006661template<typename Derived>
6662StmtResult
6663TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6664 return S;
6665}
6666
Alexander Musman64d33f12014-06-04 07:53:32 +00006667//===----------------------------------------------------------------------===//
6668// OpenMP directive transformation
6669//===----------------------------------------------------------------------===//
6670template <typename Derived>
6671StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6672 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006673
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006674 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006675 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006676 ArrayRef<OMPClause *> Clauses = D->clauses();
6677 TClauses.reserve(Clauses.size());
6678 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6679 I != E; ++I) {
6680 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00006681 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006682 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00006683 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00006684 if (Clause)
6685 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006686 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006687 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006688 }
6689 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006690 StmtResult AssociatedStmt;
6691 if (D->hasAssociatedStmt()) {
6692 if (!D->getAssociatedStmt()) {
6693 return StmtError();
6694 }
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00006695 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
6696 /*CurScope=*/nullptr);
6697 StmtResult Body;
6698 {
6699 Sema::CompoundScopeRAII CompoundScope(getSema());
6700 Body = getDerived().TransformStmt(
6701 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
6702 }
6703 AssociatedStmt =
6704 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00006705 if (AssociatedStmt.isInvalid()) {
6706 return StmtError();
6707 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006708 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006709 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006710 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006711 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006712
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006713 // Transform directive name for 'omp critical' directive.
6714 DeclarationNameInfo DirName;
6715 if (D->getDirectiveKind() == OMPD_critical) {
6716 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6717 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6718 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006719 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
6720 if (D->getDirectiveKind() == OMPD_cancellation_point) {
6721 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
6722 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006723
Alexander Musman64d33f12014-06-04 07:53:32 +00006724 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006725 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
6726 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006727}
6728
Alexander Musman64d33f12014-06-04 07:53:32 +00006729template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006730StmtResult
6731TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6732 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006733 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6734 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006735 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6736 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6737 return Res;
6738}
6739
Alexander Musman64d33f12014-06-04 07:53:32 +00006740template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006741StmtResult
6742TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6743 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006744 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6745 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006746 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6747 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006748 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006749}
6750
Alexey Bataevf29276e2014-06-18 04:14:57 +00006751template <typename Derived>
6752StmtResult
6753TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6754 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006755 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6756 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006757 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6758 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6759 return Res;
6760}
6761
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006762template <typename Derived>
6763StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00006764TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
6765 DeclarationNameInfo DirName;
6766 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
6767 D->getLocStart());
6768 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6769 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6770 return Res;
6771}
6772
6773template <typename Derived>
6774StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006775TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6776 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006777 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6778 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006779 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6780 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6781 return Res;
6782}
6783
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006784template <typename Derived>
6785StmtResult
6786TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6787 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006788 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6789 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006790 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6791 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6792 return Res;
6793}
6794
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006795template <typename Derived>
6796StmtResult
6797TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6798 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006799 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6800 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006801 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6802 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6803 return Res;
6804}
6805
Alexey Bataev4acb8592014-07-07 13:01:15 +00006806template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006807StmtResult
6808TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6809 DeclarationNameInfo DirName;
6810 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6811 D->getLocStart());
6812 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6813 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6814 return Res;
6815}
6816
6817template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006818StmtResult
6819TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6820 getDerived().getSema().StartOpenMPDSABlock(
6821 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
6822 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6823 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6824 return Res;
6825}
6826
6827template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00006828StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6829 OMPParallelForDirective *D) {
6830 DeclarationNameInfo DirName;
6831 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6832 nullptr, D->getLocStart());
6833 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6834 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6835 return Res;
6836}
6837
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006838template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00006839StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
6840 OMPParallelForSimdDirective *D) {
6841 DeclarationNameInfo DirName;
6842 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
6843 nullptr, D->getLocStart());
6844 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6845 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6846 return Res;
6847}
6848
6849template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006850StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6851 OMPParallelSectionsDirective *D) {
6852 DeclarationNameInfo DirName;
6853 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6854 nullptr, D->getLocStart());
6855 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6856 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6857 return Res;
6858}
6859
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00006860template <typename Derived>
6861StmtResult
6862TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6863 DeclarationNameInfo DirName;
6864 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6865 D->getLocStart());
6866 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6867 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6868 return Res;
6869}
6870
Alexey Bataev68446b72014-07-18 07:47:19 +00006871template <typename Derived>
6872StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
6873 OMPTaskyieldDirective *D) {
6874 DeclarationNameInfo DirName;
6875 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
6876 D->getLocStart());
6877 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6878 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6879 return Res;
6880}
6881
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00006882template <typename Derived>
6883StmtResult
6884TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
6885 DeclarationNameInfo DirName;
6886 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
6887 D->getLocStart());
6888 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6889 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6890 return Res;
6891}
6892
Alexey Bataev2df347a2014-07-18 10:17:07 +00006893template <typename Derived>
6894StmtResult
6895TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
6896 DeclarationNameInfo DirName;
6897 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
6898 D->getLocStart());
6899 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6900 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6901 return Res;
6902}
6903
Alexey Bataev6125da92014-07-21 11:26:11 +00006904template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00006905StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
6906 OMPTaskgroupDirective *D) {
6907 DeclarationNameInfo DirName;
6908 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
6909 D->getLocStart());
6910 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6911 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6912 return Res;
6913}
6914
6915template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00006916StmtResult
6917TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
6918 DeclarationNameInfo DirName;
6919 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
6920 D->getLocStart());
6921 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6922 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6923 return Res;
6924}
6925
Alexey Bataev9fb6e642014-07-22 06:45:04 +00006926template <typename Derived>
6927StmtResult
6928TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
6929 DeclarationNameInfo DirName;
6930 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
6931 D->getLocStart());
6932 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6933 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6934 return Res;
6935}
6936
Alexey Bataev0162e452014-07-22 10:10:35 +00006937template <typename Derived>
6938StmtResult
6939TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
6940 DeclarationNameInfo DirName;
6941 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
6942 D->getLocStart());
6943 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6944 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6945 return Res;
6946}
6947
Alexey Bataev0bd520b2014-09-19 08:19:49 +00006948template <typename Derived>
6949StmtResult
6950TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
6951 DeclarationNameInfo DirName;
6952 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
6953 D->getLocStart());
6954 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6955 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6956 return Res;
6957}
6958
Alexey Bataev13314bf2014-10-09 04:18:56 +00006959template <typename Derived>
6960StmtResult
6961TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
6962 DeclarationNameInfo DirName;
6963 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
6964 D->getLocStart());
6965 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6966 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6967 return Res;
6968}
6969
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006970template <typename Derived>
6971StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
6972 OMPCancellationPointDirective *D) {
6973 DeclarationNameInfo DirName;
6974 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
6975 nullptr, D->getLocStart());
6976 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6977 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6978 return Res;
6979}
6980
Alexander Musman64d33f12014-06-04 07:53:32 +00006981//===----------------------------------------------------------------------===//
6982// OpenMP clause transformation
6983//===----------------------------------------------------------------------===//
6984template <typename Derived>
6985OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006986 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6987 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006988 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006989 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006990 C->getLParenLoc(), C->getLocEnd());
6991}
6992
Alexander Musman64d33f12014-06-04 07:53:32 +00006993template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00006994OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
6995 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6996 if (Cond.isInvalid())
6997 return nullptr;
6998 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
6999 C->getLParenLoc(), C->getLocEnd());
7000}
7001
7002template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007003OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007004TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7005 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7006 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007007 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007008 return getDerived().RebuildOMPNumThreadsClause(
7009 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007010}
7011
Alexey Bataev62c87d22014-03-21 04:51:18 +00007012template <typename Derived>
7013OMPClause *
7014TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7015 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7016 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007017 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007018 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007019 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007020}
7021
Alexander Musman8bd31e62014-05-27 15:12:19 +00007022template <typename Derived>
7023OMPClause *
7024TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7025 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7026 if (E.isInvalid())
7027 return 0;
7028 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007029 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007030}
7031
Alexander Musman64d33f12014-06-04 07:53:32 +00007032template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007033OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007034TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007035 return getDerived().RebuildOMPDefaultClause(
7036 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7037 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007038}
7039
Alexander Musman64d33f12014-06-04 07:53:32 +00007040template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007041OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007042TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007043 return getDerived().RebuildOMPProcBindClause(
7044 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7045 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007046}
7047
Alexander Musman64d33f12014-06-04 07:53:32 +00007048template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007049OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007050TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7051 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7052 if (E.isInvalid())
7053 return nullptr;
7054 return getDerived().RebuildOMPScheduleClause(
7055 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7056 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7057}
7058
7059template <typename Derived>
7060OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007061TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
7062 // No need to rebuild this clause, no template-dependent parameters.
7063 return C;
7064}
7065
7066template <typename Derived>
7067OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007068TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7069 // No need to rebuild this clause, no template-dependent parameters.
7070 return C;
7071}
7072
7073template <typename Derived>
7074OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007075TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7076 // No need to rebuild this clause, no template-dependent parameters.
7077 return C;
7078}
7079
7080template <typename Derived>
7081OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007082TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7083 // No need to rebuild this clause, no template-dependent parameters.
7084 return C;
7085}
7086
7087template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007088OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7089 // No need to rebuild this clause, no template-dependent parameters.
7090 return C;
7091}
7092
7093template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007094OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7095 // No need to rebuild this clause, no template-dependent parameters.
7096 return C;
7097}
7098
7099template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007100OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007101TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7102 // No need to rebuild this clause, no template-dependent parameters.
7103 return C;
7104}
7105
7106template <typename Derived>
7107OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007108TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7109 // No need to rebuild this clause, no template-dependent parameters.
7110 return C;
7111}
7112
7113template <typename Derived>
7114OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007115TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7116 // No need to rebuild this clause, no template-dependent parameters.
7117 return C;
7118}
7119
7120template <typename Derived>
7121OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007122TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007123 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007124 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007125 for (auto *VE : C->varlists()) {
7126 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007127 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007128 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007129 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007130 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007131 return getDerived().RebuildOMPPrivateClause(
7132 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007133}
7134
Alexander Musman64d33f12014-06-04 07:53:32 +00007135template <typename Derived>
7136OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7137 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007138 llvm::SmallVector<Expr *, 16> Vars;
7139 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007140 for (auto *VE : C->varlists()) {
7141 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007142 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007143 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007144 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007145 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007146 return getDerived().RebuildOMPFirstprivateClause(
7147 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007148}
7149
Alexander Musman64d33f12014-06-04 07:53:32 +00007150template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007151OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007152TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7153 llvm::SmallVector<Expr *, 16> Vars;
7154 Vars.reserve(C->varlist_size());
7155 for (auto *VE : C->varlists()) {
7156 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7157 if (EVar.isInvalid())
7158 return nullptr;
7159 Vars.push_back(EVar.get());
7160 }
7161 return getDerived().RebuildOMPLastprivateClause(
7162 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7163}
7164
7165template <typename Derived>
7166OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007167TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7168 llvm::SmallVector<Expr *, 16> Vars;
7169 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007170 for (auto *VE : C->varlists()) {
7171 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007172 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007173 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007174 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007175 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007176 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7177 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007178}
7179
Alexander Musman64d33f12014-06-04 07:53:32 +00007180template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007181OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007182TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7183 llvm::SmallVector<Expr *, 16> Vars;
7184 Vars.reserve(C->varlist_size());
7185 for (auto *VE : C->varlists()) {
7186 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7187 if (EVar.isInvalid())
7188 return nullptr;
7189 Vars.push_back(EVar.get());
7190 }
7191 CXXScopeSpec ReductionIdScopeSpec;
7192 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7193
7194 DeclarationNameInfo NameInfo = C->getNameInfo();
7195 if (NameInfo.getName()) {
7196 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7197 if (!NameInfo.getName())
7198 return nullptr;
7199 }
7200 return getDerived().RebuildOMPReductionClause(
7201 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7202 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7203}
7204
7205template <typename Derived>
7206OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007207TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7208 llvm::SmallVector<Expr *, 16> Vars;
7209 Vars.reserve(C->varlist_size());
7210 for (auto *VE : C->varlists()) {
7211 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7212 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007213 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007214 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007215 }
7216 ExprResult Step = getDerived().TransformExpr(C->getStep());
7217 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007218 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007219 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
7220 C->getLParenLoc(),
7221 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007222}
7223
Alexander Musman64d33f12014-06-04 07:53:32 +00007224template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007225OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007226TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7227 llvm::SmallVector<Expr *, 16> Vars;
7228 Vars.reserve(C->varlist_size());
7229 for (auto *VE : C->varlists()) {
7230 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7231 if (EVar.isInvalid())
7232 return nullptr;
7233 Vars.push_back(EVar.get());
7234 }
7235 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7236 if (Alignment.isInvalid())
7237 return nullptr;
7238 return getDerived().RebuildOMPAlignedClause(
7239 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7240 C->getColonLoc(), C->getLocEnd());
7241}
7242
Alexander Musman64d33f12014-06-04 07:53:32 +00007243template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007244OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007245TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7246 llvm::SmallVector<Expr *, 16> Vars;
7247 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007248 for (auto *VE : C->varlists()) {
7249 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007250 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007251 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007252 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007253 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007254 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7255 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007256}
7257
Alexey Bataevbae9a792014-06-27 10:37:06 +00007258template <typename Derived>
7259OMPClause *
7260TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7261 llvm::SmallVector<Expr *, 16> Vars;
7262 Vars.reserve(C->varlist_size());
7263 for (auto *VE : C->varlists()) {
7264 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7265 if (EVar.isInvalid())
7266 return nullptr;
7267 Vars.push_back(EVar.get());
7268 }
7269 return getDerived().RebuildOMPCopyprivateClause(
7270 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7271}
7272
Alexey Bataev6125da92014-07-21 11:26:11 +00007273template <typename Derived>
7274OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7275 llvm::SmallVector<Expr *, 16> Vars;
7276 Vars.reserve(C->varlist_size());
7277 for (auto *VE : C->varlists()) {
7278 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7279 if (EVar.isInvalid())
7280 return nullptr;
7281 Vars.push_back(EVar.get());
7282 }
7283 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7284 C->getLParenLoc(), C->getLocEnd());
7285}
7286
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007287template <typename Derived>
7288OMPClause *
7289TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7290 llvm::SmallVector<Expr *, 16> Vars;
7291 Vars.reserve(C->varlist_size());
7292 for (auto *VE : C->varlists()) {
7293 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7294 if (EVar.isInvalid())
7295 return nullptr;
7296 Vars.push_back(EVar.get());
7297 }
7298 return getDerived().RebuildOMPDependClause(
7299 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7300 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7301}
7302
Douglas Gregorebe10102009-08-20 07:17:43 +00007303//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007304// Expression transformation
7305//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007306template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007307ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007308TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007309 if (!E->isTypeDependent())
7310 return E;
7311
7312 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7313 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007314}
Mike Stump11289f42009-09-09 15:08:12 +00007315
7316template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007317ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007318TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007319 NestedNameSpecifierLoc QualifierLoc;
7320 if (E->getQualifierLoc()) {
7321 QualifierLoc
7322 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7323 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007324 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007325 }
John McCallce546572009-12-08 09:08:17 +00007326
7327 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007328 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7329 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007330 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007331 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007332
John McCall815039a2010-08-17 21:27:17 +00007333 DeclarationNameInfo NameInfo = E->getNameInfo();
7334 if (NameInfo.getName()) {
7335 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7336 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007337 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007338 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007339
7340 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007341 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007342 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007343 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007344 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007345
7346 // Mark it referenced in the new context regardless.
7347 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007348 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007349
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007350 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007351 }
John McCallce546572009-12-08 09:08:17 +00007352
Craig Topperc3ec1492014-05-26 06:22:03 +00007353 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007354 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007355 TemplateArgs = &TransArgs;
7356 TransArgs.setLAngleLoc(E->getLAngleLoc());
7357 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007358 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7359 E->getNumTemplateArgs(),
7360 TransArgs))
7361 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007362 }
7363
Chad Rosier1dcde962012-08-08 18:46:20 +00007364 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007365 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007366}
Mike Stump11289f42009-09-09 15:08:12 +00007367
Douglas Gregora16548e2009-08-11 05:31:07 +00007368template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007369ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007370TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007371 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007372}
Mike Stump11289f42009-09-09 15:08:12 +00007373
Douglas Gregora16548e2009-08-11 05:31:07 +00007374template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007375ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007376TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007377 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007378}
Mike Stump11289f42009-09-09 15:08:12 +00007379
Douglas Gregora16548e2009-08-11 05:31:07 +00007380template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007381ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007382TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007383 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007384}
Mike Stump11289f42009-09-09 15:08:12 +00007385
Douglas Gregora16548e2009-08-11 05:31:07 +00007386template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007387ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007388TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007389 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007390}
Mike Stump11289f42009-09-09 15:08:12 +00007391
Douglas Gregora16548e2009-08-11 05:31:07 +00007392template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007393ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007394TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007395 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007396}
7397
7398template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007399ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007400TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007401 if (FunctionDecl *FD = E->getDirectCallee())
7402 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007403 return SemaRef.MaybeBindToTemporary(E);
7404}
7405
7406template<typename Derived>
7407ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007408TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7409 ExprResult ControllingExpr =
7410 getDerived().TransformExpr(E->getControllingExpr());
7411 if (ControllingExpr.isInvalid())
7412 return ExprError();
7413
Chris Lattner01cf8db2011-07-20 06:58:45 +00007414 SmallVector<Expr *, 4> AssocExprs;
7415 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007416 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7417 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7418 if (TS) {
7419 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7420 if (!AssocType)
7421 return ExprError();
7422 AssocTypes.push_back(AssocType);
7423 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007424 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007425 }
7426
7427 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7428 if (AssocExpr.isInvalid())
7429 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007430 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007431 }
7432
7433 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7434 E->getDefaultLoc(),
7435 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007436 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007437 AssocTypes,
7438 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007439}
7440
7441template<typename Derived>
7442ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007443TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007444 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007445 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007446 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007447
Douglas Gregora16548e2009-08-11 05:31:07 +00007448 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007449 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007450
John McCallb268a282010-08-23 23:25:46 +00007451 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007452 E->getRParen());
7453}
7454
Richard Smithdb2630f2012-10-21 03:28:35 +00007455/// \brief The operand of a unary address-of operator has special rules: it's
7456/// allowed to refer to a non-static member of a class even if there's no 'this'
7457/// object available.
7458template<typename Derived>
7459ExprResult
7460TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7461 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007462 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007463 else
7464 return getDerived().TransformExpr(E);
7465}
7466
Mike Stump11289f42009-09-09 15:08:12 +00007467template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007468ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007469TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007470 ExprResult SubExpr;
7471 if (E->getOpcode() == UO_AddrOf)
7472 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7473 else
7474 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007475 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007476 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007477
Douglas Gregora16548e2009-08-11 05:31:07 +00007478 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007479 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007480
Douglas Gregora16548e2009-08-11 05:31:07 +00007481 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7482 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007483 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007484}
Mike Stump11289f42009-09-09 15:08:12 +00007485
Douglas Gregora16548e2009-08-11 05:31:07 +00007486template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007487ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007488TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7489 // Transform the type.
7490 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7491 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007492 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007493
Douglas Gregor882211c2010-04-28 22:16:22 +00007494 // Transform all of the components into components similar to what the
7495 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007496 // FIXME: It would be slightly more efficient in the non-dependent case to
7497 // just map FieldDecls, rather than requiring the rebuilder to look for
7498 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007499 // template code that we don't care.
7500 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007501 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007502 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007503 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007504 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7505 const Node &ON = E->getComponent(I);
7506 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007507 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007508 Comp.LocStart = ON.getSourceRange().getBegin();
7509 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007510 switch (ON.getKind()) {
7511 case Node::Array: {
7512 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007513 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007514 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007515 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007516
Douglas Gregor882211c2010-04-28 22:16:22 +00007517 ExprChanged = ExprChanged || Index.get() != FromIndex;
7518 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007519 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007520 break;
7521 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007522
Douglas Gregor882211c2010-04-28 22:16:22 +00007523 case Node::Field:
7524 case Node::Identifier:
7525 Comp.isBrackets = false;
7526 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007527 if (!Comp.U.IdentInfo)
7528 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007529
Douglas Gregor882211c2010-04-28 22:16:22 +00007530 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007531
Douglas Gregord1702062010-04-29 00:18:15 +00007532 case Node::Base:
7533 // Will be recomputed during the rebuild.
7534 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007535 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007536
Douglas Gregor882211c2010-04-28 22:16:22 +00007537 Components.push_back(Comp);
7538 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007539
Douglas Gregor882211c2010-04-28 22:16:22 +00007540 // If nothing changed, retain the existing expression.
7541 if (!getDerived().AlwaysRebuild() &&
7542 Type == E->getTypeSourceInfo() &&
7543 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007544 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007545
Douglas Gregor882211c2010-04-28 22:16:22 +00007546 // Build a new offsetof expression.
7547 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7548 Components.data(), Components.size(),
7549 E->getRParenLoc());
7550}
7551
7552template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007553ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007554TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7555 assert(getDerived().AlreadyTransformed(E->getType()) &&
7556 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007557 return E;
John McCall8d69a212010-11-15 23:31:06 +00007558}
7559
7560template<typename Derived>
7561ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00007562TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
7563 return E;
7564}
7565
7566template<typename Derived>
7567ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007568TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007569 // Rebuild the syntactic form. The original syntactic form has
7570 // opaque-value expressions in it, so strip those away and rebuild
7571 // the result. This is a really awful way of doing this, but the
7572 // better solution (rebuilding the semantic expressions and
7573 // rebinding OVEs as necessary) doesn't work; we'd need
7574 // TreeTransform to not strip away implicit conversions.
7575 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7576 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007577 if (result.isInvalid()) return ExprError();
7578
7579 // If that gives us a pseudo-object result back, the pseudo-object
7580 // expression must have been an lvalue-to-rvalue conversion which we
7581 // should reapply.
7582 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007583 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007584
7585 return result;
7586}
7587
7588template<typename Derived>
7589ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007590TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7591 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007592 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007593 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007594
John McCallbcd03502009-12-07 02:54:59 +00007595 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007596 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007597 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007598
John McCall4c98fd82009-11-04 07:28:41 +00007599 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007600 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007601
Peter Collingbournee190dee2011-03-11 19:24:49 +00007602 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7603 E->getKind(),
7604 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007605 }
Mike Stump11289f42009-09-09 15:08:12 +00007606
Eli Friedmane4f22df2012-02-29 04:03:55 +00007607 // C++0x [expr.sizeof]p1:
7608 // The operand is either an expression, which is an unevaluated operand
7609 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007610 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7611 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007612
Reid Kleckner32506ed2014-06-12 23:03:48 +00007613 // Try to recover if we have something like sizeof(T::X) where X is a type.
7614 // Notably, there must be *exactly* one set of parens if X is a type.
7615 TypeSourceInfo *RecoveryTSI = nullptr;
7616 ExprResult SubExpr;
7617 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7618 if (auto *DRE =
7619 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7620 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7621 PE, DRE, false, &RecoveryTSI);
7622 else
7623 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7624
7625 if (RecoveryTSI) {
7626 return getDerived().RebuildUnaryExprOrTypeTrait(
7627 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7628 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007629 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007630
Eli Friedmane4f22df2012-02-29 04:03:55 +00007631 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007632 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007633
Peter Collingbournee190dee2011-03-11 19:24:49 +00007634 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7635 E->getOperatorLoc(),
7636 E->getKind(),
7637 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007638}
Mike Stump11289f42009-09-09 15:08:12 +00007639
Douglas Gregora16548e2009-08-11 05:31:07 +00007640template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007641ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007642TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007643 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007644 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007645 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007646
John McCalldadc5752010-08-24 06:29:42 +00007647 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007648 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007649 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007650
7651
Douglas Gregora16548e2009-08-11 05:31:07 +00007652 if (!getDerived().AlwaysRebuild() &&
7653 LHS.get() == E->getLHS() &&
7654 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007655 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007656
John McCallb268a282010-08-23 23:25:46 +00007657 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007658 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007659 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007660 E->getRBracketLoc());
7661}
Mike Stump11289f42009-09-09 15:08:12 +00007662
7663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007664ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007665TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007666 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007667 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007668 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007669 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007670
7671 // Transform arguments.
7672 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007673 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007674 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007675 &ArgChanged))
7676 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007677
Douglas Gregora16548e2009-08-11 05:31:07 +00007678 if (!getDerived().AlwaysRebuild() &&
7679 Callee.get() == E->getCallee() &&
7680 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007681 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007682
Douglas Gregora16548e2009-08-11 05:31:07 +00007683 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007684 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007685 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007686 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007687 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007688 E->getRParenLoc());
7689}
Mike Stump11289f42009-09-09 15:08:12 +00007690
7691template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007692ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007693TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007694 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007695 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007696 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007697
Douglas Gregorea972d32011-02-28 21:54:11 +00007698 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007699 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007700 QualifierLoc
7701 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007702
Douglas Gregorea972d32011-02-28 21:54:11 +00007703 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007704 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007705 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007706 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007707
Eli Friedman2cfcef62009-12-04 06:40:45 +00007708 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007709 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7710 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007711 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007712 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007713
John McCall16df1e52010-03-30 21:47:33 +00007714 NamedDecl *FoundDecl = E->getFoundDecl();
7715 if (FoundDecl == E->getMemberDecl()) {
7716 FoundDecl = Member;
7717 } else {
7718 FoundDecl = cast_or_null<NamedDecl>(
7719 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7720 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007721 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007722 }
7723
Douglas Gregora16548e2009-08-11 05:31:07 +00007724 if (!getDerived().AlwaysRebuild() &&
7725 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007726 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007727 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007728 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007729 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007730
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007731 // Mark it referenced in the new context regardless.
7732 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007733 SemaRef.MarkMemberReferenced(E);
7734
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007735 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007736 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007737
John McCall6b51f282009-11-23 01:53:49 +00007738 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007739 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007740 TransArgs.setLAngleLoc(E->getLAngleLoc());
7741 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007742 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7743 E->getNumTemplateArgs(),
7744 TransArgs))
7745 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007746 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007747
Douglas Gregora16548e2009-08-11 05:31:07 +00007748 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007749 SourceLocation FakeOperatorLoc =
7750 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007751
John McCall38836f02010-01-15 08:34:02 +00007752 // FIXME: to do this check properly, we will need to preserve the
7753 // first-qualifier-in-scope here, just in case we had a dependent
7754 // base (and therefore couldn't do the check) and a
7755 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007756 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007757
John McCallb268a282010-08-23 23:25:46 +00007758 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007759 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007760 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007761 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007762 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007763 Member,
John McCall16df1e52010-03-30 21:47:33 +00007764 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007765 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007766 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007767 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007768}
Mike Stump11289f42009-09-09 15:08:12 +00007769
Douglas Gregora16548e2009-08-11 05:31:07 +00007770template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007771ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007772TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007773 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007774 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007775 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007776
John McCalldadc5752010-08-24 06:29:42 +00007777 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007778 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007779 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007780
Douglas Gregora16548e2009-08-11 05:31:07 +00007781 if (!getDerived().AlwaysRebuild() &&
7782 LHS.get() == E->getLHS() &&
7783 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007784 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007785
Lang Hames5de91cc2012-10-02 04:45:10 +00007786 Sema::FPContractStateRAII FPContractState(getSema());
7787 getSema().FPFeatures.fp_contract = E->isFPContractable();
7788
Douglas Gregora16548e2009-08-11 05:31:07 +00007789 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007790 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007791}
7792
Mike Stump11289f42009-09-09 15:08:12 +00007793template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007794ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007795TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007796 CompoundAssignOperator *E) {
7797 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007798}
Mike Stump11289f42009-09-09 15:08:12 +00007799
Douglas Gregora16548e2009-08-11 05:31:07 +00007800template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007801ExprResult TreeTransform<Derived>::
7802TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7803 // Just rebuild the common and RHS expressions and see whether we
7804 // get any changes.
7805
7806 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7807 if (commonExpr.isInvalid())
7808 return ExprError();
7809
7810 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7811 if (rhs.isInvalid())
7812 return ExprError();
7813
7814 if (!getDerived().AlwaysRebuild() &&
7815 commonExpr.get() == e->getCommon() &&
7816 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007817 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007818
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007819 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007820 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007821 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007822 e->getColonLoc(),
7823 rhs.get());
7824}
7825
7826template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007827ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007828TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007829 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007830 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007831 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007832
John McCalldadc5752010-08-24 06:29:42 +00007833 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007834 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007835 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007836
John McCalldadc5752010-08-24 06:29:42 +00007837 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007838 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007839 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007840
Douglas Gregora16548e2009-08-11 05:31:07 +00007841 if (!getDerived().AlwaysRebuild() &&
7842 Cond.get() == E->getCond() &&
7843 LHS.get() == E->getLHS() &&
7844 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007845 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007846
John McCallb268a282010-08-23 23:25:46 +00007847 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007848 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007849 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007850 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007851 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007852}
Mike Stump11289f42009-09-09 15:08:12 +00007853
7854template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007855ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007856TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007857 // Implicit casts are eliminated during transformation, since they
7858 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007859 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007860}
Mike Stump11289f42009-09-09 15:08:12 +00007861
Douglas Gregora16548e2009-08-11 05:31:07 +00007862template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007863ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007864TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007865 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7866 if (!Type)
7867 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007868
John McCalldadc5752010-08-24 06:29:42 +00007869 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007870 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007871 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007872 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007873
Douglas Gregora16548e2009-08-11 05:31:07 +00007874 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007875 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007876 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007877 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007878
John McCall97513962010-01-15 18:39:57 +00007879 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007880 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007881 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007882 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007883}
Mike Stump11289f42009-09-09 15:08:12 +00007884
Douglas Gregora16548e2009-08-11 05:31:07 +00007885template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007886ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007887TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007888 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7889 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7890 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007891 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007892
John McCalldadc5752010-08-24 06:29:42 +00007893 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007894 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007895 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007896
Douglas Gregora16548e2009-08-11 05:31:07 +00007897 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007898 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007899 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007900 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007901
John McCall5d7aa7f2010-01-19 22:33:45 +00007902 // Note: the expression type doesn't necessarily match the
7903 // type-as-written, but that's okay, because it should always be
7904 // derivable from the initializer.
7905
John McCalle15bbff2010-01-18 19:35:47 +00007906 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007907 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007908 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007909}
Mike Stump11289f42009-09-09 15:08:12 +00007910
Douglas Gregora16548e2009-08-11 05:31:07 +00007911template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007912ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007913TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007914 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007915 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007916 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007917
Douglas Gregora16548e2009-08-11 05:31:07 +00007918 if (!getDerived().AlwaysRebuild() &&
7919 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007920 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007921
Douglas Gregora16548e2009-08-11 05:31:07 +00007922 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007923 SourceLocation FakeOperatorLoc =
7924 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007925 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007926 E->getAccessorLoc(),
7927 E->getAccessor());
7928}
Mike Stump11289f42009-09-09 15:08:12 +00007929
Douglas Gregora16548e2009-08-11 05:31:07 +00007930template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007931ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007932TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00007933 if (InitListExpr *Syntactic = E->getSyntacticForm())
7934 E = Syntactic;
7935
Douglas Gregora16548e2009-08-11 05:31:07 +00007936 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007937
Benjamin Kramerf0623432012-08-23 22:51:59 +00007938 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007939 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007940 Inits, &InitChanged))
7941 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007942
Richard Smith520449d2015-02-05 06:15:50 +00007943 if (!getDerived().AlwaysRebuild() && !InitChanged) {
7944 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
7945 // in some cases. We can't reuse it in general, because the syntactic and
7946 // semantic forms are linked, and we can't know that semantic form will
7947 // match even if the syntactic form does.
7948 }
Mike Stump11289f42009-09-09 15:08:12 +00007949
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007950 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007951 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007952}
Mike Stump11289f42009-09-09 15:08:12 +00007953
Douglas Gregora16548e2009-08-11 05:31:07 +00007954template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007955ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007956TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007957 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007958
Douglas Gregorebe10102009-08-20 07:17:43 +00007959 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007960 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007961 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007962 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007963
Douglas Gregorebe10102009-08-20 07:17:43 +00007964 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007965 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007966 bool ExprChanged = false;
7967 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7968 DEnd = E->designators_end();
7969 D != DEnd; ++D) {
7970 if (D->isFieldDesignator()) {
7971 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7972 D->getDotLoc(),
7973 D->getFieldLoc()));
7974 continue;
7975 }
Mike Stump11289f42009-09-09 15:08:12 +00007976
Douglas Gregora16548e2009-08-11 05:31:07 +00007977 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007978 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007979 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007980 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007981
7982 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007983 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007984
Douglas Gregora16548e2009-08-11 05:31:07 +00007985 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007986 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007987 continue;
7988 }
Mike Stump11289f42009-09-09 15:08:12 +00007989
Douglas Gregora16548e2009-08-11 05:31:07 +00007990 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007991 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007992 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7993 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007994 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007995
John McCalldadc5752010-08-24 06:29:42 +00007996 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007997 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007998 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007999
8000 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008001 End.get(),
8002 D->getLBracketLoc(),
8003 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008004
Douglas Gregora16548e2009-08-11 05:31:07 +00008005 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8006 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00008007
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008008 ArrayExprs.push_back(Start.get());
8009 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008010 }
Mike Stump11289f42009-09-09 15:08:12 +00008011
Douglas Gregora16548e2009-08-11 05:31:07 +00008012 if (!getDerived().AlwaysRebuild() &&
8013 Init.get() == E->getInit() &&
8014 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008015 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008016
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008017 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008018 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008019 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008020}
Mike Stump11289f42009-09-09 15:08:12 +00008021
Yunzhong Gaocb779302015-06-10 00:27:52 +00008022// Seems that if TransformInitListExpr() only works on the syntactic form of an
8023// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8024template<typename Derived>
8025ExprResult
8026TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8027 DesignatedInitUpdateExpr *E) {
8028 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8029 "initializer");
8030 return ExprError();
8031}
8032
8033template<typename Derived>
8034ExprResult
8035TreeTransform<Derived>::TransformNoInitExpr(
8036 NoInitExpr *E) {
8037 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8038 return ExprError();
8039}
8040
Douglas Gregora16548e2009-08-11 05:31:07 +00008041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008042ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008043TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008044 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008045 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008046
Douglas Gregor3da3c062009-10-28 00:29:27 +00008047 // FIXME: Will we ever have proper type location here? Will we actually
8048 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008049 QualType T = getDerived().TransformType(E->getType());
8050 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008051 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008052
Douglas Gregora16548e2009-08-11 05:31:07 +00008053 if (!getDerived().AlwaysRebuild() &&
8054 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008055 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008056
Douglas Gregora16548e2009-08-11 05:31:07 +00008057 return getDerived().RebuildImplicitValueInitExpr(T);
8058}
Mike Stump11289f42009-09-09 15:08:12 +00008059
Douglas Gregora16548e2009-08-11 05:31:07 +00008060template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008061ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008062TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008063 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8064 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008065 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008066
John McCalldadc5752010-08-24 06:29:42 +00008067 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008068 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008069 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008070
Douglas Gregora16548e2009-08-11 05:31:07 +00008071 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008072 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008073 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008074 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008075
John McCallb268a282010-08-23 23:25:46 +00008076 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008077 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008078}
8079
8080template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008081ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008082TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008083 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008084 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008085 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8086 &ArgumentChanged))
8087 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008088
Douglas Gregora16548e2009-08-11 05:31:07 +00008089 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008090 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008091 E->getRParenLoc());
8092}
Mike Stump11289f42009-09-09 15:08:12 +00008093
Douglas Gregora16548e2009-08-11 05:31:07 +00008094/// \brief Transform an address-of-label expression.
8095///
8096/// By default, the transformation of an address-of-label expression always
8097/// rebuilds the expression, so that the label identifier can be resolved to
8098/// the corresponding label statement by semantic analysis.
8099template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008100ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008101TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008102 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8103 E->getLabel());
8104 if (!LD)
8105 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008106
Douglas Gregora16548e2009-08-11 05:31:07 +00008107 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008108 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008109}
Mike Stump11289f42009-09-09 15:08:12 +00008110
8111template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008112ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008113TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008114 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008115 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008116 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008117 if (SubStmt.isInvalid()) {
8118 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008119 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008120 }
Mike Stump11289f42009-09-09 15:08:12 +00008121
Douglas Gregora16548e2009-08-11 05:31:07 +00008122 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008123 SubStmt.get() == E->getSubStmt()) {
8124 // Calling this an 'error' is unintuitive, but it does the right thing.
8125 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008126 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008127 }
Mike Stump11289f42009-09-09 15:08:12 +00008128
8129 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008130 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008131 E->getRParenLoc());
8132}
Mike Stump11289f42009-09-09 15:08:12 +00008133
Douglas Gregora16548e2009-08-11 05:31:07 +00008134template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008135ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008136TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008137 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008138 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008139 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008140
John McCalldadc5752010-08-24 06:29:42 +00008141 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008142 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008143 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008144
John McCalldadc5752010-08-24 06:29:42 +00008145 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008146 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008147 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008148
Douglas Gregora16548e2009-08-11 05:31:07 +00008149 if (!getDerived().AlwaysRebuild() &&
8150 Cond.get() == E->getCond() &&
8151 LHS.get() == E->getLHS() &&
8152 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008153 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008154
Douglas Gregora16548e2009-08-11 05:31:07 +00008155 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008156 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008157 E->getRParenLoc());
8158}
Mike Stump11289f42009-09-09 15:08:12 +00008159
Douglas Gregora16548e2009-08-11 05:31:07 +00008160template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008161ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008162TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008163 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008164}
8165
8166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008167ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008168TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008169 switch (E->getOperator()) {
8170 case OO_New:
8171 case OO_Delete:
8172 case OO_Array_New:
8173 case OO_Array_Delete:
8174 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008175
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008176 case OO_Call: {
8177 // This is a call to an object's operator().
8178 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8179
8180 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008181 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008182 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008183 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008184
8185 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008186 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8187 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008188
8189 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008190 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008191 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008192 Args))
8193 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008194
John McCallb268a282010-08-23 23:25:46 +00008195 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008196 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008197 E->getLocEnd());
8198 }
8199
8200#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8201 case OO_##Name:
8202#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8203#include "clang/Basic/OperatorKinds.def"
8204 case OO_Subscript:
8205 // Handled below.
8206 break;
8207
8208 case OO_Conditional:
8209 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008210
8211 case OO_None:
8212 case NUM_OVERLOADED_OPERATORS:
8213 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008214 }
8215
John McCalldadc5752010-08-24 06:29:42 +00008216 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008217 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008218 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008219
Richard Smithdb2630f2012-10-21 03:28:35 +00008220 ExprResult First;
8221 if (E->getOperator() == OO_Amp)
8222 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8223 else
8224 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008225 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008226 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008227
John McCalldadc5752010-08-24 06:29:42 +00008228 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008229 if (E->getNumArgs() == 2) {
8230 Second = getDerived().TransformExpr(E->getArg(1));
8231 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008232 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008233 }
Mike Stump11289f42009-09-09 15:08:12 +00008234
Douglas Gregora16548e2009-08-11 05:31:07 +00008235 if (!getDerived().AlwaysRebuild() &&
8236 Callee.get() == E->getCallee() &&
8237 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008238 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008239 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008240
Lang Hames5de91cc2012-10-02 04:45:10 +00008241 Sema::FPContractStateRAII FPContractState(getSema());
8242 getSema().FPFeatures.fp_contract = E->isFPContractable();
8243
Douglas Gregora16548e2009-08-11 05:31:07 +00008244 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8245 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008246 Callee.get(),
8247 First.get(),
8248 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008249}
Mike Stump11289f42009-09-09 15:08:12 +00008250
Douglas Gregora16548e2009-08-11 05:31:07 +00008251template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008252ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008253TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8254 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008255}
Mike Stump11289f42009-09-09 15:08:12 +00008256
Douglas Gregora16548e2009-08-11 05:31:07 +00008257template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008258ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008259TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8260 // Transform the callee.
8261 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8262 if (Callee.isInvalid())
8263 return ExprError();
8264
8265 // Transform exec config.
8266 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8267 if (EC.isInvalid())
8268 return ExprError();
8269
8270 // Transform arguments.
8271 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008272 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008273 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008274 &ArgChanged))
8275 return ExprError();
8276
8277 if (!getDerived().AlwaysRebuild() &&
8278 Callee.get() == E->getCallee() &&
8279 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008280 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008281
8282 // FIXME: Wrong source location information for the '('.
8283 SourceLocation FakeLParenLoc
8284 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8285 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008286 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008287 E->getRParenLoc(), EC.get());
8288}
8289
8290template<typename Derived>
8291ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008292TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008293 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8294 if (!Type)
8295 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008296
John McCalldadc5752010-08-24 06:29:42 +00008297 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008298 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008299 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008300 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008301
Douglas Gregora16548e2009-08-11 05:31:07 +00008302 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008303 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008304 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008305 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008306 return getDerived().RebuildCXXNamedCastExpr(
8307 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8308 Type, E->getAngleBrackets().getEnd(),
8309 // FIXME. this should be '(' location
8310 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008311}
Mike Stump11289f42009-09-09 15:08:12 +00008312
Douglas Gregora16548e2009-08-11 05:31:07 +00008313template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008314ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008315TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8316 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008317}
Mike Stump11289f42009-09-09 15:08:12 +00008318
8319template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008320ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008321TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8322 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008323}
8324
Douglas Gregora16548e2009-08-11 05:31:07 +00008325template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008326ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008327TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008328 CXXReinterpretCastExpr *E) {
8329 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008330}
Mike Stump11289f42009-09-09 15:08:12 +00008331
Douglas Gregora16548e2009-08-11 05:31:07 +00008332template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008333ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008334TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8335 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008336}
Mike Stump11289f42009-09-09 15:08:12 +00008337
Douglas Gregora16548e2009-08-11 05:31:07 +00008338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008339ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008340TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008341 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008342 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8343 if (!Type)
8344 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008345
John McCalldadc5752010-08-24 06:29:42 +00008346 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008347 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008348 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008349 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008350
Douglas Gregora16548e2009-08-11 05:31:07 +00008351 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008352 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008353 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008354 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008355
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008356 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008357 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008358 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008359 E->getRParenLoc());
8360}
Mike Stump11289f42009-09-09 15:08:12 +00008361
Douglas Gregora16548e2009-08-11 05:31:07 +00008362template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008363ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008364TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008365 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008366 TypeSourceInfo *TInfo
8367 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8368 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008369 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008370
Douglas Gregora16548e2009-08-11 05:31:07 +00008371 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008372 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008373 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008374
Douglas Gregor9da64192010-04-26 22:37:10 +00008375 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8376 E->getLocStart(),
8377 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008378 E->getLocEnd());
8379 }
Mike Stump11289f42009-09-09 15:08:12 +00008380
Eli Friedman456f0182012-01-20 01:26:23 +00008381 // We don't know whether the subexpression is potentially evaluated until
8382 // after we perform semantic analysis. We speculatively assume it is
8383 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008384 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008385 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8386 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008387
John McCalldadc5752010-08-24 06:29:42 +00008388 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008389 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008390 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008391
Douglas Gregora16548e2009-08-11 05:31:07 +00008392 if (!getDerived().AlwaysRebuild() &&
8393 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008394 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008395
Douglas Gregor9da64192010-04-26 22:37:10 +00008396 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8397 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008398 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008399 E->getLocEnd());
8400}
8401
8402template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008403ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008404TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8405 if (E->isTypeOperand()) {
8406 TypeSourceInfo *TInfo
8407 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8408 if (!TInfo)
8409 return ExprError();
8410
8411 if (!getDerived().AlwaysRebuild() &&
8412 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008413 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008414
Douglas Gregor69735112011-03-06 17:40:41 +00008415 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008416 E->getLocStart(),
8417 TInfo,
8418 E->getLocEnd());
8419 }
8420
Francois Pichet9f4f2072010-09-08 12:20:18 +00008421 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8422
8423 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8424 if (SubExpr.isInvalid())
8425 return ExprError();
8426
8427 if (!getDerived().AlwaysRebuild() &&
8428 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008429 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008430
8431 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8432 E->getLocStart(),
8433 SubExpr.get(),
8434 E->getLocEnd());
8435}
8436
8437template<typename Derived>
8438ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008439TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008440 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008441}
Mike Stump11289f42009-09-09 15:08:12 +00008442
Douglas Gregora16548e2009-08-11 05:31:07 +00008443template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008444ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008445TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008446 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008447 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008448}
Mike Stump11289f42009-09-09 15:08:12 +00008449
Douglas Gregora16548e2009-08-11 05:31:07 +00008450template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008451ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008452TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008453 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008454
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008455 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8456 // Make sure that we capture 'this'.
8457 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008458 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008459 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008460
Douglas Gregorb15af892010-01-07 23:12:05 +00008461 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008462}
Mike Stump11289f42009-09-09 15:08:12 +00008463
Douglas Gregora16548e2009-08-11 05:31:07 +00008464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008465ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008466TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008467 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008468 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008469 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008470
Douglas Gregora16548e2009-08-11 05:31:07 +00008471 if (!getDerived().AlwaysRebuild() &&
8472 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008473 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008474
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008475 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8476 E->isThrownVariableInScope());
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
John McCall47f29ea2009-12-08 09:21:05 +00008481TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008482 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008483 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8484 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008485 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008486 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008487
Chandler Carruth794da4c2010-02-08 06:42:49 +00008488 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008489 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008490 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008491
Douglas Gregor033f6752009-12-23 23:03:06 +00008492 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008493}
Mike Stump11289f42009-09-09 15:08:12 +00008494
Douglas Gregora16548e2009-08-11 05:31:07 +00008495template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008496ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008497TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8498 FieldDecl *Field
8499 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8500 E->getField()));
8501 if (!Field)
8502 return ExprError();
8503
8504 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008505 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008506
8507 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8508}
8509
8510template<typename Derived>
8511ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008512TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8513 CXXScalarValueInitExpr *E) {
8514 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8515 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008516 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008517
Douglas Gregora16548e2009-08-11 05:31:07 +00008518 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008519 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008520 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008521
Chad Rosier1dcde962012-08-08 18:46:20 +00008522 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008523 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008524 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008525}
Mike Stump11289f42009-09-09 15:08:12 +00008526
Douglas Gregora16548e2009-08-11 05:31:07 +00008527template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008528ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008529TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008530 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008531 TypeSourceInfo *AllocTypeInfo
8532 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8533 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008534 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008535
Douglas Gregora16548e2009-08-11 05:31:07 +00008536 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008537 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008538 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008539 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008540
Douglas Gregora16548e2009-08-11 05:31:07 +00008541 // Transform the placement arguments (if any).
8542 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008543 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008544 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008545 E->getNumPlacementArgs(), true,
8546 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008547 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008548
Sebastian Redl6047f072012-02-16 12:22:20 +00008549 // Transform the initializer (if any).
8550 Expr *OldInit = E->getInitializer();
8551 ExprResult NewInit;
8552 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008553 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008554 if (NewInit.isInvalid())
8555 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008556
Sebastian Redl6047f072012-02-16 12:22:20 +00008557 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008558 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008559 if (E->getOperatorNew()) {
8560 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008561 getDerived().TransformDecl(E->getLocStart(),
8562 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008563 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008564 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008565 }
8566
Craig Topperc3ec1492014-05-26 06:22:03 +00008567 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008568 if (E->getOperatorDelete()) {
8569 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008570 getDerived().TransformDecl(E->getLocStart(),
8571 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008572 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008573 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008574 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008575
Douglas Gregora16548e2009-08-11 05:31:07 +00008576 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008577 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008578 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008579 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008580 OperatorNew == E->getOperatorNew() &&
8581 OperatorDelete == E->getOperatorDelete() &&
8582 !ArgumentChanged) {
8583 // Mark any declarations we need as referenced.
8584 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008585 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008586 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008587 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008588 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008589
Sebastian Redl6047f072012-02-16 12:22:20 +00008590 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008591 QualType ElementType
8592 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8593 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8594 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8595 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008596 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008597 }
8598 }
8599 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008600
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008601 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008602 }
Mike Stump11289f42009-09-09 15:08:12 +00008603
Douglas Gregor0744ef62010-09-07 21:49:58 +00008604 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008605 if (!ArraySize.get()) {
8606 // If no array size was specified, but the new expression was
8607 // instantiated with an array type (e.g., "new T" where T is
8608 // instantiated with "int[4]"), extract the outer bound from the
8609 // array type as our array size. We do this with constant and
8610 // dependently-sized array types.
8611 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8612 if (!ArrayT) {
8613 // Do nothing
8614 } else if (const ConstantArrayType *ConsArrayT
8615 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008616 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8617 SemaRef.Context.getSizeType(),
8618 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008619 AllocType = ConsArrayT->getElementType();
8620 } else if (const DependentSizedArrayType *DepArrayT
8621 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8622 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008623 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008624 AllocType = DepArrayT->getElementType();
8625 }
8626 }
8627 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008628
Douglas Gregora16548e2009-08-11 05:31:07 +00008629 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8630 E->isGlobalNew(),
8631 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008632 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008633 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008634 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008635 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008636 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008637 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008638 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008639 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008640}
Mike Stump11289f42009-09-09 15:08:12 +00008641
Douglas Gregora16548e2009-08-11 05:31:07 +00008642template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008643ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008644TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008645 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008646 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008647 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008648
Douglas Gregord2d9da02010-02-26 00:38:10 +00008649 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008650 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008651 if (E->getOperatorDelete()) {
8652 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008653 getDerived().TransformDecl(E->getLocStart(),
8654 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008655 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008656 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008657 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008658
Douglas Gregora16548e2009-08-11 05:31:07 +00008659 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008660 Operand.get() == E->getArgument() &&
8661 OperatorDelete == E->getOperatorDelete()) {
8662 // Mark any declarations we need as referenced.
8663 // FIXME: instantiation-specific.
8664 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008665 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008666
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008667 if (!E->getArgument()->isTypeDependent()) {
8668 QualType Destroyed = SemaRef.Context.getBaseElementType(
8669 E->getDestroyedType());
8670 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8671 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008672 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008673 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008674 }
8675 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008676
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008677 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008678 }
Mike Stump11289f42009-09-09 15:08:12 +00008679
Douglas Gregora16548e2009-08-11 05:31:07 +00008680 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8681 E->isGlobalDelete(),
8682 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008683 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008684}
Mike Stump11289f42009-09-09 15:08:12 +00008685
Douglas Gregora16548e2009-08-11 05:31:07 +00008686template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008687ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008688TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008689 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008690 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008691 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008692 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008693
John McCallba7bf592010-08-24 05:47:05 +00008694 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008695 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008696 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008697 E->getOperatorLoc(),
8698 E->isArrow()? tok::arrow : tok::period,
8699 ObjectTypePtr,
8700 MayBePseudoDestructor);
8701 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008702 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008703
John McCallba7bf592010-08-24 05:47:05 +00008704 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008705 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8706 if (QualifierLoc) {
8707 QualifierLoc
8708 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8709 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008710 return ExprError();
8711 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008712 CXXScopeSpec SS;
8713 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008714
Douglas Gregor678f90d2010-02-25 01:56:36 +00008715 PseudoDestructorTypeStorage Destroyed;
8716 if (E->getDestroyedTypeInfo()) {
8717 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008718 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008719 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008720 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008721 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008722 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008723 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008724 // We aren't likely to be able to resolve the identifier down to a type
8725 // now anyway, so just retain the identifier.
8726 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8727 E->getDestroyedTypeLoc());
8728 } else {
8729 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008730 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008731 *E->getDestroyedTypeIdentifier(),
8732 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008733 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008734 SS, ObjectTypePtr,
8735 false);
8736 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008737 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008738
Douglas Gregor678f90d2010-02-25 01:56:36 +00008739 Destroyed
8740 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8741 E->getDestroyedTypeLoc());
8742 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008743
Craig Topperc3ec1492014-05-26 06:22:03 +00008744 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008745 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008746 CXXScopeSpec EmptySS;
8747 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008748 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008749 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008750 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008751 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008752
John McCallb268a282010-08-23 23:25:46 +00008753 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008754 E->getOperatorLoc(),
8755 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008756 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008757 ScopeTypeInfo,
8758 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008759 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008760 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008761}
Mike Stump11289f42009-09-09 15:08:12 +00008762
Douglas Gregorad8a3362009-09-04 17:36:40 +00008763template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008764ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008765TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008766 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008767 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8768 Sema::LookupOrdinaryName);
8769
8770 // Transform all the decls.
8771 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8772 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008773 NamedDecl *InstD = static_cast<NamedDecl*>(
8774 getDerived().TransformDecl(Old->getNameLoc(),
8775 *I));
John McCall84d87672009-12-10 09:41:52 +00008776 if (!InstD) {
8777 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8778 // This can happen because of dependent hiding.
8779 if (isa<UsingShadowDecl>(*I))
8780 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008781 else {
8782 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008783 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008784 }
John McCall84d87672009-12-10 09:41:52 +00008785 }
John McCalle66edc12009-11-24 19:00:30 +00008786
8787 // Expand using declarations.
8788 if (isa<UsingDecl>(InstD)) {
8789 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008790 for (auto *I : UD->shadows())
8791 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008792 continue;
8793 }
8794
8795 R.addDecl(InstD);
8796 }
8797
8798 // Resolve a kind, but don't do any further analysis. If it's
8799 // ambiguous, the callee needs to deal with it.
8800 R.resolveKind();
8801
8802 // Rebuild the nested-name qualifier, if present.
8803 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008804 if (Old->getQualifierLoc()) {
8805 NestedNameSpecifierLoc QualifierLoc
8806 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8807 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008808 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008809
Douglas Gregor0da1d432011-02-28 20:01:57 +00008810 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008811 }
8812
Douglas Gregor9262f472010-04-27 18:19:34 +00008813 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008814 CXXRecordDecl *NamingClass
8815 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8816 Old->getNameLoc(),
8817 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008818 if (!NamingClass) {
8819 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008820 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008821 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008822
Douglas Gregorda7be082010-04-27 16:10:10 +00008823 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008824 }
8825
Abramo Bagnara7945c982012-01-27 09:46:47 +00008826 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8827
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008828 // If we have neither explicit template arguments, nor the template keyword,
8829 // it's a normal declaration name.
8830 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008831 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8832
8833 // If we have template arguments, rebuild them, then rebuild the
8834 // templateid expression.
8835 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008836 if (Old->hasExplicitTemplateArgs() &&
8837 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008838 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008839 TransArgs)) {
8840 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008841 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008842 }
John McCalle66edc12009-11-24 19:00:30 +00008843
Abramo Bagnara7945c982012-01-27 09:46:47 +00008844 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008845 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008846}
Mike Stump11289f42009-09-09 15:08:12 +00008847
Douglas Gregora16548e2009-08-11 05:31:07 +00008848template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008849ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008850TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8851 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008852 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008853 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8854 TypeSourceInfo *From = E->getArg(I);
8855 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008856 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008857 TypeLocBuilder TLB;
8858 TLB.reserve(FromTL.getFullDataSize());
8859 QualType To = getDerived().TransformType(TLB, FromTL);
8860 if (To.isNull())
8861 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008862
Douglas Gregor29c42f22012-02-24 07:38:34 +00008863 if (To == From->getType())
8864 Args.push_back(From);
8865 else {
8866 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8867 ArgChanged = true;
8868 }
8869 continue;
8870 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008871
Douglas Gregor29c42f22012-02-24 07:38:34 +00008872 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008873
Douglas Gregor29c42f22012-02-24 07:38:34 +00008874 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008875 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008876 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8877 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8878 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008879
Douglas Gregor29c42f22012-02-24 07:38:34 +00008880 // Determine whether the set of unexpanded parameter packs can and should
8881 // be expanded.
8882 bool Expand = true;
8883 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008884 Optional<unsigned> OrigNumExpansions =
8885 ExpansionTL.getTypePtr()->getNumExpansions();
8886 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008887 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8888 PatternTL.getSourceRange(),
8889 Unexpanded,
8890 Expand, RetainExpansion,
8891 NumExpansions))
8892 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008893
Douglas Gregor29c42f22012-02-24 07:38:34 +00008894 if (!Expand) {
8895 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008896 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008897 // expansion.
8898 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008899
Douglas Gregor29c42f22012-02-24 07:38:34 +00008900 TypeLocBuilder TLB;
8901 TLB.reserve(From->getTypeLoc().getFullDataSize());
8902
8903 QualType To = getDerived().TransformType(TLB, PatternTL);
8904 if (To.isNull())
8905 return ExprError();
8906
Chad Rosier1dcde962012-08-08 18:46:20 +00008907 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008908 PatternTL.getSourceRange(),
8909 ExpansionTL.getEllipsisLoc(),
8910 NumExpansions);
8911 if (To.isNull())
8912 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008913
Douglas Gregor29c42f22012-02-24 07:38:34 +00008914 PackExpansionTypeLoc ToExpansionTL
8915 = TLB.push<PackExpansionTypeLoc>(To);
8916 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8917 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8918 continue;
8919 }
8920
8921 // Expand the pack expansion by substituting for each argument in the
8922 // pack(s).
8923 for (unsigned I = 0; I != *NumExpansions; ++I) {
8924 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8925 TypeLocBuilder TLB;
8926 TLB.reserve(PatternTL.getFullDataSize());
8927 QualType To = getDerived().TransformType(TLB, PatternTL);
8928 if (To.isNull())
8929 return ExprError();
8930
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008931 if (To->containsUnexpandedParameterPack()) {
8932 To = getDerived().RebuildPackExpansionType(To,
8933 PatternTL.getSourceRange(),
8934 ExpansionTL.getEllipsisLoc(),
8935 NumExpansions);
8936 if (To.isNull())
8937 return ExprError();
8938
8939 PackExpansionTypeLoc ToExpansionTL
8940 = TLB.push<PackExpansionTypeLoc>(To);
8941 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8942 }
8943
Douglas Gregor29c42f22012-02-24 07:38:34 +00008944 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8945 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008946
Douglas Gregor29c42f22012-02-24 07:38:34 +00008947 if (!RetainExpansion)
8948 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008949
Douglas Gregor29c42f22012-02-24 07:38:34 +00008950 // If we're supposed to retain a pack expansion, do so by temporarily
8951 // forgetting the partially-substituted parameter pack.
8952 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8953
8954 TypeLocBuilder TLB;
8955 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008956
Douglas Gregor29c42f22012-02-24 07:38:34 +00008957 QualType To = getDerived().TransformType(TLB, PatternTL);
8958 if (To.isNull())
8959 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008960
8961 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008962 PatternTL.getSourceRange(),
8963 ExpansionTL.getEllipsisLoc(),
8964 NumExpansions);
8965 if (To.isNull())
8966 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008967
Douglas Gregor29c42f22012-02-24 07:38:34 +00008968 PackExpansionTypeLoc ToExpansionTL
8969 = TLB.push<PackExpansionTypeLoc>(To);
8970 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8971 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8972 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008973
Douglas Gregor29c42f22012-02-24 07:38:34 +00008974 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008975 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008976
8977 return getDerived().RebuildTypeTrait(E->getTrait(),
8978 E->getLocStart(),
8979 Args,
8980 E->getLocEnd());
8981}
8982
8983template<typename Derived>
8984ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008985TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8986 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8987 if (!T)
8988 return ExprError();
8989
8990 if (!getDerived().AlwaysRebuild() &&
8991 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008992 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008993
8994 ExprResult SubExpr;
8995 {
8996 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8997 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8998 if (SubExpr.isInvalid())
8999 return ExprError();
9000
9001 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009002 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009003 }
9004
9005 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9006 E->getLocStart(),
9007 T,
9008 SubExpr.get(),
9009 E->getLocEnd());
9010}
9011
9012template<typename Derived>
9013ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009014TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9015 ExprResult SubExpr;
9016 {
9017 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9018 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9019 if (SubExpr.isInvalid())
9020 return ExprError();
9021
9022 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009023 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009024 }
9025
9026 return getDerived().RebuildExpressionTrait(
9027 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9028}
9029
Reid Kleckner32506ed2014-06-12 23:03:48 +00009030template <typename Derived>
9031ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9032 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9033 TypeSourceInfo **RecoveryTSI) {
9034 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9035 DRE, AddrTaken, RecoveryTSI);
9036
9037 // Propagate both errors and recovered types, which return ExprEmpty.
9038 if (!NewDRE.isUsable())
9039 return NewDRE;
9040
9041 // We got an expr, wrap it up in parens.
9042 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9043 return PE;
9044 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9045 PE->getRParen());
9046}
9047
9048template <typename Derived>
9049ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9050 DependentScopeDeclRefExpr *E) {
9051 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9052 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009053}
9054
9055template<typename Derived>
9056ExprResult
9057TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9058 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009059 bool IsAddressOfOperand,
9060 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009061 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009062 NestedNameSpecifierLoc QualifierLoc
9063 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9064 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009065 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009066 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009067
John McCall31f82722010-11-12 08:19:04 +00009068 // TODO: If this is a conversion-function-id, verify that the
9069 // destination type name (if present) resolves the same way after
9070 // instantiation as it did in the local scope.
9071
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009072 DeclarationNameInfo NameInfo
9073 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9074 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009075 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009076
John McCalle66edc12009-11-24 19:00:30 +00009077 if (!E->hasExplicitTemplateArgs()) {
9078 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009079 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009080 // Note: it is sufficient to compare the Name component of NameInfo:
9081 // if name has not changed, DNLoc has not changed either.
9082 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009083 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009084
Reid Kleckner32506ed2014-06-12 23:03:48 +00009085 return getDerived().RebuildDependentScopeDeclRefExpr(
9086 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9087 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009088 }
John McCall6b51f282009-11-23 01:53:49 +00009089
9090 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009091 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9092 E->getNumTemplateArgs(),
9093 TransArgs))
9094 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009095
Reid Kleckner32506ed2014-06-12 23:03:48 +00009096 return getDerived().RebuildDependentScopeDeclRefExpr(
9097 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9098 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009099}
9100
9101template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009102ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009103TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009104 // CXXConstructExprs other than for list-initialization and
9105 // CXXTemporaryObjectExpr are always implicit, so when we have
9106 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009107 if ((E->getNumArgs() == 1 ||
9108 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009109 (!getDerived().DropCallArgument(E->getArg(0))) &&
9110 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009111 return getDerived().TransformExpr(E->getArg(0));
9112
Douglas Gregora16548e2009-08-11 05:31:07 +00009113 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9114
9115 QualType T = getDerived().TransformType(E->getType());
9116 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009117 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009118
9119 CXXConstructorDecl *Constructor
9120 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009121 getDerived().TransformDecl(E->getLocStart(),
9122 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009123 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009124 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009125
Douglas Gregora16548e2009-08-11 05:31:07 +00009126 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009127 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009128 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009129 &ArgumentChanged))
9130 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009131
Douglas Gregora16548e2009-08-11 05:31:07 +00009132 if (!getDerived().AlwaysRebuild() &&
9133 T == E->getType() &&
9134 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009135 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009136 // Mark the constructor as referenced.
9137 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009138 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009139 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009140 }
Mike Stump11289f42009-09-09 15:08:12 +00009141
Douglas Gregordb121ba2009-12-14 16:27:04 +00009142 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9143 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009144 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009145 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009146 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009147 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009148 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009149 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009150 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009151}
Mike Stump11289f42009-09-09 15:08:12 +00009152
Douglas Gregora16548e2009-08-11 05:31:07 +00009153/// \brief Transform a C++ temporary-binding expression.
9154///
Douglas Gregor363b1512009-12-24 18:51:59 +00009155/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9156/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009158ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009159TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009160 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009161}
Mike Stump11289f42009-09-09 15:08:12 +00009162
John McCall5d413782010-12-06 08:20:24 +00009163/// \brief Transform a C++ expression that contains cleanups that should
9164/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009165///
John McCall5d413782010-12-06 08:20:24 +00009166/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009167/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009168template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009169ExprResult
John McCall5d413782010-12-06 08:20:24 +00009170TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009171 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009172}
Mike Stump11289f42009-09-09 15:08:12 +00009173
Douglas Gregora16548e2009-08-11 05:31:07 +00009174template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009175ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009176TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009177 CXXTemporaryObjectExpr *E) {
9178 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9179 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009180 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009181
Douglas Gregora16548e2009-08-11 05:31:07 +00009182 CXXConstructorDecl *Constructor
9183 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009184 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009185 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009186 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009187 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009188
Douglas Gregora16548e2009-08-11 05:31:07 +00009189 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009190 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009191 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009192 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009193 &ArgumentChanged))
9194 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009195
Douglas Gregora16548e2009-08-11 05:31:07 +00009196 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009197 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009198 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009199 !ArgumentChanged) {
9200 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009201 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009202 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009203 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009204
Richard Smithd59b8322012-12-19 01:39:02 +00009205 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009206 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9207 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009208 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009209 E->getLocEnd());
9210}
Mike Stump11289f42009-09-09 15:08:12 +00009211
Douglas Gregora16548e2009-08-11 05:31:07 +00009212template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009213ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009214TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009215 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009216 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009217 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009218 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9219 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009220 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009221 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009222 CEnd = E->capture_end();
9223 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009224 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009225 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009226 EnterExpressionEvaluationContext EEEC(getSema(),
9227 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009228 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9229 C->getCapturedVar()->getInit(),
9230 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009231
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009232 if (NewExprInitResult.isInvalid())
9233 return ExprError();
9234 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009235
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009236 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009237 QualType NewInitCaptureType =
9238 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
9239 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009240 NewExprInit);
9241 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009242 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9243 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009244 }
9245
Faisal Vali2cba1332013-10-23 06:44:28 +00009246 // Transform the template parameters, and add them to the current
9247 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009248 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009249 E->getTemplateParameterList());
9250
Richard Smith01014ce2014-11-20 23:53:14 +00009251 // Transform the type of the original lambda's call operator.
9252 // The transformation MUST be done in the CurrentInstantiationScope since
9253 // it introduces a mapping of the original to the newly created
9254 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009255 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009256 {
9257 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9258 FunctionProtoTypeLoc OldCallOpFPTL =
9259 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009260
9261 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009262 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009263 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009264 QualType NewCallOpType = TransformFunctionProtoType(
9265 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009266 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9267 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9268 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009269 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009270 if (NewCallOpType.isNull())
9271 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009272 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9273 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009274 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009275
Richard Smithc38498f2015-04-27 21:27:54 +00009276 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9277 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9278 LSI->GLTemplateParameterList = TPL;
9279
Eli Friedmand564afb2012-09-19 01:18:11 +00009280 // Create the local class that will describe the lambda.
9281 CXXRecordDecl *Class
9282 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009283 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009284 /*KnownDependent=*/false,
9285 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009286 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9287
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009288 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009289 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9290 Class, E->getIntroducerRange(), NewCallOpTSI,
9291 E->getCallOperator()->getLocEnd(),
9292 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009293 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009294
Faisal Vali2cba1332013-10-23 06:44:28 +00009295 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009296 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009297
Douglas Gregorb4328232012-02-14 00:00:48 +00009298 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009299 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009300 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009301
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009302 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009303 getSema().buildLambdaScope(LSI, NewCallOperator,
9304 E->getIntroducerRange(),
9305 E->getCaptureDefault(),
9306 E->getCaptureDefaultLoc(),
9307 E->hasExplicitParameters(),
9308 E->hasExplicitResultType(),
9309 E->isMutable());
9310
9311 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009312
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009313 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009314 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009315 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009316 CEnd = E->capture_end();
9317 C != CEnd; ++C) {
9318 // When we hit the first implicit capture, tell Sema that we've finished
9319 // the list of explicit captures.
9320 if (!FinishedExplicitCaptures && C->isImplicit()) {
9321 getSema().finishLambdaExplicitCaptures(LSI);
9322 FinishedExplicitCaptures = true;
9323 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009324
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009325 // Capturing 'this' is trivial.
9326 if (C->capturesThis()) {
9327 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9328 continue;
9329 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009330 // Captured expression will be recaptured during captured variables
9331 // rebuilding.
9332 if (C->capturesVLAType())
9333 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009334
Richard Smithba71c082013-05-16 06:20:58 +00009335 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +00009336 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009337 InitCaptureInfoTy InitExprTypePair =
9338 InitCaptureExprsAndTypes[C - E->capture_begin()];
9339 ExprResult Init = InitExprTypePair.first;
9340 QualType InitQualType = InitExprTypePair.second;
9341 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009342 Invalid = true;
9343 continue;
9344 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009345 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009346 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9347 OldVD->getLocation(), InitExprTypePair.second,
9348 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009349 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009350 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009351 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009352 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009353 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009354 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009355 continue;
9356 }
9357
9358 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9359
Douglas Gregor3e308b12012-02-14 19:27:52 +00009360 // Determine the capture kind for Sema.
9361 Sema::TryCaptureKind Kind
9362 = C->isImplicit()? Sema::TryCapture_Implicit
9363 : C->getCaptureKind() == LCK_ByCopy
9364 ? Sema::TryCapture_ExplicitByVal
9365 : Sema::TryCapture_ExplicitByRef;
9366 SourceLocation EllipsisLoc;
9367 if (C->isPackExpansion()) {
9368 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9369 bool ShouldExpand = false;
9370 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009371 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009372 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9373 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009374 Unexpanded,
9375 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009376 NumExpansions)) {
9377 Invalid = true;
9378 continue;
9379 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009380
Douglas Gregor3e308b12012-02-14 19:27:52 +00009381 if (ShouldExpand) {
9382 // The transform has determined that we should perform an expansion;
9383 // transform and capture each of the arguments.
9384 // expansion of the pattern. Do so.
9385 VarDecl *Pack = C->getCapturedVar();
9386 for (unsigned I = 0; I != *NumExpansions; ++I) {
9387 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9388 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009389 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009390 Pack));
9391 if (!CapturedVar) {
9392 Invalid = true;
9393 continue;
9394 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009395
Douglas Gregor3e308b12012-02-14 19:27:52 +00009396 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009397 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9398 }
Richard Smith9467be42014-06-06 17:33:35 +00009399
9400 // FIXME: Retain a pack expansion if RetainExpansion is true.
9401
Douglas Gregor3e308b12012-02-14 19:27:52 +00009402 continue;
9403 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009404
Douglas Gregor3e308b12012-02-14 19:27:52 +00009405 EllipsisLoc = C->getEllipsisLoc();
9406 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009407
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009408 // Transform the captured variable.
9409 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009410 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009411 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009412 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009413 Invalid = true;
9414 continue;
9415 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009416
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009417 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +00009418 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
9419 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009420 }
9421 if (!FinishedExplicitCaptures)
9422 getSema().finishLambdaExplicitCaptures(LSI);
9423
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009424 // Enter a new evaluation context to insulate the lambda from any
9425 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009426 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009427
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009428 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +00009429 StmtResult Body =
9430 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
9431
9432 // ActOnLambda* will pop the function scope for us.
9433 FuncScopeCleanup.disable();
9434
Douglas Gregorb4328232012-02-14 00:00:48 +00009435 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +00009436 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +00009437 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009438 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009439 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009440 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009441
Richard Smithc38498f2015-04-27 21:27:54 +00009442 // Copy the LSI before ActOnFinishFunctionBody removes it.
9443 // FIXME: This is dumb. Store the lambda information somewhere that outlives
9444 // the call operator.
9445 auto LSICopy = *LSI;
9446 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
9447 /*IsInstantiation*/ true);
9448 SavedContext.pop();
9449
9450 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
9451 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +00009452}
9453
9454template<typename Derived>
9455ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009456TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009457 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009458 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9459 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009460 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009461
Douglas Gregora16548e2009-08-11 05:31:07 +00009462 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009463 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009464 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009465 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009466 &ArgumentChanged))
9467 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009468
Douglas Gregora16548e2009-08-11 05:31:07 +00009469 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009470 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009471 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009472 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009473
Douglas Gregora16548e2009-08-11 05:31:07 +00009474 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009475 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009476 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009477 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009478 E->getRParenLoc());
9479}
Mike Stump11289f42009-09-09 15:08:12 +00009480
Douglas Gregora16548e2009-08-11 05:31:07 +00009481template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009482ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009483TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009484 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009485 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009486 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009487 Expr *OldBase;
9488 QualType BaseType;
9489 QualType ObjectType;
9490 if (!E->isImplicitAccess()) {
9491 OldBase = E->getBase();
9492 Base = getDerived().TransformExpr(OldBase);
9493 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009494 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009495
John McCall2d74de92009-12-01 22:10:20 +00009496 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009497 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009498 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009499 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009500 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009501 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009502 ObjectTy,
9503 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009504 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009505 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009506
John McCallba7bf592010-08-24 05:47:05 +00009507 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009508 BaseType = ((Expr*) Base.get())->getType();
9509 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009510 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009511 BaseType = getDerived().TransformType(E->getBaseType());
9512 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9513 }
Mike Stump11289f42009-09-09 15:08:12 +00009514
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009515 // Transform the first part of the nested-name-specifier that qualifies
9516 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009517 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009518 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009519 E->getFirstQualifierFoundInScope(),
9520 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009521
Douglas Gregore16af532011-02-28 18:50:33 +00009522 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009523 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009524 QualifierLoc
9525 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9526 ObjectType,
9527 FirstQualifierInScope);
9528 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009529 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009530 }
Mike Stump11289f42009-09-09 15:08:12 +00009531
Abramo Bagnara7945c982012-01-27 09:46:47 +00009532 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9533
John McCall31f82722010-11-12 08:19:04 +00009534 // TODO: If this is a conversion-function-id, verify that the
9535 // destination type name (if present) resolves the same way after
9536 // instantiation as it did in the local scope.
9537
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009538 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009539 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009540 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009541 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009542
John McCall2d74de92009-12-01 22:10:20 +00009543 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009544 // This is a reference to a member without an explicitly-specified
9545 // template argument list. Optimize for this common case.
9546 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009547 Base.get() == OldBase &&
9548 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009549 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009550 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009551 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009552 return E;
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 Gregor308047d2009-09-09 00:23:06 +00009556 E->isArrow(),
9557 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009558 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009559 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009560 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009561 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009562 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009563 }
9564
John McCall6b51f282009-11-23 01:53:49 +00009565 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009566 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9567 E->getNumTemplateArgs(),
9568 TransArgs))
9569 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009570
John McCallb268a282010-08-23 23:25:46 +00009571 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009572 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009573 E->isArrow(),
9574 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009575 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009576 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009577 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009578 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009579 &TransArgs);
9580}
9581
9582template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009583ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009584TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009585 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009586 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009587 QualType BaseType;
9588 if (!Old->isImplicitAccess()) {
9589 Base = getDerived().TransformExpr(Old->getBase());
9590 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009591 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009592 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009593 Old->isArrow());
9594 if (Base.isInvalid())
9595 return ExprError();
9596 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009597 } else {
9598 BaseType = getDerived().TransformType(Old->getBaseType());
9599 }
John McCall10eae182009-11-30 22:42:35 +00009600
Douglas Gregor0da1d432011-02-28 20:01:57 +00009601 NestedNameSpecifierLoc QualifierLoc;
9602 if (Old->getQualifierLoc()) {
9603 QualifierLoc
9604 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9605 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009606 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009607 }
9608
Abramo Bagnara7945c982012-01-27 09:46:47 +00009609 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9610
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009611 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009612 Sema::LookupOrdinaryName);
9613
9614 // Transform all the decls.
9615 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9616 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009617 NamedDecl *InstD = static_cast<NamedDecl*>(
9618 getDerived().TransformDecl(Old->getMemberLoc(),
9619 *I));
John McCall84d87672009-12-10 09:41:52 +00009620 if (!InstD) {
9621 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9622 // This can happen because of dependent hiding.
9623 if (isa<UsingShadowDecl>(*I))
9624 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009625 else {
9626 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009627 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009628 }
John McCall84d87672009-12-10 09:41:52 +00009629 }
John McCall10eae182009-11-30 22:42:35 +00009630
9631 // Expand using declarations.
9632 if (isa<UsingDecl>(InstD)) {
9633 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009634 for (auto *I : UD->shadows())
9635 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009636 continue;
9637 }
9638
9639 R.addDecl(InstD);
9640 }
9641
9642 R.resolveKind();
9643
Douglas Gregor9262f472010-04-27 18:19:34 +00009644 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009645 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009646 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009647 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009648 Old->getMemberLoc(),
9649 Old->getNamingClass()));
9650 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009651 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009652
Douglas Gregorda7be082010-04-27 16:10:10 +00009653 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009654 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009655
John McCall10eae182009-11-30 22:42:35 +00009656 TemplateArgumentListInfo TransArgs;
9657 if (Old->hasExplicitTemplateArgs()) {
9658 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9659 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009660 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9661 Old->getNumTemplateArgs(),
9662 TransArgs))
9663 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009664 }
John McCall38836f02010-01-15 08:34:02 +00009665
9666 // FIXME: to do this check properly, we will need to preserve the
9667 // first-qualifier-in-scope here, just in case we had a dependent
9668 // base (and therefore couldn't do the check) and a
9669 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009670 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009671
John McCallb268a282010-08-23 23:25:46 +00009672 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009673 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009674 Old->getOperatorLoc(),
9675 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009676 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009677 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009678 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009679 R,
9680 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009681 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009682}
9683
9684template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009685ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009686TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009687 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009688 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9689 if (SubExpr.isInvalid())
9690 return ExprError();
9691
9692 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009693 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009694
9695 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9696}
9697
9698template<typename Derived>
9699ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009700TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009701 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9702 if (Pattern.isInvalid())
9703 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009704
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009705 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009706 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009707
Douglas Gregorb8840002011-01-14 21:20:45 +00009708 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9709 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009710}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009711
9712template<typename Derived>
9713ExprResult
9714TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9715 // If E is not value-dependent, then nothing will change when we transform it.
9716 // Note: This is an instantiation-centric view.
9717 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009718 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009719
9720 // Note: None of the implementations of TryExpandParameterPacks can ever
9721 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009722 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009723 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9724 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009725 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009726 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009727 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009728 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009729 ShouldExpand, RetainExpansion,
9730 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009731 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009732
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009733 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009734 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009735
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009736 NamedDecl *Pack = E->getPack();
9737 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009738 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009739 Pack));
9740 if (!Pack)
9741 return ExprError();
9742 }
9743
Chad Rosier1dcde962012-08-08 18:46:20 +00009744
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009745 // We now know the length of the parameter pack, so build a new expression
9746 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009747 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9748 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009749 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009750}
9751
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009752template<typename Derived>
9753ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009754TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9755 SubstNonTypeTemplateParmPackExpr *E) {
9756 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009757 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009758}
9759
9760template<typename Derived>
9761ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009762TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9763 SubstNonTypeTemplateParmExpr *E) {
9764 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009765 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009766}
9767
9768template<typename Derived>
9769ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009770TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9771 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009772 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009773}
9774
9775template<typename Derived>
9776ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009777TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9778 MaterializeTemporaryExpr *E) {
9779 return getDerived().TransformExpr(E->GetTemporaryExpr());
9780}
Chad Rosier1dcde962012-08-08 18:46:20 +00009781
Douglas Gregorfe314812011-06-21 17:03:29 +00009782template<typename Derived>
9783ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +00009784TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
9785 Expr *Pattern = E->getPattern();
9786
9787 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9788 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
9789 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9790
9791 // Determine whether the set of unexpanded parameter packs can and should
9792 // be expanded.
9793 bool Expand = true;
9794 bool RetainExpansion = false;
9795 Optional<unsigned> NumExpansions;
9796 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
9797 Pattern->getSourceRange(),
9798 Unexpanded,
9799 Expand, RetainExpansion,
9800 NumExpansions))
9801 return true;
9802
9803 if (!Expand) {
9804 // Do not expand any packs here, just transform and rebuild a fold
9805 // expression.
9806 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9807
9808 ExprResult LHS =
9809 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
9810 if (LHS.isInvalid())
9811 return true;
9812
9813 ExprResult RHS =
9814 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
9815 if (RHS.isInvalid())
9816 return true;
9817
9818 if (!getDerived().AlwaysRebuild() &&
9819 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
9820 return E;
9821
9822 return getDerived().RebuildCXXFoldExpr(
9823 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
9824 RHS.get(), E->getLocEnd());
9825 }
9826
9827 // The transform has determined that we should perform an elementwise
9828 // expansion of the pattern. Do so.
9829 ExprResult Result = getDerived().TransformExpr(E->getInit());
9830 if (Result.isInvalid())
9831 return true;
9832 bool LeftFold = E->isLeftFold();
9833
9834 // If we're retaining an expansion for a right fold, it is the innermost
9835 // component and takes the init (if any).
9836 if (!LeftFold && RetainExpansion) {
9837 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9838
9839 ExprResult Out = getDerived().TransformExpr(Pattern);
9840 if (Out.isInvalid())
9841 return true;
9842
9843 Result = getDerived().RebuildCXXFoldExpr(
9844 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
9845 Result.get(), E->getLocEnd());
9846 if (Result.isInvalid())
9847 return true;
9848 }
9849
9850 for (unsigned I = 0; I != *NumExpansions; ++I) {
9851 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
9852 getSema(), LeftFold ? I : *NumExpansions - I - 1);
9853 ExprResult Out = getDerived().TransformExpr(Pattern);
9854 if (Out.isInvalid())
9855 return true;
9856
9857 if (Out.get()->containsUnexpandedParameterPack()) {
9858 // We still have a pack; retain a pack expansion for this slice.
9859 Result = getDerived().RebuildCXXFoldExpr(
9860 E->getLocStart(),
9861 LeftFold ? Result.get() : Out.get(),
9862 E->getOperator(), E->getEllipsisLoc(),
9863 LeftFold ? Out.get() : Result.get(),
9864 E->getLocEnd());
9865 } else if (Result.isUsable()) {
9866 // We've got down to a single element; build a binary operator.
9867 Result = getDerived().RebuildBinaryOperator(
9868 E->getEllipsisLoc(), E->getOperator(),
9869 LeftFold ? Result.get() : Out.get(),
9870 LeftFold ? Out.get() : Result.get());
9871 } else
9872 Result = Out;
9873
9874 if (Result.isInvalid())
9875 return true;
9876 }
9877
9878 // If we're retaining an expansion for a left fold, it is the outermost
9879 // component and takes the complete expansion so far as its init (if any).
9880 if (LeftFold && RetainExpansion) {
9881 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9882
9883 ExprResult Out = getDerived().TransformExpr(Pattern);
9884 if (Out.isInvalid())
9885 return true;
9886
9887 Result = getDerived().RebuildCXXFoldExpr(
9888 E->getLocStart(), Result.get(),
9889 E->getOperator(), E->getEllipsisLoc(),
9890 Out.get(), E->getLocEnd());
9891 if (Result.isInvalid())
9892 return true;
9893 }
9894
9895 // If we had no init and an empty pack, and we're not retaining an expansion,
9896 // then produce a fallback value or error.
9897 if (Result.isUnset())
9898 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
9899 E->getOperator());
9900
9901 return Result;
9902}
9903
9904template<typename Derived>
9905ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009906TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9907 CXXStdInitializerListExpr *E) {
9908 return getDerived().TransformExpr(E->getSubExpr());
9909}
9910
9911template<typename Derived>
9912ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009913TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009914 return SemaRef.MaybeBindToTemporary(E);
9915}
9916
9917template<typename Derived>
9918ExprResult
9919TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009920 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009921}
9922
9923template<typename Derived>
9924ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009925TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9926 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9927 if (SubExpr.isInvalid())
9928 return ExprError();
9929
9930 if (!getDerived().AlwaysRebuild() &&
9931 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009932 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009933
9934 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009935}
9936
9937template<typename Derived>
9938ExprResult
9939TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9940 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009941 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009942 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009943 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009944 /*IsCall=*/false, Elements, &ArgChanged))
9945 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009946
Ted Kremeneke65b0862012-03-06 20:05:56 +00009947 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9948 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009949
Ted Kremeneke65b0862012-03-06 20:05:56 +00009950 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9951 Elements.data(),
9952 Elements.size());
9953}
9954
9955template<typename Derived>
9956ExprResult
9957TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009958 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009959 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009960 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009961 bool ArgChanged = false;
9962 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9963 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009964
Ted Kremeneke65b0862012-03-06 20:05:56 +00009965 if (OrigElement.isPackExpansion()) {
9966 // This key/value element is a pack expansion.
9967 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9968 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9969 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9970 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9971
9972 // Determine whether the set of unexpanded parameter packs can
9973 // and should be expanded.
9974 bool Expand = true;
9975 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009976 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9977 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009978 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9979 OrigElement.Value->getLocEnd());
9980 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9981 PatternRange,
9982 Unexpanded,
9983 Expand, RetainExpansion,
9984 NumExpansions))
9985 return ExprError();
9986
9987 if (!Expand) {
9988 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009989 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009990 // expansion.
9991 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9992 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9993 if (Key.isInvalid())
9994 return ExprError();
9995
9996 if (Key.get() != OrigElement.Key)
9997 ArgChanged = true;
9998
9999 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10000 if (Value.isInvalid())
10001 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010002
Ted Kremeneke65b0862012-03-06 20:05:56 +000010003 if (Value.get() != OrigElement.Value)
10004 ArgChanged = true;
10005
Chad Rosier1dcde962012-08-08 18:46:20 +000010006 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010007 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10008 };
10009 Elements.push_back(Expansion);
10010 continue;
10011 }
10012
10013 // Record right away that the argument was changed. This needs
10014 // to happen even if the array expands to nothing.
10015 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010016
Ted Kremeneke65b0862012-03-06 20:05:56 +000010017 // The transform has determined that we should perform an elementwise
10018 // expansion of the pattern. Do so.
10019 for (unsigned I = 0; I != *NumExpansions; ++I) {
10020 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10021 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10022 if (Key.isInvalid())
10023 return ExprError();
10024
10025 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10026 if (Value.isInvalid())
10027 return ExprError();
10028
Chad Rosier1dcde962012-08-08 18:46:20 +000010029 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010030 Key.get(), Value.get(), SourceLocation(), NumExpansions
10031 };
10032
10033 // If any unexpanded parameter packs remain, we still have a
10034 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010035 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010036 if (Key.get()->containsUnexpandedParameterPack() ||
10037 Value.get()->containsUnexpandedParameterPack())
10038 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010039
Ted Kremeneke65b0862012-03-06 20:05:56 +000010040 Elements.push_back(Element);
10041 }
10042
Richard Smith9467be42014-06-06 17:33:35 +000010043 // FIXME: Retain a pack expansion if RetainExpansion is true.
10044
Ted Kremeneke65b0862012-03-06 20:05:56 +000010045 // We've finished with this pack expansion.
10046 continue;
10047 }
10048
10049 // Transform and check key.
10050 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10051 if (Key.isInvalid())
10052 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010053
Ted Kremeneke65b0862012-03-06 20:05:56 +000010054 if (Key.get() != OrigElement.Key)
10055 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010056
Ted Kremeneke65b0862012-03-06 20:05:56 +000010057 // Transform and check value.
10058 ExprResult Value
10059 = getDerived().TransformExpr(OrigElement.Value);
10060 if (Value.isInvalid())
10061 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010062
Ted Kremeneke65b0862012-03-06 20:05:56 +000010063 if (Value.get() != OrigElement.Value)
10064 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010065
10066 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010067 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010068 };
10069 Elements.push_back(Element);
10070 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010071
Ted Kremeneke65b0862012-03-06 20:05:56 +000010072 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10073 return SemaRef.MaybeBindToTemporary(E);
10074
10075 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
10076 Elements.data(),
10077 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +000010078}
10079
Mike Stump11289f42009-09-09 15:08:12 +000010080template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010081ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010082TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010083 TypeSourceInfo *EncodedTypeInfo
10084 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10085 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010086 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010087
Douglas Gregora16548e2009-08-11 05:31:07 +000010088 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010089 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010090 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010091
10092 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010093 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010094 E->getRParenLoc());
10095}
Mike Stump11289f42009-09-09 15:08:12 +000010096
Douglas Gregora16548e2009-08-11 05:31:07 +000010097template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010098ExprResult TreeTransform<Derived>::
10099TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010100 // This is a kind of implicit conversion, and it needs to get dropped
10101 // and recomputed for the same general reasons that ImplicitCastExprs
10102 // do, as well a more specific one: this expression is only valid when
10103 // it appears *immediately* as an argument expression.
10104 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010105}
10106
10107template<typename Derived>
10108ExprResult TreeTransform<Derived>::
10109TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010110 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010111 = getDerived().TransformType(E->getTypeInfoAsWritten());
10112 if (!TSInfo)
10113 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010114
John McCall31168b02011-06-15 23:02:42 +000010115 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010116 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010117 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010118
John McCall31168b02011-06-15 23:02:42 +000010119 if (!getDerived().AlwaysRebuild() &&
10120 TSInfo == E->getTypeInfoAsWritten() &&
10121 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010122 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010123
John McCall31168b02011-06-15 23:02:42 +000010124 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010125 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010126 Result.get());
10127}
10128
10129template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010130ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010131TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010132 // Transform arguments.
10133 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010134 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010135 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010136 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010137 &ArgChanged))
10138 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010139
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010140 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10141 // Class message: transform the receiver type.
10142 TypeSourceInfo *ReceiverTypeInfo
10143 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10144 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010145 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010146
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010147 // If nothing changed, just retain the existing message send.
10148 if (!getDerived().AlwaysRebuild() &&
10149 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010150 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010151
10152 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010153 SmallVector<SourceLocation, 16> SelLocs;
10154 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010155 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10156 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010157 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010158 E->getMethodDecl(),
10159 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010160 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010161 E->getRightLoc());
10162 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010163 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10164 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10165 // Build a new class message send to 'super'.
10166 SmallVector<SourceLocation, 16> SelLocs;
10167 E->getSelectorLocs(SelLocs);
10168 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10169 E->getSelector(),
10170 SelLocs,
10171 E->getMethodDecl(),
10172 E->getLeftLoc(),
10173 Args,
10174 E->getRightLoc());
10175 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010176
10177 // Instance message: transform the receiver
10178 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10179 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010180 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010181 = getDerived().TransformExpr(E->getInstanceReceiver());
10182 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010183 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010184
10185 // If nothing changed, just retain the existing message send.
10186 if (!getDerived().AlwaysRebuild() &&
10187 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010188 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010189
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010190 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010191 SmallVector<SourceLocation, 16> SelLocs;
10192 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010193 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010194 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010195 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010196 E->getMethodDecl(),
10197 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010198 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010199 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010200}
10201
Mike Stump11289f42009-09-09 15:08:12 +000010202template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010203ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010204TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010205 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010206}
10207
Mike Stump11289f42009-09-09 15:08:12 +000010208template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010209ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010210TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010211 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010212}
10213
Mike Stump11289f42009-09-09 15:08:12 +000010214template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010215ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010216TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010217 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010218 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010219 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010220 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010221
10222 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010223
Douglas Gregord51d90d2010-04-26 20:11:03 +000010224 // If nothing changed, just retain the existing expression.
10225 if (!getDerived().AlwaysRebuild() &&
10226 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010227 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010228
John McCallb268a282010-08-23 23:25:46 +000010229 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010230 E->getLocation(),
10231 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010232}
10233
Mike Stump11289f42009-09-09 15:08:12 +000010234template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010235ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010236TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010237 // 'super' and types never change. Property never changes. Just
10238 // retain the existing expression.
10239 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010240 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010241
Douglas Gregor9faee212010-04-26 20:47:02 +000010242 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010243 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010244 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010245 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010246
Douglas Gregor9faee212010-04-26 20:47:02 +000010247 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010248
Douglas Gregor9faee212010-04-26 20:47:02 +000010249 // If nothing changed, just retain the existing expression.
10250 if (!getDerived().AlwaysRebuild() &&
10251 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010252 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010253
John McCallb7bd14f2010-12-02 01:19:52 +000010254 if (E->isExplicitProperty())
10255 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10256 E->getExplicitProperty(),
10257 E->getLocation());
10258
10259 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010260 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010261 E->getImplicitPropertyGetter(),
10262 E->getImplicitPropertySetter(),
10263 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010264}
10265
Mike Stump11289f42009-09-09 15:08:12 +000010266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010267ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010268TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10269 // Transform the base expression.
10270 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10271 if (Base.isInvalid())
10272 return ExprError();
10273
10274 // Transform the key expression.
10275 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10276 if (Key.isInvalid())
10277 return ExprError();
10278
10279 // If nothing changed, just retain the existing expression.
10280 if (!getDerived().AlwaysRebuild() &&
10281 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010282 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010283
Chad Rosier1dcde962012-08-08 18:46:20 +000010284 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010285 Base.get(), Key.get(),
10286 E->getAtIndexMethodDecl(),
10287 E->setAtIndexMethodDecl());
10288}
10289
10290template<typename Derived>
10291ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010292TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010293 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010294 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010295 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010296 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010297
Douglas Gregord51d90d2010-04-26 20:11:03 +000010298 // If nothing changed, just retain the existing expression.
10299 if (!getDerived().AlwaysRebuild() &&
10300 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010301 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010302
John McCallb268a282010-08-23 23:25:46 +000010303 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010304 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010305 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010306}
10307
Mike Stump11289f42009-09-09 15:08:12 +000010308template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010309ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010310TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010311 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010312 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010313 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010314 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010315 SubExprs, &ArgumentChanged))
10316 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010317
Douglas Gregora16548e2009-08-11 05:31:07 +000010318 if (!getDerived().AlwaysRebuild() &&
10319 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010320 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010321
Douglas Gregora16548e2009-08-11 05:31:07 +000010322 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010323 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010324 E->getRParenLoc());
10325}
10326
Mike Stump11289f42009-09-09 15:08:12 +000010327template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010328ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010329TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10330 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10331 if (SrcExpr.isInvalid())
10332 return ExprError();
10333
10334 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10335 if (!Type)
10336 return ExprError();
10337
10338 if (!getDerived().AlwaysRebuild() &&
10339 Type == E->getTypeSourceInfo() &&
10340 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010341 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010342
10343 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10344 SrcExpr.get(), Type,
10345 E->getRParenLoc());
10346}
10347
10348template<typename Derived>
10349ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010350TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010351 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010352
Craig Topperc3ec1492014-05-26 06:22:03 +000010353 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010354 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10355
10356 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010357 blockScope->TheDecl->setBlockMissingReturnType(
10358 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010359
Chris Lattner01cf8db2011-07-20 06:58:45 +000010360 SmallVector<ParmVarDecl*, 4> params;
10361 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010362
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010363 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010364 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
10365 oldBlock->param_begin(),
10366 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010367 nullptr, paramTypes, &params)) {
10368 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010369 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010370 }
John McCall490112f2011-02-04 18:33:18 +000010371
Jordan Rosea0a86be2013-03-08 22:25:36 +000010372 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000010373 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000010374 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000010375
Jordan Rose5c382722013-03-08 21:51:21 +000010376 QualType functionType =
10377 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010378 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000010379 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000010380
10381 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000010382 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000010383 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000010384
10385 if (!oldBlock->blockMissingReturnType()) {
10386 blockScope->HasImplicitReturnType = false;
10387 blockScope->ReturnType = exprResultType;
10388 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010389
John McCall3882ace2011-01-05 12:14:39 +000010390 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000010391 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010392 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010393 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000010394 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010395 }
John McCall3882ace2011-01-05 12:14:39 +000010396
John McCall490112f2011-02-04 18:33:18 +000010397#ifndef NDEBUG
10398 // In builds with assertions, make sure that we captured everything we
10399 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010400 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010401 for (const auto &I : oldBlock->captures()) {
10402 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010403
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010404 // Ignore parameter packs.
10405 if (isa<ParmVarDecl>(oldCapture) &&
10406 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10407 continue;
John McCall490112f2011-02-04 18:33:18 +000010408
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010409 VarDecl *newCapture =
10410 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10411 oldCapture));
10412 assert(blockScope->CaptureMap.count(newCapture));
10413 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010414 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010415 }
10416#endif
10417
10418 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010419 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010420}
10421
Mike Stump11289f42009-09-09 15:08:12 +000010422template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010423ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010424TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010425 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010426}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010427
10428template<typename Derived>
10429ExprResult
10430TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010431 QualType RetTy = getDerived().TransformType(E->getType());
10432 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010433 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010434 SubExprs.reserve(E->getNumSubExprs());
10435 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10436 SubExprs, &ArgumentChanged))
10437 return ExprError();
10438
10439 if (!getDerived().AlwaysRebuild() &&
10440 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010441 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010442
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010443 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010444 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010445}
Chad Rosier1dcde962012-08-08 18:46:20 +000010446
Douglas Gregora16548e2009-08-11 05:31:07 +000010447//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010448// Type reconstruction
10449//===----------------------------------------------------------------------===//
10450
Mike Stump11289f42009-09-09 15:08:12 +000010451template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010452QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10453 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010454 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010455 getDerived().getBaseEntity());
10456}
10457
Mike Stump11289f42009-09-09 15:08:12 +000010458template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010459QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10460 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010461 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010462 getDerived().getBaseEntity());
10463}
10464
Mike Stump11289f42009-09-09 15:08:12 +000010465template<typename Derived>
10466QualType
John McCall70dd5f62009-10-30 00:06:24 +000010467TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10468 bool WrittenAsLValue,
10469 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010470 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010471 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010472}
10473
10474template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010475QualType
John McCall70dd5f62009-10-30 00:06:24 +000010476TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10477 QualType ClassType,
10478 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010479 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10480 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010481}
10482
10483template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010484QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010485TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10486 ArrayType::ArraySizeModifier SizeMod,
10487 const llvm::APInt *Size,
10488 Expr *SizeExpr,
10489 unsigned IndexTypeQuals,
10490 SourceRange BracketsRange) {
10491 if (SizeExpr || !Size)
10492 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10493 IndexTypeQuals, BracketsRange,
10494 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010495
10496 QualType Types[] = {
10497 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10498 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10499 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010500 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010501 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010502 QualType SizeType;
10503 for (unsigned I = 0; I != NumTypes; ++I)
10504 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10505 SizeType = Types[I];
10506 break;
10507 }
Mike Stump11289f42009-09-09 15:08:12 +000010508
Eli Friedman9562f392012-01-25 23:20:27 +000010509 // Note that we can return a VariableArrayType here in the case where
10510 // the element type was a dependent VariableArrayType.
10511 IntegerLiteral *ArraySize
10512 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10513 /*FIXME*/BracketsRange.getBegin());
10514 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010515 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010516 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010517}
Mike Stump11289f42009-09-09 15:08:12 +000010518
Douglas Gregord6ff3322009-08-04 16:50:30 +000010519template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010520QualType
10521TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010522 ArrayType::ArraySizeModifier SizeMod,
10523 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010524 unsigned IndexTypeQuals,
10525 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010526 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010527 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010528}
10529
10530template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010531QualType
Mike Stump11289f42009-09-09 15:08:12 +000010532TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010533 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010534 unsigned IndexTypeQuals,
10535 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010536 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010537 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010538}
Mike Stump11289f42009-09-09 15:08:12 +000010539
Douglas Gregord6ff3322009-08-04 16:50:30 +000010540template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010541QualType
10542TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010543 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010544 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010545 unsigned IndexTypeQuals,
10546 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010547 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010548 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010549 IndexTypeQuals, BracketsRange);
10550}
10551
10552template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010553QualType
10554TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010555 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010556 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010557 unsigned IndexTypeQuals,
10558 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010559 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010560 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010561 IndexTypeQuals, BracketsRange);
10562}
10563
10564template<typename Derived>
10565QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010566 unsigned NumElements,
10567 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010568 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010569 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010570}
Mike Stump11289f42009-09-09 15:08:12 +000010571
Douglas Gregord6ff3322009-08-04 16:50:30 +000010572template<typename Derived>
10573QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10574 unsigned NumElements,
10575 SourceLocation AttributeLoc) {
10576 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10577 NumElements, true);
10578 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010579 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10580 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010581 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010582}
Mike Stump11289f42009-09-09 15:08:12 +000010583
Douglas Gregord6ff3322009-08-04 16:50:30 +000010584template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010585QualType
10586TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010587 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010588 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010589 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010590}
Mike Stump11289f42009-09-09 15:08:12 +000010591
Douglas Gregord6ff3322009-08-04 16:50:30 +000010592template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010593QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10594 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010595 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010596 const FunctionProtoType::ExtProtoInfo &EPI) {
10597 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010598 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010599 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010600 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010601}
Mike Stump11289f42009-09-09 15:08:12 +000010602
Douglas Gregord6ff3322009-08-04 16:50:30 +000010603template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010604QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10605 return SemaRef.Context.getFunctionNoProtoType(T);
10606}
10607
10608template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010609QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10610 assert(D && "no decl found");
10611 if (D->isInvalidDecl()) return QualType();
10612
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010613 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010614 TypeDecl *Ty;
10615 if (isa<UsingDecl>(D)) {
10616 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010617 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010618 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10619
10620 // A valid resolved using typename decl points to exactly one type decl.
10621 assert(++Using->shadow_begin() == Using->shadow_end());
10622 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010623
John McCallb96ec562009-12-04 22:46:56 +000010624 } else {
10625 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10626 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10627 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10628 }
10629
10630 return SemaRef.Context.getTypeDeclType(Ty);
10631}
10632
10633template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010634QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10635 SourceLocation Loc) {
10636 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010637}
10638
10639template<typename Derived>
10640QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10641 return SemaRef.Context.getTypeOfType(Underlying);
10642}
10643
10644template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010645QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10646 SourceLocation Loc) {
10647 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010648}
10649
10650template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010651QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10652 UnaryTransformType::UTTKind UKind,
10653 SourceLocation Loc) {
10654 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10655}
10656
10657template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010658QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010659 TemplateName Template,
10660 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010661 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010662 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010663}
Mike Stump11289f42009-09-09 15:08:12 +000010664
Douglas Gregor1135c352009-08-06 05:28:30 +000010665template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010666QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10667 SourceLocation KWLoc) {
10668 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10669}
10670
10671template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010672TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010673TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010674 bool TemplateKW,
10675 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010676 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010677 Template);
10678}
10679
10680template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010681TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010682TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10683 const IdentifierInfo &Name,
10684 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010685 QualType ObjectType,
10686 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010687 UnqualifiedId TemplateName;
10688 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010689 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010690 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010691 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010692 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010693 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010694 /*EnteringContext=*/false,
10695 Template);
John McCall31f82722010-11-12 08:19:04 +000010696 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010697}
Mike Stump11289f42009-09-09 15:08:12 +000010698
Douglas Gregora16548e2009-08-11 05:31:07 +000010699template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010700TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010701TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010702 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010703 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010704 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010705 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010706 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010707 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010708 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010709 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010710 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010711 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010712 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010713 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010714 /*EnteringContext=*/false,
10715 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010716 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010717}
Chad Rosier1dcde962012-08-08 18:46:20 +000010718
Douglas Gregor71395fa2009-11-04 00:56:37 +000010719template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010720ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010721TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10722 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010723 Expr *OrigCallee,
10724 Expr *First,
10725 Expr *Second) {
10726 Expr *Callee = OrigCallee->IgnoreParenCasts();
10727 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010728
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010729 if (First->getObjectKind() == OK_ObjCProperty) {
10730 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10731 if (BinaryOperator::isAssignmentOp(Opc))
10732 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10733 First, Second);
10734 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10735 if (Result.isInvalid())
10736 return ExprError();
10737 First = Result.get();
10738 }
10739
10740 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10741 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10742 if (Result.isInvalid())
10743 return ExprError();
10744 Second = Result.get();
10745 }
10746
Douglas Gregora16548e2009-08-11 05:31:07 +000010747 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010748 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010749 if (!First->getType()->isOverloadableType() &&
10750 !Second->getType()->isOverloadableType())
10751 return getSema().CreateBuiltinArraySubscriptExpr(First,
10752 Callee->getLocStart(),
10753 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010754 } else if (Op == OO_Arrow) {
10755 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010756 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10757 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010758 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010759 // The argument is not of overloadable type, so try to create a
10760 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010761 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010762 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010763
John McCallb268a282010-08-23 23:25:46 +000010764 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010765 }
10766 } else {
John McCallb268a282010-08-23 23:25:46 +000010767 if (!First->getType()->isOverloadableType() &&
10768 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010769 // Neither of the arguments is an overloadable type, so try to
10770 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010771 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010772 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010773 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010774 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010775 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010776
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010777 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010778 }
10779 }
Mike Stump11289f42009-09-09 15:08:12 +000010780
10781 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010782 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010783 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010784
John McCallb268a282010-08-23 23:25:46 +000010785 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010786 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010787 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010788 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010789 // If we've resolved this to a particular non-member function, just call
10790 // that function. If we resolved it to a member function,
10791 // CreateOverloaded* will find that function for us.
10792 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10793 if (!isa<CXXMethodDecl>(ND))
10794 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000010795 }
Mike Stump11289f42009-09-09 15:08:12 +000010796
Douglas Gregora16548e2009-08-11 05:31:07 +000010797 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000010798 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000010799 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000010800
Douglas Gregora16548e2009-08-11 05:31:07 +000010801 // Create the overloaded operator invocation for unary operators.
10802 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000010803 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010804 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000010805 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010806 }
Mike Stump11289f42009-09-09 15:08:12 +000010807
Douglas Gregore9d62932011-07-15 16:25:15 +000010808 if (Op == OO_Subscript) {
10809 SourceLocation LBrace;
10810 SourceLocation RBrace;
10811
10812 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000010813 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000010814 LBrace = SourceLocation::getFromRawEncoding(
10815 NameLoc.CXXOperatorName.BeginOpNameLoc);
10816 RBrace = SourceLocation::getFromRawEncoding(
10817 NameLoc.CXXOperatorName.EndOpNameLoc);
10818 } else {
10819 LBrace = Callee->getLocStart();
10820 RBrace = OpLoc;
10821 }
10822
10823 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10824 First, Second);
10825 }
Sebastian Redladba46e2009-10-29 20:17:01 +000010826
Douglas Gregora16548e2009-08-11 05:31:07 +000010827 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000010828 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010829 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000010830 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10831 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010832 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010833
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010834 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010835}
Mike Stump11289f42009-09-09 15:08:12 +000010836
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010837template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010838ExprResult
John McCallb268a282010-08-23 23:25:46 +000010839TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010840 SourceLocation OperatorLoc,
10841 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010842 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010843 TypeSourceInfo *ScopeType,
10844 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010845 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010846 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010847 QualType BaseType = Base->getType();
10848 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010849 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010850 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010851 !BaseType->getAs<PointerType>()->getPointeeType()
10852 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010853 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000010854 return SemaRef.BuildPseudoDestructorExpr(
10855 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
10856 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010857 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010858
Douglas Gregor678f90d2010-02-25 01:56:36 +000010859 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010860 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10861 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10862 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10863 NameInfo.setNamedTypeInfo(DestroyedType);
10864
Richard Smith8e4a3862012-05-15 06:15:11 +000010865 // The scope type is now known to be a valid nested name specifier
10866 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000010867 if (ScopeType) {
10868 if (!ScopeType->getType()->getAs<TagType>()) {
10869 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
10870 diag::err_expected_class_or_namespace)
10871 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
10872 return ExprError();
10873 }
10874 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
10875 CCLoc);
10876 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010877
Abramo Bagnara7945c982012-01-27 09:46:47 +000010878 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010879 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010880 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010881 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010882 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010883 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010884 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010885}
10886
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010887template<typename Derived>
10888StmtResult
10889TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010890 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010891 CapturedDecl *CD = S->getCapturedDecl();
10892 unsigned NumParams = CD->getNumParams();
10893 unsigned ContextParamPos = CD->getContextParamPosition();
10894 SmallVector<Sema::CapturedParamNameType, 4> Params;
10895 for (unsigned I = 0; I < NumParams; ++I) {
10896 if (I != ContextParamPos) {
10897 Params.push_back(
10898 std::make_pair(
10899 CD->getParam(I)->getName(),
10900 getDerived().TransformType(CD->getParam(I)->getType())));
10901 } else {
10902 Params.push_back(std::make_pair(StringRef(), QualType()));
10903 }
10904 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010905 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010906 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010907 StmtResult Body;
10908 {
10909 Sema::CompoundScopeRAII CompoundScope(getSema());
10910 Body = getDerived().TransformStmt(S->getCapturedStmt());
10911 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010912
10913 if (Body.isInvalid()) {
10914 getSema().ActOnCapturedRegionError();
10915 return StmtError();
10916 }
10917
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010918 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010919}
10920
Douglas Gregord6ff3322009-08-04 16:50:30 +000010921} // end namespace clang
10922
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000010923#endif