blob: c569d31f7e30944bbcc89ebf80d446162475fedb [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000016
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000101
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000106
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000114
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000119
Mike Stump11289f42009-09-09 15:08:12 +0000120public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000123
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 }
131
John McCalldadc5752010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000134
Douglas Gregord6ff3322009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000144 ///
145 /// We must always rebuild all AST nodes when performing variadic template
146 /// pack expansion, in order to avoid violating the AST invariant that each
147 /// statement node appears at most once in its containing declaration.
148 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregord6ff3322009-08-04 16:50:30 +0000150 /// \brief Returns the location of the entity being transformed, if that
151 /// information was not available elsewhere in the AST.
152 ///
Mike Stump11289f42009-09-09 15:08:12 +0000153 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000154 /// provide an alternative implementation that provides better location
155 /// information.
156 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregord6ff3322009-08-04 16:50:30 +0000158 /// \brief Returns the name of the entity being transformed, if that
159 /// information was not available elsewhere in the AST.
160 ///
161 /// By default, returns an empty name. Subclasses can provide an alternative
162 /// implementation with a more precise name.
163 DeclarationName getBaseEntity() { return DeclarationName(); }
164
Douglas Gregora16548e2009-08-11 05:31:07 +0000165 /// \brief Sets the "base" location and entity when that
166 /// information is known based on another transformation.
167 ///
168 /// By default, the source location and entity are ignored. Subclasses can
169 /// override this function to provide a customized implementation.
170 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000171
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 /// \brief RAII object that temporarily sets the base location and entity
173 /// used for reporting diagnostics in types.
174 class TemporaryBase {
175 TreeTransform &Self;
176 SourceLocation OldLocation;
177 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 public:
180 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000181 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000182 OldLocation = Self.getDerived().getBaseLocation();
183 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000184
Douglas Gregora518d5b2011-01-25 17:51:48 +0000185 if (Location.isValid())
186 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000187 }
Mike Stump11289f42009-09-09 15:08:12 +0000188
Douglas Gregora16548e2009-08-11 05:31:07 +0000189 ~TemporaryBase() {
190 Self.getDerived().setBase(OldLocation, OldEntity);
191 }
192 };
Mike Stump11289f42009-09-09 15:08:12 +0000193
194 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000195 /// transformed.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000198 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000199 /// not change. For example, template instantiation need not traverse
200 /// non-dependent types.
201 bool AlreadyTransformed(QualType T) {
202 return T.isNull();
203 }
204
Douglas Gregord196a582009-12-14 19:27:10 +0000205 /// \brief Determine whether the given call argument should be dropped, e.g.,
206 /// because it is a default argument.
207 ///
208 /// Subclasses can provide an alternative implementation of this routine to
209 /// determine which kinds of call arguments get dropped. By default,
210 /// CXXDefaultArgument nodes are dropped (prior to transformation).
211 bool DropCallArgument(Expr *E) {
212 return E->isDefaultArgument();
213 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000214
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000215 /// \brief Determine whether we should expand a pack expansion with the
216 /// given set of parameter packs into separate arguments by repeatedly
217 /// transforming the pattern.
218 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000219 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000220 /// Subclasses can override this routine to provide different behavior.
221 ///
222 /// \param EllipsisLoc The location of the ellipsis that identifies the
223 /// pack expansion.
224 ///
225 /// \param PatternRange The source range that covers the entire pattern of
226 /// the pack expansion.
227 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000228 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000229 /// pattern.
230 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// \param ShouldExpand Will be set to \c true if the transformer should
232 /// expand the corresponding pack expansions into separate arguments. When
233 /// set, \c NumExpansions must also be set.
234 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000235 /// \param RetainExpansion Whether the caller should add an unexpanded
236 /// pack expansion after all of the expanded arguments. This is used
237 /// when extending explicitly-specified template argument packs per
238 /// C++0x [temp.arg.explicit]p9.
239 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000241 /// the expanded form of the corresponding pack expansion. This is both an
242 /// input and an output parameter, which can be set by the caller if the
243 /// number of expansions is known a priori (e.g., due to a prior substitution)
244 /// and will be set by the callee when the number of expansions is known.
245 /// The callee must set this value when \c ShouldExpand is \c true; it may
246 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000247 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000248 /// \returns true if an error occurred (e.g., because the parameter packs
249 /// are to be instantiated with arguments of different lengths), false
250 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 /// must be set.
252 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
253 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000254 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000255 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000257 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000258 ShouldExpand = false;
259 return false;
260 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000261
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000262 /// \brief "Forget" about the partially-substituted pack template argument,
263 /// when performing an instantiation that must preserve the parameter pack
264 /// use.
265 ///
266 /// This routine is meant to be overridden by the template instantiator.
267 TemplateArgument ForgetPartiallySubstitutedPack() {
268 return TemplateArgument();
269 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000270
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000271 /// \brief "Remember" the partially-substituted pack template argument
272 /// after performing an instantiation that must preserve the parameter pack
273 /// use.
274 ///
275 /// This routine is meant to be overridden by the template instantiator.
276 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000277
Douglas Gregorf3010112011-01-07 16:43:16 +0000278 /// \brief Note to the derived class when a function parameter pack is
279 /// being expanded.
280 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transforms the given type into another type.
283 ///
John McCall550e0c22009-10-21 00:40:46 +0000284 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000285 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000286 /// function. This is expensive, but we don't mind, because
287 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000288 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
290 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000291 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000292
John McCall550e0c22009-10-21 00:40:46 +0000293 /// \brief Transforms the given type-with-location into a new
294 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000295 ///
John McCall550e0c22009-10-21 00:40:46 +0000296 /// By default, this routine transforms a type by delegating to the
297 /// appropriate TransformXXXType to build a new type. Subclasses
298 /// may override this function (to take over all type
299 /// transformations) or some set of the TransformXXXType functions
300 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000301 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000302
303 /// \brief Transform the given type-with-location into a new
304 /// type, collecting location information in the given builder
305 /// as necessary.
306 ///
John McCall31f82722010-11-12 08:19:04 +0000307 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000308
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000309 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000310 ///
Mike Stump11289f42009-09-09 15:08:12 +0000311 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000312 /// appropriate TransformXXXStmt function to transform a specific kind of
313 /// statement or the TransformExpr() function to transform an expression.
314 /// Subclasses may override this function to transform statements using some
315 /// other mechanism.
316 ///
317 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000318 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000319
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000320 /// \brief Transform the given statement.
321 ///
322 /// By default, this routine transforms a statement by delegating to the
323 /// appropriate TransformOMPXXXClause function to transform a specific kind
324 /// of clause. Subclasses may override this function to transform statements
325 /// using some other mechanism.
326 ///
327 /// \returns the transformed OpenMP clause.
328 OMPClause *TransformOMPClause(OMPClause *S);
329
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000330 /// \brief Transform the given attribute.
331 ///
332 /// By default, this routine transforms a statement by delegating to the
333 /// appropriate TransformXXXAttr function to transform a specific kind
334 /// of attribute. Subclasses may override this function to transform
335 /// attributed statements using some other mechanism.
336 ///
337 /// \returns the transformed attribute
338 const Attr *TransformAttr(const Attr *S);
339
340/// \brief Transform the specified attribute.
341///
342/// Subclasses should override the transformation of attributes with a pragma
343/// spelling to transform expressions stored within the attribute.
344///
345/// \returns the transformed attribute.
346#define ATTR(X)
347#define PRAGMA_SPELLING_ATTR(X) \
348 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
349#include "clang/Basic/AttrList.inc"
350
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000351 /// \brief Transform the given expression.
352 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000353 /// By default, this routine transforms an expression by delegating to the
354 /// appropriate TransformXXXExpr function to build a new expression.
355 /// Subclasses may override this function to transform expressions using some
356 /// other mechanism.
357 ///
358 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000359 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000360
Richard Smithd59b8322012-12-19 01:39:02 +0000361 /// \brief Transform the given initializer.
362 ///
363 /// By default, this routine transforms an initializer by stripping off the
364 /// semantic nodes added by initialization, then passing the result to
365 /// TransformExpr or TransformExprs.
366 ///
367 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000368 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000369
Douglas Gregora3efea12011-01-03 19:04:46 +0000370 /// \brief Transform the given list of expressions.
371 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000372 /// This routine transforms a list of expressions by invoking
373 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000374 /// support for variadic templates by expanding any pack expansions (if the
375 /// derived class permits such expansion) along the way. When pack expansions
376 /// are present, the number of outputs may not equal the number of inputs.
377 ///
378 /// \param Inputs The set of expressions to be transformed.
379 ///
380 /// \param NumInputs The number of expressions in \c Inputs.
381 ///
382 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000383 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000384 /// be.
385 ///
386 /// \param Outputs The transformed input expressions will be added to this
387 /// vector.
388 ///
389 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
390 /// due to transformation.
391 ///
392 /// \returns true if an error occurred, false otherwise.
393 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000394 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000395 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000396
Douglas Gregord6ff3322009-08-04 16:50:30 +0000397 /// \brief Transform the given declaration, which is referenced from a type
398 /// or expression.
399 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000400 /// By default, acts as the identity function on declarations, unless the
401 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000402 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000403 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000404 llvm::DenseMap<Decl *, Decl *>::iterator Known
405 = TransformedLocalDecls.find(D);
406 if (Known != TransformedLocalDecls.end())
407 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
409 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000410 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000411
Chad Rosier1dcde962012-08-08 18:46:20 +0000412 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000413 /// place them on the new declaration.
414 ///
415 /// By default, this operation does nothing. Subclasses may override this
416 /// behavior to transform attributes.
417 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000418
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000419 /// \brief Note that a local declaration has been transformed by this
420 /// transformer.
421 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000422 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000423 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
424 /// the transformer itself has to transform the declarations. This routine
425 /// can be overridden by a subclass that keeps track of such mappings.
426 void transformedLocalDecl(Decl *Old, Decl *New) {
427 TransformedLocalDecls[Old] = New;
428 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000429
Douglas Gregorebe10102009-08-20 07:17:43 +0000430 /// \brief Transform the definition of the given declaration.
431 ///
Mike Stump11289f42009-09-09 15:08:12 +0000432 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000433 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000434 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
435 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000436 }
Mike Stump11289f42009-09-09 15:08:12 +0000437
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000438 /// \brief Transform the given declaration, which was the first part of a
439 /// nested-name-specifier in a member access expression.
440 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000441 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000442 /// identifier in a nested-name-specifier of a member access expression, e.g.,
443 /// the \c T in \c x->T::member
444 ///
445 /// By default, invokes TransformDecl() to transform the declaration.
446 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000447 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
448 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000449 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000450
Douglas Gregor14454802011-02-25 02:25:35 +0000451 /// \brief Transform the given nested-name-specifier with source-location
452 /// information.
453 ///
454 /// By default, transforms all of the types and declarations within the
455 /// nested-name-specifier. Subclasses may override this function to provide
456 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000457 NestedNameSpecifierLoc
458 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
459 QualType ObjectType = QualType(),
460 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000461
Douglas Gregorf816bd72009-09-03 22:13:48 +0000462 /// \brief Transform the given declaration name.
463 ///
464 /// By default, transforms the types of conversion function, constructor,
465 /// and destructor names and then (if needed) rebuilds the declaration name.
466 /// Identifiers and selectors are returned unmodified. Sublcasses may
467 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000468 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000469 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000470
Douglas Gregord6ff3322009-08-04 16:50:30 +0000471 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000472 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000473 /// \param SS The nested-name-specifier that qualifies the template
474 /// name. This nested-name-specifier must already have been transformed.
475 ///
476 /// \param Name The template name to transform.
477 ///
478 /// \param NameLoc The source location of the template name.
479 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000480 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000481 /// access expression, this is the type of the object whose member template
482 /// is being referenced.
483 ///
484 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
485 /// also refers to a name within the current (lexical) scope, this is the
486 /// declaration it refers to.
487 ///
488 /// By default, transforms the template name by transforming the declarations
489 /// and nested-name-specifiers that occur within the template name.
490 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000491 TemplateName
492 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
493 SourceLocation NameLoc,
494 QualType ObjectType = QualType(),
495 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000496
Douglas Gregord6ff3322009-08-04 16:50:30 +0000497 /// \brief Transform the given template argument.
498 ///
Mike Stump11289f42009-09-09 15:08:12 +0000499 /// By default, this operation transforms the type, expression, or
500 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000501 /// new template argument from the transformed result. Subclasses may
502 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000503 ///
504 /// Returns true if there was an error.
505 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
506 TemplateArgumentLoc &Output);
507
Douglas Gregor62e06f22010-12-20 17:31:10 +0000508 /// \brief Transform the given set of template arguments.
509 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000510 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000511 /// in the input set using \c TransformTemplateArgument(), and appends
512 /// the transformed arguments to the output list.
513 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000514 /// Note that this overload of \c TransformTemplateArguments() is merely
515 /// a convenience function. Subclasses that wish to override this behavior
516 /// should override the iterator-based member template version.
517 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000518 /// \param Inputs The set of template arguments to be transformed.
519 ///
520 /// \param NumInputs The number of template arguments in \p Inputs.
521 ///
522 /// \param Outputs The set of transformed template arguments output by this
523 /// routine.
524 ///
525 /// Returns true if an error occurred.
526 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
527 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000528 TemplateArgumentListInfo &Outputs) {
529 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
530 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000531
532 /// \brief Transform the given set of template arguments.
533 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000534 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000535 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000536 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000537 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000538 /// \param First An iterator to the first template argument.
539 ///
540 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000541 ///
542 /// \param Outputs The set of transformed template arguments output by this
543 /// routine.
544 ///
545 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000546 template<typename InputIterator>
547 bool TransformTemplateArguments(InputIterator First,
548 InputIterator Last,
549 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000550
John McCall0ad16662009-10-29 08:12:44 +0000551 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
552 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
553 TemplateArgumentLoc &ArgLoc);
554
John McCallbcd03502009-12-07 02:54:59 +0000555 /// \brief Fakes up a TypeSourceInfo for a type.
556 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
557 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000558 getDerived().getBaseLocation());
559 }
Mike Stump11289f42009-09-09 15:08:12 +0000560
John McCall550e0c22009-10-21 00:40:46 +0000561#define ABSTRACT_TYPELOC(CLASS, PARENT)
562#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000563 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000564#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000565
Douglas Gregor3024f072012-04-16 07:05:22 +0000566 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
567 FunctionProtoTypeLoc TL,
568 CXXRecordDecl *ThisContext,
NAKAMURA Takumi23224152014-10-17 12:48:37 +0000569 unsigned ThisTypeQuals);
Douglas Gregor3024f072012-04-16 07:05:22 +0000570
David Majnemerfad8f482013-10-15 09:33:02 +0000571 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000572
Chad Rosier1dcde962012-08-08 18:46:20 +0000573 QualType
John McCall31f82722010-11-12 08:19:04 +0000574 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
575 TemplateSpecializationTypeLoc TL,
576 TemplateName Template);
577
Chad Rosier1dcde962012-08-08 18:46:20 +0000578 QualType
John McCall31f82722010-11-12 08:19:04 +0000579 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
580 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000581 TemplateName Template,
582 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000583
Nico Weberc153d242014-07-28 00:02:09 +0000584 QualType TransformDependentTemplateSpecializationType(
585 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
586 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000587
John McCall58f10c32010-03-11 09:03:00 +0000588 /// \brief Transforms the parameters of a function type into the
589 /// given vectors.
590 ///
591 /// The result vectors should be kept in sync; null entries in the
592 /// variables vector are acceptable.
593 ///
594 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000595 bool TransformFunctionTypeParams(SourceLocation Loc,
596 ParmVarDecl **Params, unsigned NumParams,
597 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000598 SmallVectorImpl<QualType> &PTypes,
599 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000600
601 /// \brief Transforms a single function-type parameter. Return null
602 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000603 ///
604 /// \param indexAdjustment - A number to add to the parameter's
605 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000606 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000607 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000608 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000609 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000610
John McCall31f82722010-11-12 08:19:04 +0000611 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000612
John McCalldadc5752010-08-24 06:29:42 +0000613 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
614 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000615
616 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000617 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000618 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
619 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000620
Faisal Vali2cba1332013-10-23 06:44:28 +0000621 TemplateParameterList *TransformTemplateParameterList(
622 TemplateParameterList *TPL) {
623 return TPL;
624 }
625
Richard Smithdb2630f2012-10-21 03:28:35 +0000626 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000627
Richard Smithdb2630f2012-10-21 03:28:35 +0000628 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000629 bool IsAddressOfOperand,
630 TypeSourceInfo **RecoveryTSI);
631
632 ExprResult TransformParenDependentScopeDeclRefExpr(
633 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
634 TypeSourceInfo **RecoveryTSI);
635
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000636 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000637
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000638// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
639// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000640#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000641 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000642 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000643#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000644 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000645 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000646#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000647#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000648
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000649#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000650 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000651 OMPClause *Transform ## Class(Class *S);
652#include "clang/Basic/OpenMPKinds.def"
653
Douglas Gregord6ff3322009-08-04 16:50:30 +0000654 /// \brief Build a new pointer type given its pointee type.
655 ///
656 /// By default, performs semantic analysis when building the pointer type.
657 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000658 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659
660 /// \brief Build a new block pointer type given its pointee type.
661 ///
Mike Stump11289f42009-09-09 15:08:12 +0000662 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000663 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000664 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000665
John McCall70dd5f62009-10-30 00:06:24 +0000666 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667 ///
John McCall70dd5f62009-10-30 00:06:24 +0000668 /// By default, performs semantic analysis when building the
669 /// reference type. Subclasses may override this routine to provide
670 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000671 ///
John McCall70dd5f62009-10-30 00:06:24 +0000672 /// \param LValue whether the type was written with an lvalue sigil
673 /// or an rvalue sigil.
674 QualType RebuildReferenceType(QualType ReferentType,
675 bool LValue,
676 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000677
Douglas Gregord6ff3322009-08-04 16:50:30 +0000678 /// \brief Build a new member pointer type given the pointee type and the
679 /// class type it refers into.
680 ///
681 /// By default, performs semantic analysis when building the member pointer
682 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000683 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
684 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000685
Douglas Gregord6ff3322009-08-04 16:50:30 +0000686 /// \brief Build a new array type given the element type, size
687 /// modifier, size of the array (if known), size expression, and index type
688 /// qualifiers.
689 ///
690 /// By default, performs semantic analysis when building the array type.
691 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000692 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000693 QualType RebuildArrayType(QualType ElementType,
694 ArrayType::ArraySizeModifier SizeMod,
695 const llvm::APInt *Size,
696 Expr *SizeExpr,
697 unsigned IndexTypeQuals,
698 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000699
Douglas Gregord6ff3322009-08-04 16:50:30 +0000700 /// \brief Build a new constant array type given the element type, size
701 /// modifier, (known) size of the array, and index type qualifiers.
702 ///
703 /// By default, performs semantic analysis when building the array type.
704 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000705 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000706 ArrayType::ArraySizeModifier SizeMod,
707 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000708 unsigned IndexTypeQuals,
709 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000710
Douglas Gregord6ff3322009-08-04 16:50:30 +0000711 /// \brief Build a new incomplete array type given the element type, size
712 /// modifier, and index type qualifiers.
713 ///
714 /// By default, performs semantic analysis when building the array type.
715 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000716 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000717 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000718 unsigned IndexTypeQuals,
719 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000720
Mike Stump11289f42009-09-09 15:08:12 +0000721 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000722 /// size modifier, size expression, and index type qualifiers.
723 ///
724 /// By default, performs semantic analysis when building the array type.
725 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000726 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000727 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000728 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000729 unsigned IndexTypeQuals,
730 SourceRange BracketsRange);
731
Mike Stump11289f42009-09-09 15:08:12 +0000732 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000733 /// size modifier, size expression, and index type qualifiers.
734 ///
735 /// By default, performs semantic analysis when building the array type.
736 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000737 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000738 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000739 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 unsigned IndexTypeQuals,
741 SourceRange BracketsRange);
742
743 /// \brief Build a new vector type given the element type and
744 /// number of elements.
745 ///
746 /// By default, performs semantic analysis when building the vector type.
747 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000748 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000749 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000750
Douglas Gregord6ff3322009-08-04 16:50:30 +0000751 /// \brief Build a new extended vector type given the element type and
752 /// number of elements.
753 ///
754 /// By default, performs semantic analysis when building the vector type.
755 /// Subclasses may override this routine to provide different behavior.
756 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
757 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000758
759 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000760 /// given the element type and number of elements.
761 ///
762 /// By default, performs semantic analysis when building the vector type.
763 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000764 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000765 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000766 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000767
Douglas Gregord6ff3322009-08-04 16:50:30 +0000768 /// \brief Build a new function type.
769 ///
770 /// By default, performs semantic analysis when building the function type.
771 /// Subclasses may override this routine to provide different behavior.
772 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000773 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000774 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000775
John McCall550e0c22009-10-21 00:40:46 +0000776 /// \brief Build a new unprototyped function type.
777 QualType RebuildFunctionNoProtoType(QualType ResultType);
778
John McCallb96ec562009-12-04 22:46:56 +0000779 /// \brief Rebuild an unresolved typename type, given the decl that
780 /// the UnresolvedUsingTypenameDecl was transformed to.
781 QualType RebuildUnresolvedUsingType(Decl *D);
782
Douglas Gregord6ff3322009-08-04 16:50:30 +0000783 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000784 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000785 return SemaRef.Context.getTypeDeclType(Typedef);
786 }
787
788 /// \brief Build a new class/struct/union type.
789 QualType RebuildRecordType(RecordDecl *Record) {
790 return SemaRef.Context.getTypeDeclType(Record);
791 }
792
793 /// \brief Build a new Enum type.
794 QualType RebuildEnumType(EnumDecl *Enum) {
795 return SemaRef.Context.getTypeDeclType(Enum);
796 }
John McCallfcc33b02009-09-05 00:15:47 +0000797
Mike Stump11289f42009-09-09 15:08:12 +0000798 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000799 ///
800 /// By default, performs semantic analysis when building the typeof type.
801 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000802 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000803
Mike Stump11289f42009-09-09 15:08:12 +0000804 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000805 ///
806 /// By default, builds a new TypeOfType with the given underlying type.
807 QualType RebuildTypeOfType(QualType Underlying);
808
Alexis Hunte852b102011-05-24 22:41:36 +0000809 /// \brief Build a new unary transform type.
810 QualType RebuildUnaryTransformType(QualType BaseType,
811 UnaryTransformType::UTTKind UKind,
812 SourceLocation Loc);
813
Richard Smith74aeef52013-04-26 16:15:35 +0000814 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000815 ///
816 /// By default, performs semantic analysis when building the decltype type.
817 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000818 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000819
Richard Smith74aeef52013-04-26 16:15:35 +0000820 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000821 ///
822 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000823 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000824 // Note, IsDependent is always false here: we implicitly convert an 'auto'
825 // which has been deduced to a dependent type into an undeduced 'auto', so
826 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000827 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
828 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000829 }
830
Douglas Gregord6ff3322009-08-04 16:50:30 +0000831 /// \brief Build a new template specialization type.
832 ///
833 /// By default, performs semantic analysis when building the template
834 /// specialization type. Subclasses may override this routine to provide
835 /// different behavior.
836 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000837 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000838 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000839
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000840 /// \brief Build a new parenthesized type.
841 ///
842 /// By default, builds a new ParenType type from the inner type.
843 /// Subclasses may override this routine to provide different behavior.
844 QualType RebuildParenType(QualType InnerType) {
845 return SemaRef.Context.getParenType(InnerType);
846 }
847
Douglas Gregord6ff3322009-08-04 16:50:30 +0000848 /// \brief Build a new qualified name type.
849 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000850 /// By default, builds a new ElaboratedType type from the keyword,
851 /// the nested-name-specifier and the named type.
852 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000853 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
854 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000855 NestedNameSpecifierLoc QualifierLoc,
856 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000857 return SemaRef.Context.getElaboratedType(Keyword,
858 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000859 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000860 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000861
862 /// \brief Build a new typename type that refers to a template-id.
863 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000864 /// By default, builds a new DependentNameType type from the
865 /// nested-name-specifier and the given type. Subclasses may override
866 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000867 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000868 ElaboratedTypeKeyword Keyword,
869 NestedNameSpecifierLoc QualifierLoc,
870 const IdentifierInfo *Name,
871 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000872 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000873 // Rebuild the template name.
874 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000875 CXXScopeSpec SS;
876 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000877 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000878 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
879 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000880
Douglas Gregora7a795b2011-03-01 20:11:18 +0000881 if (InstName.isNull())
882 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000883
Douglas Gregora7a795b2011-03-01 20:11:18 +0000884 // If it's still dependent, make a dependent specialization.
885 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000886 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
887 QualifierLoc.getNestedNameSpecifier(),
888 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000889 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000890
Douglas Gregora7a795b2011-03-01 20:11:18 +0000891 // Otherwise, make an elaborated type wrapping a non-dependent
892 // specialization.
893 QualType T =
894 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
895 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000896
Craig Topperc3ec1492014-05-26 06:22:03 +0000897 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000898 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000899
900 return SemaRef.Context.getElaboratedType(Keyword,
901 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000902 T);
903 }
904
Douglas Gregord6ff3322009-08-04 16:50:30 +0000905 /// \brief Build a new typename type that refers to an identifier.
906 ///
907 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000908 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000909 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000910 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000911 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000912 NestedNameSpecifierLoc QualifierLoc,
913 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000914 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000915 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000916 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000917
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000918 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000919 // If the name is still dependent, just build a new dependent name type.
920 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000921 return SemaRef.Context.getDependentNameType(Keyword,
922 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000923 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000924 }
925
Abramo Bagnara6150c882010-05-11 21:36:43 +0000926 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000927 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000928 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000929
930 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
931
Abramo Bagnarad7548482010-05-19 21:37:53 +0000932 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000933 // into a non-dependent elaborated-type-specifier. Find the tag we're
934 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000935 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000936 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
937 if (!DC)
938 return QualType();
939
John McCallbf8c5192010-05-27 06:40:31 +0000940 if (SemaRef.RequireCompleteDeclContext(SS, DC))
941 return QualType();
942
Craig Topperc3ec1492014-05-26 06:22:03 +0000943 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000944 SemaRef.LookupQualifiedName(Result, DC);
945 switch (Result.getResultKind()) {
946 case LookupResult::NotFound:
947 case LookupResult::NotFoundInCurrentInstantiation:
948 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000949
Douglas Gregore677daf2010-03-31 22:19:08 +0000950 case LookupResult::Found:
951 Tag = Result.getAsSingle<TagDecl>();
952 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000953
Douglas Gregore677daf2010-03-31 22:19:08 +0000954 case LookupResult::FoundOverloaded:
955 case LookupResult::FoundUnresolvedValue:
956 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000957
Douglas Gregore677daf2010-03-31 22:19:08 +0000958 case LookupResult::Ambiguous:
959 // Let the LookupResult structure handle ambiguities.
960 return QualType();
961 }
962
963 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000964 // Check where the name exists but isn't a tag type and use that to emit
965 // better diagnostics.
966 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
967 SemaRef.LookupQualifiedName(Result, DC);
968 switch (Result.getResultKind()) {
969 case LookupResult::Found:
970 case LookupResult::FoundOverloaded:
971 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000972 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000973 unsigned Kind = 0;
974 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000975 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
976 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000977 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
978 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
979 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000980 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000981 default:
Nick Lewycky0c438082011-01-24 19:01:04 +0000982 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000983 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000984 break;
985 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000986 return QualType();
987 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000988
Richard Trieucaa33d32011-06-10 03:11:26 +0000989 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
990 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000991 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000992 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
993 return QualType();
994 }
995
996 // Build the elaborated-type-specifier type.
997 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000998 return SemaRef.Context.getElaboratedType(Keyword,
999 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001000 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001001 }
Mike Stump11289f42009-09-09 15:08:12 +00001002
Douglas Gregor822d0302011-01-12 17:07:58 +00001003 /// \brief Build a new pack expansion type.
1004 ///
1005 /// By default, builds a new PackExpansionType type from the given pattern.
1006 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001007 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001008 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001009 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001010 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001011 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1012 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001013 }
1014
Eli Friedman0dfb8892011-10-06 23:00:33 +00001015 /// \brief Build a new atomic type given its value type.
1016 ///
1017 /// By default, performs semantic analysis when building the atomic type.
1018 /// Subclasses may override this routine to provide different behavior.
1019 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1020
Douglas Gregor71dc5092009-08-06 06:41:21 +00001021 /// \brief Build a new template name given a nested name specifier, a flag
1022 /// indicating whether the "template" keyword was provided, and the template
1023 /// that the template name refers to.
1024 ///
1025 /// By default, builds the new template name directly. Subclasses may override
1026 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001027 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001028 bool TemplateKW,
1029 TemplateDecl *Template);
1030
Douglas Gregor71dc5092009-08-06 06:41:21 +00001031 /// \brief Build a new template name given a nested name specifier and the
1032 /// name that is referred to as a template.
1033 ///
1034 /// By default, performs semantic analysis to determine whether the name can
1035 /// be resolved to a specific template, then builds the appropriate kind of
1036 /// template name. Subclasses may override this routine to provide different
1037 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001038 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1039 const IdentifierInfo &Name,
1040 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001041 QualType ObjectType,
1042 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001043
Douglas Gregor71395fa2009-11-04 00:56:37 +00001044 /// \brief Build a new template name given a nested name specifier and the
1045 /// overloaded operator name that is referred to as a template.
1046 ///
1047 /// By default, performs semantic analysis to determine whether the name can
1048 /// be resolved to a specific template, then builds the appropriate kind of
1049 /// template name. Subclasses may override this routine to provide different
1050 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001051 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001052 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001053 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001054 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001055
1056 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001057 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001058 ///
1059 /// By default, performs semantic analysis to determine whether the name can
1060 /// be resolved to a specific template, then builds the appropriate kind of
1061 /// template name. Subclasses may override this routine to provide different
1062 /// behavior.
1063 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1064 const TemplateArgument &ArgPack) {
1065 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1066 }
1067
Douglas Gregorebe10102009-08-20 07:17:43 +00001068 /// \brief Build a new compound statement.
1069 ///
1070 /// By default, performs semantic analysis to build the new statement.
1071 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001072 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001073 MultiStmtArg Statements,
1074 SourceLocation RBraceLoc,
1075 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001076 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001077 IsStmtExpr);
1078 }
1079
1080 /// \brief Build a new case statement.
1081 ///
1082 /// By default, performs semantic analysis to build the new statement.
1083 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001084 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001085 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001086 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001087 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001088 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001089 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001090 ColonLoc);
1091 }
Mike Stump11289f42009-09-09 15:08:12 +00001092
Douglas Gregorebe10102009-08-20 07:17:43 +00001093 /// \brief Attach the body to a new case statement.
1094 ///
1095 /// By default, performs semantic analysis to build the new statement.
1096 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001097 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001098 getSema().ActOnCaseStmtBody(S, Body);
1099 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001100 }
Mike Stump11289f42009-09-09 15:08:12 +00001101
Douglas Gregorebe10102009-08-20 07:17:43 +00001102 /// \brief Build a new default statement.
1103 ///
1104 /// By default, performs semantic analysis to build the new statement.
1105 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001106 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001107 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001108 Stmt *SubStmt) {
1109 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001110 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001111 }
Mike Stump11289f42009-09-09 15:08:12 +00001112
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 /// \brief Build a new label statement.
1114 ///
1115 /// By default, performs semantic analysis to build the new statement.
1116 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001117 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1118 SourceLocation ColonLoc, Stmt *SubStmt) {
1119 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001120 }
Mike Stump11289f42009-09-09 15:08:12 +00001121
Richard Smithc202b282012-04-14 00:33:13 +00001122 /// \brief Build a new label statement.
1123 ///
1124 /// By default, performs semantic analysis to build the new statement.
1125 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001126 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1127 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001128 Stmt *SubStmt) {
1129 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1130 }
1131
Douglas Gregorebe10102009-08-20 07:17:43 +00001132 /// \brief Build a new "if" statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001136 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001137 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001138 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001139 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001140 }
Mike Stump11289f42009-09-09 15:08:12 +00001141
Douglas Gregorebe10102009-08-20 07:17:43 +00001142 /// \brief Start building a new switch statement.
1143 ///
1144 /// By default, performs semantic analysis to build the new statement.
1145 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001146 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001147 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001148 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001149 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001150 }
Mike Stump11289f42009-09-09 15:08:12 +00001151
Douglas Gregorebe10102009-08-20 07:17:43 +00001152 /// \brief Attach the body to the switch statement.
1153 ///
1154 /// By default, performs semantic analysis to build the new statement.
1155 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001156 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001157 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001158 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001159 }
1160
1161 /// \brief Build a new while statement.
1162 ///
1163 /// By default, performs semantic analysis to build the new statement.
1164 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001165 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1166 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001167 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001168 }
Mike Stump11289f42009-09-09 15:08:12 +00001169
Douglas Gregorebe10102009-08-20 07:17:43 +00001170 /// \brief Build a new do-while statement.
1171 ///
1172 /// By default, performs semantic analysis to build the new statement.
1173 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001174 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001175 SourceLocation WhileLoc, SourceLocation LParenLoc,
1176 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001177 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1178 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001179 }
1180
1181 /// \brief Build a new for statement.
1182 ///
1183 /// By default, performs semantic analysis to build the new statement.
1184 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001185 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001186 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001187 VarDecl *CondVar, Sema::FullExprArg Inc,
1188 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001189 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001190 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001191 }
Mike Stump11289f42009-09-09 15:08:12 +00001192
Douglas Gregorebe10102009-08-20 07:17:43 +00001193 /// \brief Build a new goto statement.
1194 ///
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001197 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1198 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001199 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001200 }
1201
1202 /// \brief Build a new indirect goto statement.
1203 ///
1204 /// By default, performs semantic analysis to build the new statement.
1205 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001206 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001207 SourceLocation StarLoc,
1208 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001209 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001210 }
Mike Stump11289f42009-09-09 15:08:12 +00001211
Douglas Gregorebe10102009-08-20 07:17:43 +00001212 /// \brief Build a new return statement.
1213 ///
1214 /// By default, performs semantic analysis to build the new statement.
1215 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001216 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001217 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001218 }
Mike Stump11289f42009-09-09 15:08:12 +00001219
Douglas Gregorebe10102009-08-20 07:17:43 +00001220 /// \brief Build a new declaration statement.
1221 ///
1222 /// By default, performs semantic analysis to build the new statement.
1223 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001224 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001225 SourceLocation StartLoc, SourceLocation EndLoc) {
1226 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001227 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001228 }
Mike Stump11289f42009-09-09 15:08:12 +00001229
Anders Carlssonaaeef072010-01-24 05:50:09 +00001230 /// \brief Build a new inline asm statement.
1231 ///
1232 /// By default, performs semantic analysis to build the new statement.
1233 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001234 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1235 bool IsVolatile, unsigned NumOutputs,
1236 unsigned NumInputs, IdentifierInfo **Names,
1237 MultiExprArg Constraints, MultiExprArg Exprs,
1238 Expr *AsmString, MultiExprArg Clobbers,
1239 SourceLocation RParenLoc) {
1240 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1241 NumInputs, Names, Constraints, Exprs,
1242 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001243 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001244
Chad Rosier32503022012-06-11 20:47:18 +00001245 /// \brief Build a new MS style inline asm statement.
1246 ///
1247 /// By default, performs semantic analysis to build the new statement.
1248 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001249 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001250 ArrayRef<Token> AsmToks,
1251 StringRef AsmString,
1252 unsigned NumOutputs, unsigned NumInputs,
1253 ArrayRef<StringRef> Constraints,
1254 ArrayRef<StringRef> Clobbers,
1255 ArrayRef<Expr*> Exprs,
1256 SourceLocation EndLoc) {
1257 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1258 NumOutputs, NumInputs,
1259 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001260 }
1261
James Dennett2a4d13c2012-06-15 07:13:21 +00001262 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001263 ///
1264 /// By default, performs semantic analysis to build the new statement.
1265 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001266 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001267 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001268 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001269 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001270 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001271 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001272 }
1273
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001274 /// \brief Rebuild an Objective-C exception declaration.
1275 ///
1276 /// By default, performs semantic analysis to build the new declaration.
1277 /// Subclasses may override this routine to provide different behavior.
1278 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1279 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001280 return getSema().BuildObjCExceptionDecl(TInfo, T,
1281 ExceptionDecl->getInnerLocStart(),
1282 ExceptionDecl->getLocation(),
1283 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001284 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001285
James Dennett2a4d13c2012-06-15 07:13:21 +00001286 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001287 ///
1288 /// By default, performs semantic analysis to build the new statement.
1289 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001290 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001291 SourceLocation RParenLoc,
1292 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001293 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001294 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001295 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001296 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001297
James Dennett2a4d13c2012-06-15 07:13:21 +00001298 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001299 ///
1300 /// By default, performs semantic analysis to build the new statement.
1301 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001302 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001303 Stmt *Body) {
1304 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001305 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001306
James Dennett2a4d13c2012-06-15 07:13:21 +00001307 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001308 ///
1309 /// By default, performs semantic analysis to build the new statement.
1310 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001311 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001312 Expr *Operand) {
1313 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001314 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001315
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001316 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001317 ///
1318 /// By default, performs semantic analysis to build the new statement.
1319 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001320 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001321 DeclarationNameInfo DirName,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001322 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001323 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001324 SourceLocation EndLoc) {
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001325 return getSema().ActOnOpenMPExecutableDirective(Kind, DirName, Clauses,
1326 AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001327 }
1328
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001329 /// \brief Build a new OpenMP 'if' clause.
1330 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001331 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001332 /// Subclasses may override this routine to provide different behavior.
1333 OMPClause *RebuildOMPIfClause(Expr *Condition,
1334 SourceLocation StartLoc,
1335 SourceLocation LParenLoc,
1336 SourceLocation EndLoc) {
1337 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1338 LParenLoc, EndLoc);
1339 }
1340
Alexey Bataev3778b602014-07-17 07:32:53 +00001341 /// \brief Build a new OpenMP 'final' clause.
1342 ///
1343 /// By default, performs semantic analysis to build the new OpenMP clause.
1344 /// Subclasses may override this routine to provide different behavior.
1345 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1346 SourceLocation LParenLoc,
1347 SourceLocation EndLoc) {
1348 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1349 EndLoc);
1350 }
1351
Alexey Bataev568a8332014-03-06 06:15:19 +00001352 /// \brief Build a new OpenMP 'num_threads' clause.
1353 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001354 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001355 /// Subclasses may override this routine to provide different behavior.
1356 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1357 SourceLocation StartLoc,
1358 SourceLocation LParenLoc,
1359 SourceLocation EndLoc) {
1360 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1361 LParenLoc, EndLoc);
1362 }
1363
Alexey Bataev62c87d22014-03-21 04:51:18 +00001364 /// \brief Build a new OpenMP 'safelen' clause.
1365 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001366 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001367 /// Subclasses may override this routine to provide different behavior.
1368 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1369 SourceLocation LParenLoc,
1370 SourceLocation EndLoc) {
1371 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1372 }
1373
Alexander Musman8bd31e62014-05-27 15:12:19 +00001374 /// \brief Build a new OpenMP 'collapse' clause.
1375 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001376 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001377 /// Subclasses may override this routine to provide different behavior.
1378 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1379 SourceLocation LParenLoc,
1380 SourceLocation EndLoc) {
1381 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1382 EndLoc);
1383 }
1384
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001385 /// \brief Build a new OpenMP 'default' clause.
1386 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001387 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001388 /// Subclasses may override this routine to provide different behavior.
1389 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1390 SourceLocation KindKwLoc,
1391 SourceLocation StartLoc,
1392 SourceLocation LParenLoc,
1393 SourceLocation EndLoc) {
1394 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1395 StartLoc, LParenLoc, EndLoc);
1396 }
1397
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001398 /// \brief Build a new OpenMP 'proc_bind' clause.
1399 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001400 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001401 /// Subclasses may override this routine to provide different behavior.
1402 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1403 SourceLocation KindKwLoc,
1404 SourceLocation StartLoc,
1405 SourceLocation LParenLoc,
1406 SourceLocation EndLoc) {
1407 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1408 StartLoc, LParenLoc, EndLoc);
1409 }
1410
Alexey Bataev56dafe82014-06-20 07:16:17 +00001411 /// \brief Build a new OpenMP 'schedule' clause.
1412 ///
1413 /// By default, performs semantic analysis to build the new OpenMP clause.
1414 /// Subclasses may override this routine to provide different behavior.
1415 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1416 Expr *ChunkSize,
1417 SourceLocation StartLoc,
1418 SourceLocation LParenLoc,
1419 SourceLocation KindLoc,
1420 SourceLocation CommaLoc,
1421 SourceLocation EndLoc) {
1422 return getSema().ActOnOpenMPScheduleClause(
1423 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1424 }
1425
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001426 /// \brief Build a new OpenMP 'private' clause.
1427 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001428 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001429 /// Subclasses may override this routine to provide different behavior.
1430 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1431 SourceLocation StartLoc,
1432 SourceLocation LParenLoc,
1433 SourceLocation EndLoc) {
1434 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1435 EndLoc);
1436 }
1437
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001438 /// \brief Build a new OpenMP 'firstprivate' clause.
1439 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001440 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001441 /// Subclasses may override this routine to provide different behavior.
1442 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1443 SourceLocation StartLoc,
1444 SourceLocation LParenLoc,
1445 SourceLocation EndLoc) {
1446 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1447 EndLoc);
1448 }
1449
Alexander Musman1bb328c2014-06-04 13:06:39 +00001450 /// \brief Build a new OpenMP 'lastprivate' clause.
1451 ///
1452 /// By default, performs semantic analysis to build the new OpenMP clause.
1453 /// Subclasses may override this routine to provide different behavior.
1454 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1455 SourceLocation StartLoc,
1456 SourceLocation LParenLoc,
1457 SourceLocation EndLoc) {
1458 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1459 EndLoc);
1460 }
1461
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001462 /// \brief Build a new OpenMP 'shared' clause.
1463 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001464 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001465 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001466 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1467 SourceLocation StartLoc,
1468 SourceLocation LParenLoc,
1469 SourceLocation EndLoc) {
1470 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1471 EndLoc);
1472 }
1473
Alexey Bataevc5e02582014-06-16 07:08:35 +00001474 /// \brief Build a new OpenMP 'reduction' clause.
1475 ///
1476 /// By default, performs semantic analysis to build the new statement.
1477 /// Subclasses may override this routine to provide different behavior.
1478 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1479 SourceLocation StartLoc,
1480 SourceLocation LParenLoc,
1481 SourceLocation ColonLoc,
1482 SourceLocation EndLoc,
1483 CXXScopeSpec &ReductionIdScopeSpec,
1484 const DeclarationNameInfo &ReductionId) {
1485 return getSema().ActOnOpenMPReductionClause(
1486 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1487 ReductionId);
1488 }
1489
Alexander Musman8dba6642014-04-22 13:09:42 +00001490 /// \brief Build a new OpenMP 'linear' clause.
1491 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001492 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001493 /// Subclasses may override this routine to provide different behavior.
1494 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1495 SourceLocation StartLoc,
1496 SourceLocation LParenLoc,
1497 SourceLocation ColonLoc,
1498 SourceLocation EndLoc) {
1499 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1500 ColonLoc, EndLoc);
1501 }
1502
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001503 /// \brief Build a new OpenMP 'aligned' clause.
1504 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001505 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001506 /// Subclasses may override this routine to provide different behavior.
1507 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1508 SourceLocation StartLoc,
1509 SourceLocation LParenLoc,
1510 SourceLocation ColonLoc,
1511 SourceLocation EndLoc) {
1512 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1513 LParenLoc, ColonLoc, EndLoc);
1514 }
1515
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001516 /// \brief Build a new OpenMP 'copyin' clause.
1517 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001518 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001519 /// Subclasses may override this routine to provide different behavior.
1520 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1521 SourceLocation StartLoc,
1522 SourceLocation LParenLoc,
1523 SourceLocation EndLoc) {
1524 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1525 EndLoc);
1526 }
1527
Alexey Bataevbae9a792014-06-27 10:37:06 +00001528 /// \brief Build a new OpenMP 'copyprivate' clause.
1529 ///
1530 /// By default, performs semantic analysis to build the new OpenMP clause.
1531 /// Subclasses may override this routine to provide different behavior.
1532 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1533 SourceLocation StartLoc,
1534 SourceLocation LParenLoc,
1535 SourceLocation EndLoc) {
1536 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1537 EndLoc);
1538 }
1539
Alexey Bataev6125da92014-07-21 11:26:11 +00001540 /// \brief Build a new OpenMP 'flush' pseudo clause.
1541 ///
1542 /// By default, performs semantic analysis to build the new OpenMP clause.
1543 /// Subclasses may override this routine to provide different behavior.
1544 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1545 SourceLocation StartLoc,
1546 SourceLocation LParenLoc,
1547 SourceLocation EndLoc) {
1548 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1549 EndLoc);
1550 }
1551
James Dennett2a4d13c2012-06-15 07:13:21 +00001552 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001553 ///
1554 /// By default, performs semantic analysis to build the new statement.
1555 /// Subclasses may override this routine to provide different behavior.
1556 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1557 Expr *object) {
1558 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1559 }
1560
James Dennett2a4d13c2012-06-15 07:13:21 +00001561 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001562 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001563 /// By default, performs semantic analysis to build the new statement.
1564 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001565 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001566 Expr *Object, Stmt *Body) {
1567 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001568 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001569
James Dennett2a4d13c2012-06-15 07:13:21 +00001570 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001571 ///
1572 /// By default, performs semantic analysis to build the new statement.
1573 /// Subclasses may override this routine to provide different behavior.
1574 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1575 Stmt *Body) {
1576 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1577 }
John McCall53848232011-07-27 01:07:15 +00001578
Douglas Gregorf68a5082010-04-22 23:10:45 +00001579 /// \brief Build a new Objective-C fast enumeration statement.
1580 ///
1581 /// By default, performs semantic analysis to build the new statement.
1582 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001583 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001584 Stmt *Element,
1585 Expr *Collection,
1586 SourceLocation RParenLoc,
1587 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001588 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001589 Element,
John McCallb268a282010-08-23 23:25:46 +00001590 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001591 RParenLoc);
1592 if (ForEachStmt.isInvalid())
1593 return StmtError();
1594
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001595 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001596 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001597
Douglas Gregorebe10102009-08-20 07:17:43 +00001598 /// \brief Build a new C++ exception declaration.
1599 ///
1600 /// By default, performs semantic analysis to build the new decaration.
1601 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001602 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001603 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001604 SourceLocation StartLoc,
1605 SourceLocation IdLoc,
1606 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001607 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001608 StartLoc, IdLoc, Id);
1609 if (Var)
1610 getSema().CurContext->addDecl(Var);
1611 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001612 }
1613
1614 /// \brief Build a new C++ catch statement.
1615 ///
1616 /// By default, performs semantic analysis to build the new statement.
1617 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001618 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001619 VarDecl *ExceptionDecl,
1620 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001621 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1622 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001623 }
Mike Stump11289f42009-09-09 15:08:12 +00001624
Douglas Gregorebe10102009-08-20 07:17:43 +00001625 /// \brief Build a new C++ try statement.
1626 ///
1627 /// By default, performs semantic analysis to build the new statement.
1628 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001629 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1630 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001631 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001632 }
Mike Stump11289f42009-09-09 15:08:12 +00001633
Richard Smith02e85f32011-04-14 22:09:26 +00001634 /// \brief Build a new C++0x range-based for statement.
1635 ///
1636 /// By default, performs semantic analysis to build the new statement.
1637 /// Subclasses may override this routine to provide different behavior.
1638 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1639 SourceLocation ColonLoc,
1640 Stmt *Range, Stmt *BeginEnd,
1641 Expr *Cond, Expr *Inc,
1642 Stmt *LoopVar,
1643 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001644 // If we've just learned that the range is actually an Objective-C
1645 // collection, treat this as an Objective-C fast enumeration loop.
1646 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1647 if (RangeStmt->isSingleDecl()) {
1648 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001649 if (RangeVar->isInvalidDecl())
1650 return StmtError();
1651
Douglas Gregorf7106af2013-04-08 18:40:13 +00001652 Expr *RangeExpr = RangeVar->getInit();
1653 if (!RangeExpr->isTypeDependent() &&
1654 RangeExpr->getType()->isObjCObjectPointerType())
1655 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1656 RParenLoc);
1657 }
1658 }
1659 }
1660
Richard Smith02e85f32011-04-14 22:09:26 +00001661 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001662 Cond, Inc, LoopVar, RParenLoc,
1663 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001664 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001665
1666 /// \brief Build a new C++0x range-based for statement.
1667 ///
1668 /// By default, performs semantic analysis to build the new statement.
1669 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001670 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001671 bool IsIfExists,
1672 NestedNameSpecifierLoc QualifierLoc,
1673 DeclarationNameInfo NameInfo,
1674 Stmt *Nested) {
1675 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1676 QualifierLoc, NameInfo, Nested);
1677 }
1678
Richard Smith02e85f32011-04-14 22:09:26 +00001679 /// \brief Attach body to a C++0x range-based for statement.
1680 ///
1681 /// By default, performs semantic analysis to finish the new statement.
1682 /// Subclasses may override this routine to provide different behavior.
1683 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1684 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1685 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001686
David Majnemerfad8f482013-10-15 09:33:02 +00001687 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001688 Stmt *TryBlock, Stmt *Handler) {
1689 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001690 }
1691
David Majnemerfad8f482013-10-15 09:33:02 +00001692 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001693 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001694 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001695 }
1696
David Majnemerfad8f482013-10-15 09:33:02 +00001697 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1698 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001699 }
1700
Alexey Bataevec474782014-10-09 08:45:04 +00001701 /// \brief Build a new predefined expression.
1702 ///
1703 /// By default, performs semantic analysis to build the new expression.
1704 /// Subclasses may override this routine to provide different behavior.
1705 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1706 PredefinedExpr::IdentType IT) {
1707 return getSema().BuildPredefinedExpr(Loc, IT);
1708 }
1709
Douglas Gregora16548e2009-08-11 05:31:07 +00001710 /// \brief Build a new expression that references a declaration.
1711 ///
1712 /// By default, performs semantic analysis to build the new expression.
1713 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001714 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001715 LookupResult &R,
1716 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001717 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1718 }
1719
1720
1721 /// \brief Build a new expression that references a declaration.
1722 ///
1723 /// By default, performs semantic analysis to build the new expression.
1724 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001725 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001726 ValueDecl *VD,
1727 const DeclarationNameInfo &NameInfo,
1728 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001729 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001730 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001731
1732 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001733
1734 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001735 }
Mike Stump11289f42009-09-09 15:08:12 +00001736
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001738 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 /// By default, performs semantic analysis to build the new expression.
1740 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001741 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001742 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001743 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001744 }
1745
Douglas Gregorad8a3362009-09-04 17:36:40 +00001746 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001747 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001748 /// By default, performs semantic analysis to build the new expression.
1749 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001750 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001751 SourceLocation OperatorLoc,
1752 bool isArrow,
1753 CXXScopeSpec &SS,
1754 TypeSourceInfo *ScopeType,
1755 SourceLocation CCLoc,
1756 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001757 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001758
Douglas Gregora16548e2009-08-11 05:31:07 +00001759 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001760 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 /// By default, performs semantic analysis to build the new expression.
1762 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001763 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001764 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001765 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001766 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 }
Mike Stump11289f42009-09-09 15:08:12 +00001768
Douglas Gregor882211c2010-04-28 22:16:22 +00001769 /// \brief Build a new builtin offsetof expression.
1770 ///
1771 /// By default, performs semantic analysis to build the new expression.
1772 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001773 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001774 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001775 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001776 unsigned NumComponents,
1777 SourceLocation RParenLoc) {
1778 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1779 NumComponents, RParenLoc);
1780 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001781
1782 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001783 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001784 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001785 /// By default, performs semantic analysis to build the new expression.
1786 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001787 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1788 SourceLocation OpLoc,
1789 UnaryExprOrTypeTrait ExprKind,
1790 SourceRange R) {
1791 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 }
1793
Peter Collingbournee190dee2011-03-11 19:24:49 +00001794 /// \brief Build a new sizeof, alignof or vec step expression with an
1795 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001796 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001797 /// By default, performs semantic analysis to build the new expression.
1798 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001799 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1800 UnaryExprOrTypeTrait ExprKind,
1801 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001802 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001803 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001805 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001806
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001807 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001808 }
Mike Stump11289f42009-09-09 15:08:12 +00001809
Douglas Gregora16548e2009-08-11 05:31:07 +00001810 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001811 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001812 /// By default, performs semantic analysis to build the new expression.
1813 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001814 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001815 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001816 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001817 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001818 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001819 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001820 RBracketLoc);
1821 }
1822
1823 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001824 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001825 /// By default, performs semantic analysis to build the new expression.
1826 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001827 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001828 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001829 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001830 Expr *ExecConfig = nullptr) {
1831 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001832 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001833 }
1834
1835 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001836 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001837 /// By default, performs semantic analysis to build the new expression.
1838 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001839 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001840 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001841 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001842 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001843 const DeclarationNameInfo &MemberNameInfo,
1844 ValueDecl *Member,
1845 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001846 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001847 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001848 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1849 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001850 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001851 // We have a reference to an unnamed field. This is always the
1852 // base of an anonymous struct/union member access, i.e. the
1853 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001854 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001855 assert(Member->getType()->isRecordType() &&
1856 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001857
Richard Smithcab9a7d2011-10-26 19:06:56 +00001858 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001859 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001860 QualifierLoc.getNestedNameSpecifier(),
1861 FoundDecl, Member);
1862 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001863 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001864 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001865 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001866 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001867 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001868 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001869 cast<FieldDecl>(Member)->getType(),
1870 VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001871 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001872 }
Mike Stump11289f42009-09-09 15:08:12 +00001873
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001874 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001875 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001876
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001877 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001878 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001879
John McCall16df1e52010-03-30 21:47:33 +00001880 // FIXME: this involves duplicating earlier analysis in a lot of
1881 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001882 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001883 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001884 R.resolveKind();
1885
John McCallb268a282010-08-23 23:25:46 +00001886 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001887 SS, TemplateKWLoc,
1888 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001889 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001890 }
Mike Stump11289f42009-09-09 15:08:12 +00001891
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001893 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001894 /// By default, performs semantic analysis to build the new expression.
1895 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001896 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001897 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001898 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001899 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001900 }
1901
1902 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001903 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 /// By default, performs semantic analysis to build the new expression.
1905 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001906 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001907 SourceLocation QuestionLoc,
1908 Expr *LHS,
1909 SourceLocation ColonLoc,
1910 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001911 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1912 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 }
1914
Douglas Gregora16548e2009-08-11 05:31:07 +00001915 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001916 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 /// By default, performs semantic analysis to build the new expression.
1918 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001919 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001920 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001922 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001923 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001924 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001925 }
Mike Stump11289f42009-09-09 15:08:12 +00001926
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001928 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 /// By default, performs semantic analysis to build the new expression.
1930 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001931 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001932 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001933 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001934 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001935 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001936 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 }
Mike Stump11289f42009-09-09 15:08:12 +00001938
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001940 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 /// By default, performs semantic analysis to build the new expression.
1942 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001943 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 SourceLocation OpLoc,
1945 SourceLocation AccessorLoc,
1946 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001947
John McCall10eae182009-11-30 22:42:35 +00001948 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001949 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001950 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001951 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001952 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001953 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001954 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001955 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001956 }
Mike Stump11289f42009-09-09 15:08:12 +00001957
Douglas Gregora16548e2009-08-11 05:31:07 +00001958 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001959 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 /// By default, performs semantic analysis to build the new expression.
1961 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001962 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001963 MultiExprArg Inits,
1964 SourceLocation RBraceLoc,
1965 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001966 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001967 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001968 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001969 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001970
Douglas Gregord3d93062009-11-09 17:16:50 +00001971 // Patch in the result type we were given, which may have been computed
1972 // when the initial InitListExpr was built.
1973 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1974 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001975 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 }
Mike Stump11289f42009-09-09 15:08:12 +00001977
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001979 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001980 /// By default, performs semantic analysis to build the new expression.
1981 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001982 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 MultiExprArg ArrayExprs,
1984 SourceLocation EqualOrColonLoc,
1985 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001986 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001987 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001988 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001989 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001990 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001991 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001992
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001993 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 }
Mike Stump11289f42009-09-09 15:08:12 +00001995
Douglas Gregora16548e2009-08-11 05:31:07 +00001996 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001997 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 /// By default, builds the implicit value initialization without performing
1999 /// any semantic analysis. Subclasses may override this routine to provide
2000 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002001 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002002 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 }
Mike Stump11289f42009-09-09 15:08:12 +00002004
Douglas Gregora16548e2009-08-11 05:31:07 +00002005 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002006 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002007 /// By default, performs semantic analysis to build the new expression.
2008 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002009 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002010 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002011 SourceLocation RParenLoc) {
2012 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002013 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002014 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002015 }
2016
2017 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002018 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 /// By default, performs semantic analysis to build the new expression.
2020 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002021 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002022 MultiExprArg SubExprs,
2023 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002024 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002025 }
Mike Stump11289f42009-09-09 15:08:12 +00002026
Douglas Gregora16548e2009-08-11 05:31:07 +00002027 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002028 ///
2029 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 /// rather than attempting to map the label statement itself.
2031 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002032 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002033 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002034 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002035 }
Mike Stump11289f42009-09-09 15:08:12 +00002036
Douglas Gregora16548e2009-08-11 05:31:07 +00002037 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002038 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002039 /// By default, performs semantic analysis to build the new expression.
2040 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002041 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002042 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002044 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002045 }
Mike Stump11289f42009-09-09 15:08:12 +00002046
Douglas Gregora16548e2009-08-11 05:31:07 +00002047 /// \brief Build a new __builtin_choose_expr expression.
2048 ///
2049 /// By default, performs semantic analysis to build the new expression.
2050 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002051 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002052 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 SourceLocation RParenLoc) {
2054 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002055 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002056 RParenLoc);
2057 }
Mike Stump11289f42009-09-09 15:08:12 +00002058
Peter Collingbourne91147592011-04-15 00:35:48 +00002059 /// \brief Build a new generic selection expression.
2060 ///
2061 /// By default, performs semantic analysis to build the new expression.
2062 /// Subclasses may override this routine to provide different behavior.
2063 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2064 SourceLocation DefaultLoc,
2065 SourceLocation RParenLoc,
2066 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002067 ArrayRef<TypeSourceInfo *> Types,
2068 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002069 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002070 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002071 }
2072
Douglas Gregora16548e2009-08-11 05:31:07 +00002073 /// \brief Build a new overloaded operator call expression.
2074 ///
2075 /// By default, performs semantic analysis to build the new expression.
2076 /// The semantic analysis provides the behavior of template instantiation,
2077 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002078 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002079 /// argument-dependent lookup, etc. Subclasses may override this routine to
2080 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002081 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002083 Expr *Callee,
2084 Expr *First,
2085 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002086
2087 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002088 /// reinterpret_cast.
2089 ///
2090 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002091 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002092 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002093 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002094 Stmt::StmtClass Class,
2095 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002096 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002097 SourceLocation RAngleLoc,
2098 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002099 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002100 SourceLocation RParenLoc) {
2101 switch (Class) {
2102 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002103 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002104 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002105 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002106
2107 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002108 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002109 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002110 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002111
Douglas Gregora16548e2009-08-11 05:31:07 +00002112 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002113 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002114 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002115 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002116 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002117
Douglas Gregora16548e2009-08-11 05:31:07 +00002118 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002119 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002120 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002121 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002122
Douglas Gregora16548e2009-08-11 05:31:07 +00002123 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002124 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002125 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002126 }
Mike Stump11289f42009-09-09 15:08:12 +00002127
Douglas Gregora16548e2009-08-11 05:31:07 +00002128 /// \brief Build a new C++ static_cast expression.
2129 ///
2130 /// By default, performs semantic analysis to build the new expression.
2131 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002132 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002133 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002134 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 SourceLocation RAngleLoc,
2136 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002137 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002139 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002140 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002141 SourceRange(LAngleLoc, RAngleLoc),
2142 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002143 }
2144
2145 /// \brief Build a new C++ dynamic_cast expression.
2146 ///
2147 /// By default, performs semantic analysis to build the new expression.
2148 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002149 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002150 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002151 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002152 SourceLocation RAngleLoc,
2153 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002154 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002155 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002156 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002157 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002158 SourceRange(LAngleLoc, RAngleLoc),
2159 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 }
2161
2162 /// \brief Build a new C++ reinterpret_cast expression.
2163 ///
2164 /// By default, performs semantic analysis to build the new expression.
2165 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002166 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002167 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002168 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002169 SourceLocation RAngleLoc,
2170 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002171 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002173 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002174 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002175 SourceRange(LAngleLoc, RAngleLoc),
2176 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 }
2178
2179 /// \brief Build a new C++ const_cast expression.
2180 ///
2181 /// By default, performs semantic analysis to build the new expression.
2182 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002183 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002185 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 SourceLocation RAngleLoc,
2187 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002188 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002190 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002191 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002192 SourceRange(LAngleLoc, RAngleLoc),
2193 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 }
Mike Stump11289f42009-09-09 15:08:12 +00002195
Douglas Gregora16548e2009-08-11 05:31:07 +00002196 /// \brief Build a new C++ functional-style cast expression.
2197 ///
2198 /// By default, performs semantic analysis to build the new expression.
2199 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002200 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2201 SourceLocation LParenLoc,
2202 Expr *Sub,
2203 SourceLocation RParenLoc) {
2204 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002205 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002206 RParenLoc);
2207 }
Mike Stump11289f42009-09-09 15:08:12 +00002208
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 /// \brief Build a new C++ typeid(type) expression.
2210 ///
2211 /// By default, performs semantic analysis to build the new expression.
2212 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002213 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002214 SourceLocation TypeidLoc,
2215 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002216 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002217 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002218 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002219 }
Mike Stump11289f42009-09-09 15:08:12 +00002220
Francois Pichet9f4f2072010-09-08 12:20:18 +00002221
Douglas Gregora16548e2009-08-11 05:31:07 +00002222 /// \brief Build a new C++ typeid(expr) expression.
2223 ///
2224 /// By default, performs semantic analysis to build the new expression.
2225 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002226 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002227 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002228 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002229 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002230 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002231 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002232 }
2233
Francois Pichet9f4f2072010-09-08 12:20:18 +00002234 /// \brief Build a new C++ __uuidof(type) expression.
2235 ///
2236 /// By default, performs semantic analysis to build the new expression.
2237 /// Subclasses may override this routine to provide different behavior.
2238 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2239 SourceLocation TypeidLoc,
2240 TypeSourceInfo *Operand,
2241 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002242 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002243 RParenLoc);
2244 }
2245
2246 /// \brief Build a new C++ __uuidof(expr) expression.
2247 ///
2248 /// By default, performs semantic analysis to build the new expression.
2249 /// Subclasses may override this routine to provide different behavior.
2250 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2251 SourceLocation TypeidLoc,
2252 Expr *Operand,
2253 SourceLocation RParenLoc) {
2254 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2255 RParenLoc);
2256 }
2257
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 /// \brief Build a new C++ "this" expression.
2259 ///
2260 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002261 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002262 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002263 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002264 QualType ThisType,
2265 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002266 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002267 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002268 }
2269
2270 /// \brief Build a new C++ throw expression.
2271 ///
2272 /// By default, performs semantic analysis to build the new expression.
2273 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002274 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2275 bool IsThrownVariableInScope) {
2276 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002277 }
2278
2279 /// \brief Build a new C++ default-argument expression.
2280 ///
2281 /// By default, builds a new default-argument expression, which does not
2282 /// require any semantic analysis. Subclasses may override this routine to
2283 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002284 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002285 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002286 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002287 }
2288
Richard Smith852c9db2013-04-20 22:23:05 +00002289 /// \brief Build a new C++11 default-initialization expression.
2290 ///
2291 /// By default, builds a new default field initialization expression, which
2292 /// does not require any semantic analysis. Subclasses may override this
2293 /// routine to provide different behavior.
2294 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2295 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002296 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002297 }
2298
Douglas Gregora16548e2009-08-11 05:31:07 +00002299 /// \brief Build a new C++ zero-initialization expression.
2300 ///
2301 /// By default, performs semantic analysis to build the new expression.
2302 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002303 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2304 SourceLocation LParenLoc,
2305 SourceLocation RParenLoc) {
2306 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002307 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002308 }
Mike Stump11289f42009-09-09 15:08:12 +00002309
Douglas Gregora16548e2009-08-11 05:31:07 +00002310 /// \brief Build a new C++ "new" expression.
2311 ///
2312 /// By default, performs semantic analysis to build the new expression.
2313 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002314 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002315 bool UseGlobal,
2316 SourceLocation PlacementLParen,
2317 MultiExprArg PlacementArgs,
2318 SourceLocation PlacementRParen,
2319 SourceRange TypeIdParens,
2320 QualType AllocatedType,
2321 TypeSourceInfo *AllocatedTypeInfo,
2322 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002323 SourceRange DirectInitRange,
2324 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002325 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002326 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002327 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002328 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002329 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002330 AllocatedType,
2331 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002332 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002333 DirectInitRange,
2334 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002335 }
Mike Stump11289f42009-09-09 15:08:12 +00002336
Douglas Gregora16548e2009-08-11 05:31:07 +00002337 /// \brief Build a new C++ "delete" expression.
2338 ///
2339 /// By default, performs semantic analysis to build the new expression.
2340 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002341 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002342 bool IsGlobalDelete,
2343 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002344 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002345 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002346 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002347 }
Mike Stump11289f42009-09-09 15:08:12 +00002348
Douglas Gregor29c42f22012-02-24 07:38:34 +00002349 /// \brief Build a new type trait expression.
2350 ///
2351 /// By default, performs semantic analysis to build the new expression.
2352 /// Subclasses may override this routine to provide different behavior.
2353 ExprResult RebuildTypeTrait(TypeTrait Trait,
2354 SourceLocation StartLoc,
2355 ArrayRef<TypeSourceInfo *> Args,
2356 SourceLocation RParenLoc) {
2357 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2358 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002359
John Wiegley6242b6a2011-04-28 00:16:57 +00002360 /// \brief Build a new array type trait expression.
2361 ///
2362 /// By default, performs semantic analysis to build the new expression.
2363 /// Subclasses may override this routine to provide different behavior.
2364 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2365 SourceLocation StartLoc,
2366 TypeSourceInfo *TSInfo,
2367 Expr *DimExpr,
2368 SourceLocation RParenLoc) {
2369 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2370 }
2371
John Wiegleyf9f65842011-04-25 06:54:41 +00002372 /// \brief Build a new expression trait expression.
2373 ///
2374 /// By default, performs semantic analysis to build the new expression.
2375 /// Subclasses may override this routine to provide different behavior.
2376 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2377 SourceLocation StartLoc,
2378 Expr *Queried,
2379 SourceLocation RParenLoc) {
2380 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2381 }
2382
Mike Stump11289f42009-09-09 15:08:12 +00002383 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002384 /// expression.
2385 ///
2386 /// By default, performs semantic analysis to build the new expression.
2387 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002388 ExprResult RebuildDependentScopeDeclRefExpr(
2389 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002390 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002391 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002392 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002393 bool IsAddressOfOperand,
2394 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002395 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002396 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002397
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002398 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002399 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2400 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002401
Reid Kleckner32506ed2014-06-12 23:03:48 +00002402 return getSema().BuildQualifiedDeclarationNameExpr(
2403 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002404 }
2405
2406 /// \brief Build a new template-id expression.
2407 ///
2408 /// By default, performs semantic analysis to build the new expression.
2409 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002410 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002411 SourceLocation TemplateKWLoc,
2412 LookupResult &R,
2413 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002414 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002415 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2416 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002417 }
2418
2419 /// \brief Build a new object-construction expression.
2420 ///
2421 /// By default, performs semantic analysis to build the new expression.
2422 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002423 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002424 SourceLocation Loc,
2425 CXXConstructorDecl *Constructor,
2426 bool IsElidable,
2427 MultiExprArg Args,
2428 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002429 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002430 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002431 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002432 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002433 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002434 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002435 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002436 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002437 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002438
Douglas Gregordb121ba2009-12-14 16:27:04 +00002439 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002440 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002441 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002442 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002443 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002444 RequiresZeroInit, ConstructKind,
2445 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002446 }
2447
2448 /// \brief Build a new object-construction expression.
2449 ///
2450 /// By default, performs semantic analysis to build the new expression.
2451 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002452 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2453 SourceLocation LParenLoc,
2454 MultiExprArg Args,
2455 SourceLocation RParenLoc) {
2456 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002457 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002458 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002459 RParenLoc);
2460 }
2461
2462 /// \brief Build a new object-construction expression.
2463 ///
2464 /// By default, performs semantic analysis to build the new expression.
2465 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002466 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2467 SourceLocation LParenLoc,
2468 MultiExprArg Args,
2469 SourceLocation RParenLoc) {
2470 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002471 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002472 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002473 RParenLoc);
2474 }
Mike Stump11289f42009-09-09 15:08:12 +00002475
Douglas Gregora16548e2009-08-11 05:31:07 +00002476 /// \brief Build a new member reference expression.
2477 ///
2478 /// By default, performs semantic analysis to build the new expression.
2479 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002480 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002481 QualType BaseType,
2482 bool IsArrow,
2483 SourceLocation OperatorLoc,
2484 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002485 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002486 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002487 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002488 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002489 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002490 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002491
John McCallb268a282010-08-23 23:25:46 +00002492 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002493 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002494 SS, TemplateKWLoc,
2495 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002496 MemberNameInfo,
2497 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002498 }
2499
John McCall10eae182009-11-30 22:42:35 +00002500 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002501 ///
2502 /// By default, performs semantic analysis to build the new expression.
2503 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002504 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2505 SourceLocation OperatorLoc,
2506 bool IsArrow,
2507 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002508 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002509 NamedDecl *FirstQualifierInScope,
2510 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002511 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002512 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002513 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002514
John McCallb268a282010-08-23 23:25:46 +00002515 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002516 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002517 SS, TemplateKWLoc,
2518 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002519 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002520 }
Mike Stump11289f42009-09-09 15:08:12 +00002521
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002522 /// \brief Build a new noexcept expression.
2523 ///
2524 /// By default, performs semantic analysis to build the new expression.
2525 /// Subclasses may override this routine to provide different behavior.
2526 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2527 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2528 }
2529
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002530 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002531 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2532 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002533 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002534 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002535 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002536 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2537 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002538 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002539
2540 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2541 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002542 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002543 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002544
Patrick Beard0caa3942012-04-19 00:25:12 +00002545 /// \brief Build a new Objective-C boxed expression.
2546 ///
2547 /// By default, performs semantic analysis to build the new expression.
2548 /// Subclasses may override this routine to provide different behavior.
2549 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2550 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2551 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002552
Ted Kremeneke65b0862012-03-06 20:05:56 +00002553 /// \brief Build a new Objective-C array literal.
2554 ///
2555 /// By default, performs semantic analysis to build the new expression.
2556 /// Subclasses may override this routine to provide different behavior.
2557 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2558 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002559 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002560 MultiExprArg(Elements, NumElements));
2561 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002562
2563 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002564 Expr *Base, Expr *Key,
2565 ObjCMethodDecl *getterMethod,
2566 ObjCMethodDecl *setterMethod) {
2567 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2568 getterMethod, setterMethod);
2569 }
2570
2571 /// \brief Build a new Objective-C dictionary literal.
2572 ///
2573 /// By default, performs semantic analysis to build the new expression.
2574 /// Subclasses may override this routine to provide different behavior.
2575 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2576 ObjCDictionaryElement *Elements,
2577 unsigned NumElements) {
2578 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2579 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002580
James Dennett2a4d13c2012-06-15 07:13:21 +00002581 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002582 ///
2583 /// By default, performs semantic analysis to build the new expression.
2584 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002585 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002586 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002587 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002588 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002589 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002590
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002591 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002592 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002593 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002594 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002595 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002596 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002597 MultiExprArg Args,
2598 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002599 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2600 ReceiverTypeInfo->getType(),
2601 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002602 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002603 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002604 }
2605
2606 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002607 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002608 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002609 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002610 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002611 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002612 MultiExprArg Args,
2613 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002614 return SemaRef.BuildInstanceMessage(Receiver,
2615 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002616 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002617 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002618 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002619 }
2620
Douglas Gregord51d90d2010-04-26 20:11:03 +00002621 /// \brief Build a new Objective-C ivar reference expression.
2622 ///
2623 /// By default, performs semantic analysis to build the new expression.
2624 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002625 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002626 SourceLocation IvarLoc,
2627 bool IsArrow, bool IsFreeIvar) {
2628 // FIXME: We lose track of the IsFreeIvar bit.
2629 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002630 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2631 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002632 /*FIXME:*/IvarLoc, IsArrow,
2633 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002634 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002635 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002636 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002637 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002638
2639 /// \brief Build a new Objective-C property reference expression.
2640 ///
2641 /// By default, performs semantic analysis to build the new expression.
2642 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002643 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002644 ObjCPropertyDecl *Property,
2645 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002646 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002647 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2648 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2649 /*FIXME:*/PropertyLoc,
2650 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002651 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002652 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002653 NameInfo,
2654 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002655 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002656
John McCallb7bd14f2010-12-02 01:19:52 +00002657 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002658 ///
2659 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002660 /// Subclasses may override this routine to provide different behavior.
2661 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2662 ObjCMethodDecl *Getter,
2663 ObjCMethodDecl *Setter,
2664 SourceLocation PropertyLoc) {
2665 // Since these expressions can only be value-dependent, we do not
2666 // need to perform semantic analysis again.
2667 return Owned(
2668 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2669 VK_LValue, OK_ObjCProperty,
2670 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002671 }
2672
Douglas Gregord51d90d2010-04-26 20:11:03 +00002673 /// \brief Build a new Objective-C "isa" expression.
2674 ///
2675 /// By default, performs semantic analysis to build the new expression.
2676 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002677 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002678 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002679 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002680 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2681 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002682 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002683 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002684 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002685 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002686 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002687 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002688
Douglas Gregora16548e2009-08-11 05:31:07 +00002689 /// \brief Build a new shuffle vector expression.
2690 ///
2691 /// By default, performs semantic analysis to build the new expression.
2692 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002693 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002694 MultiExprArg SubExprs,
2695 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002696 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002697 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002698 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2699 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2700 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002701 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002702
Douglas Gregora16548e2009-08-11 05:31:07 +00002703 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002704 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002705 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2706 SemaRef.Context.BuiltinFnTy,
2707 VK_RValue, BuiltinLoc);
2708 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2709 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002710 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002711
2712 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002713 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002714 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002715 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002716
Douglas Gregora16548e2009-08-11 05:31:07 +00002717 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002718 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002719 }
John McCall31f82722010-11-12 08:19:04 +00002720
Hal Finkelc4d7c822013-09-18 03:29:45 +00002721 /// \brief Build a new convert vector expression.
2722 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2723 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2724 SourceLocation RParenLoc) {
2725 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2726 BuiltinLoc, RParenLoc);
2727 }
2728
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002729 /// \brief Build a new template argument pack expansion.
2730 ///
2731 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002732 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002733 /// different behavior.
2734 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002735 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002736 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002737 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002738 case TemplateArgument::Expression: {
2739 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002740 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2741 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002742 if (Result.isInvalid())
2743 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002744
Douglas Gregor98318c22011-01-03 21:37:45 +00002745 return TemplateArgumentLoc(Result.get(), Result.get());
2746 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002747
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002748 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002749 return TemplateArgumentLoc(TemplateArgument(
2750 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002751 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002752 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002753 Pattern.getTemplateNameLoc(),
2754 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002755
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002756 case TemplateArgument::Null:
2757 case TemplateArgument::Integral:
2758 case TemplateArgument::Declaration:
2759 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002760 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002761 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002762 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002763
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002764 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002765 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002766 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002767 EllipsisLoc,
2768 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002769 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2770 Expansion);
2771 break;
2772 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002773
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002774 return TemplateArgumentLoc();
2775 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002776
Douglas Gregor968f23a2011-01-03 19:31:53 +00002777 /// \brief Build a new expression pack expansion.
2778 ///
2779 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002780 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002781 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002782 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002783 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002784 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002785 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002786
2787 /// \brief Build a new atomic operation expression.
2788 ///
2789 /// By default, performs semantic analysis to build the new expression.
2790 /// Subclasses may override this routine to provide different behavior.
2791 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2792 MultiExprArg SubExprs,
2793 QualType RetTy,
2794 AtomicExpr::AtomicOp Op,
2795 SourceLocation RParenLoc) {
2796 // Just create the expression; there is not any interesting semantic
2797 // analysis here because we can't actually build an AtomicExpr until
2798 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002799 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002800 RParenLoc);
2801 }
2802
John McCall31f82722010-11-12 08:19:04 +00002803private:
Douglas Gregor14454802011-02-25 02:25:35 +00002804 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2805 QualType ObjectType,
2806 NamedDecl *FirstQualifierInScope,
2807 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002808
2809 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2810 QualType ObjectType,
2811 NamedDecl *FirstQualifierInScope,
2812 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002813
2814 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2815 NamedDecl *FirstQualifierInScope,
2816 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002817};
Douglas Gregora16548e2009-08-11 05:31:07 +00002818
Douglas Gregorebe10102009-08-20 07:17:43 +00002819template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002820StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002821 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002822 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002823
Douglas Gregorebe10102009-08-20 07:17:43 +00002824 switch (S->getStmtClass()) {
2825 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002826
Douglas Gregorebe10102009-08-20 07:17:43 +00002827 // Transform individual statement nodes
2828#define STMT(Node, Parent) \
2829 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002830#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002831#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002832#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002833
Douglas Gregorebe10102009-08-20 07:17:43 +00002834 // Transform expressions by calling TransformExpr.
2835#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002836#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002837#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002838#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002839 {
John McCalldadc5752010-08-24 06:29:42 +00002840 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002841 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002842 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002843
Richard Smith945f8d32013-01-14 22:39:08 +00002844 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002845 }
Mike Stump11289f42009-09-09 15:08:12 +00002846 }
2847
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002848 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002849}
Mike Stump11289f42009-09-09 15:08:12 +00002850
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002851template<typename Derived>
2852OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2853 if (!S)
2854 return S;
2855
2856 switch (S->getClauseKind()) {
2857 default: break;
2858 // Transform individual clause nodes
2859#define OPENMP_CLAUSE(Name, Class) \
2860 case OMPC_ ## Name : \
2861 return getDerived().Transform ## Class(cast<Class>(S));
2862#include "clang/Basic/OpenMPKinds.def"
2863 }
2864
2865 return S;
2866}
2867
Mike Stump11289f42009-09-09 15:08:12 +00002868
Douglas Gregore922c772009-08-04 22:27:00 +00002869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002870ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002871 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002872 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002873
2874 switch (E->getStmtClass()) {
2875 case Stmt::NoStmtClass: break;
2876#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002877#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002878#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002879 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002880#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002881 }
2882
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002883 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002884}
2885
2886template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002887ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00002888 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00002889 // Initializers are instantiated like expressions, except that various outer
2890 // layers are stripped.
2891 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002892 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002893
2894 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2895 Init = ExprTemp->getSubExpr();
2896
Richard Smithe6ca4752013-05-30 22:40:16 +00002897 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2898 Init = MTE->GetTemporaryExpr();
2899
Richard Smithd59b8322012-12-19 01:39:02 +00002900 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2901 Init = Binder->getSubExpr();
2902
2903 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2904 Init = ICE->getSubExprAsWritten();
2905
Richard Smithcc1b96d2013-06-12 22:31:48 +00002906 if (CXXStdInitializerListExpr *ILE =
2907 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00002908 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00002909
Richard Smithc6abd962014-07-25 01:12:44 +00002910 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00002911 // InitListExprs. Other forms of copy-initialization will be a no-op if
2912 // the initializer is already the right type.
2913 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00002914 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00002915 return getDerived().TransformExpr(Init);
2916
2917 // Revert value-initialization back to empty parens.
2918 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2919 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002920 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002921 Parens.getEnd());
2922 }
2923
2924 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2925 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002926 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002927 SourceLocation());
2928
2929 // Revert initialization by constructor back to a parenthesized or braced list
2930 // of expressions. Any other form of initializer can just be reused directly.
2931 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002932 return getDerived().TransformExpr(Init);
2933
Richard Smithf8adcdc2014-07-17 05:12:35 +00002934 // If the initialization implicitly converted an initializer list to a
2935 // std::initializer_list object, unwrap the std::initializer_list too.
2936 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00002937 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00002938
Richard Smithd59b8322012-12-19 01:39:02 +00002939 SmallVector<Expr*, 8> NewArgs;
2940 bool ArgChanged = false;
2941 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00002942 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00002943 return ExprError();
2944
2945 // If this was list initialization, revert to list form.
2946 if (Construct->isListInitialization())
2947 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2948 Construct->getLocEnd(),
2949 Construct->getType());
2950
Richard Smithd59b8322012-12-19 01:39:02 +00002951 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002952 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00002953 if (Parens.isInvalid()) {
2954 // This was a variable declaration's initialization for which no initializer
2955 // was specified.
2956 assert(NewArgs.empty() &&
2957 "no parens or braces but have direct init with arguments?");
2958 return ExprEmpty();
2959 }
Richard Smithd59b8322012-12-19 01:39:02 +00002960 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2961 Parens.getEnd());
2962}
2963
2964template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002965bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2966 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002967 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002968 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002969 bool *ArgChanged) {
2970 for (unsigned I = 0; I != NumInputs; ++I) {
2971 // If requested, drop call arguments that need to be dropped.
2972 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2973 if (ArgChanged)
2974 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002975
Douglas Gregora3efea12011-01-03 19:04:46 +00002976 break;
2977 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002978
Douglas Gregor968f23a2011-01-03 19:31:53 +00002979 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2980 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002981
Chris Lattner01cf8db2011-07-20 06:58:45 +00002982 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002983 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2984 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002985
Douglas Gregor968f23a2011-01-03 19:31:53 +00002986 // Determine whether the set of unexpanded parameter packs can and should
2987 // be expanded.
2988 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002989 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002990 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2991 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002992 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2993 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002994 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002995 Expand, RetainExpansion,
2996 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002997 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002998
Douglas Gregor968f23a2011-01-03 19:31:53 +00002999 if (!Expand) {
3000 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003001 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003002 // expansion.
3003 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3004 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3005 if (OutPattern.isInvalid())
3006 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003007
3008 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003009 Expansion->getEllipsisLoc(),
3010 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003011 if (Out.isInvalid())
3012 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003013
Douglas Gregor968f23a2011-01-03 19:31:53 +00003014 if (ArgChanged)
3015 *ArgChanged = true;
3016 Outputs.push_back(Out.get());
3017 continue;
3018 }
John McCall542e7c62011-07-06 07:30:07 +00003019
3020 // Record right away that the argument was changed. This needs
3021 // to happen even if the array expands to nothing.
3022 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003023
Douglas Gregor968f23a2011-01-03 19:31:53 +00003024 // The transform has determined that we should perform an elementwise
3025 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003026 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003027 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3028 ExprResult Out = getDerived().TransformExpr(Pattern);
3029 if (Out.isInvalid())
3030 return true;
3031
Richard Smith9467be42014-06-06 17:33:35 +00003032 // FIXME: Can this happen? We should not try to expand the pack
3033 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003034 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003035 Out = getDerived().RebuildPackExpansion(
3036 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003037 if (Out.isInvalid())
3038 return true;
3039 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003040
Douglas Gregor968f23a2011-01-03 19:31:53 +00003041 Outputs.push_back(Out.get());
3042 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003043
Richard Smith9467be42014-06-06 17:33:35 +00003044 // If we're supposed to retain a pack expansion, do so by temporarily
3045 // forgetting the partially-substituted parameter pack.
3046 if (RetainExpansion) {
3047 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3048
3049 ExprResult Out = getDerived().TransformExpr(Pattern);
3050 if (Out.isInvalid())
3051 return true;
3052
3053 Out = getDerived().RebuildPackExpansion(
3054 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3055 if (Out.isInvalid())
3056 return true;
3057
3058 Outputs.push_back(Out.get());
3059 }
3060
Douglas Gregor968f23a2011-01-03 19:31:53 +00003061 continue;
3062 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003063
Richard Smithd59b8322012-12-19 01:39:02 +00003064 ExprResult Result =
3065 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3066 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003067 if (Result.isInvalid())
3068 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003069
Douglas Gregora3efea12011-01-03 19:04:46 +00003070 if (Result.get() != Inputs[I] && ArgChanged)
3071 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003072
3073 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003074 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003075
Douglas Gregora3efea12011-01-03 19:04:46 +00003076 return false;
3077}
3078
3079template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003080NestedNameSpecifierLoc
3081TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3082 NestedNameSpecifierLoc NNS,
3083 QualType ObjectType,
3084 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003085 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003086 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003087 Qualifier = Qualifier.getPrefix())
3088 Qualifiers.push_back(Qualifier);
3089
3090 CXXScopeSpec SS;
3091 while (!Qualifiers.empty()) {
3092 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3093 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003094
Douglas Gregor14454802011-02-25 02:25:35 +00003095 switch (QNNS->getKind()) {
3096 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003097 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003098 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003099 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003100 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003101 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003102 FirstQualifierInScope, false))
3103 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003104
Douglas Gregor14454802011-02-25 02:25:35 +00003105 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003106
Douglas Gregor14454802011-02-25 02:25:35 +00003107 case NestedNameSpecifier::Namespace: {
3108 NamespaceDecl *NS
3109 = cast_or_null<NamespaceDecl>(
3110 getDerived().TransformDecl(
3111 Q.getLocalBeginLoc(),
3112 QNNS->getAsNamespace()));
3113 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3114 break;
3115 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003116
Douglas Gregor14454802011-02-25 02:25:35 +00003117 case NestedNameSpecifier::NamespaceAlias: {
3118 NamespaceAliasDecl *Alias
3119 = cast_or_null<NamespaceAliasDecl>(
3120 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3121 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003122 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003123 Q.getLocalEndLoc());
3124 break;
3125 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003126
Douglas Gregor14454802011-02-25 02:25:35 +00003127 case NestedNameSpecifier::Global:
3128 // There is no meaningful transformation that one could perform on the
3129 // global scope.
3130 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3131 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003132
Nikola Smiljanic67860242014-09-26 00:28:20 +00003133 case NestedNameSpecifier::Super: {
3134 CXXRecordDecl *RD =
3135 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3136 SourceLocation(), QNNS->getAsRecordDecl()));
3137 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3138 break;
3139 }
3140
Douglas Gregor14454802011-02-25 02:25:35 +00003141 case NestedNameSpecifier::TypeSpecWithTemplate:
3142 case NestedNameSpecifier::TypeSpec: {
3143 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3144 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003145
Douglas Gregor14454802011-02-25 02:25:35 +00003146 if (!TL)
3147 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003148
Douglas Gregor14454802011-02-25 02:25:35 +00003149 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003150 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003151 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003152 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003153 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003154 if (TL.getType()->isEnumeralType())
3155 SemaRef.Diag(TL.getBeginLoc(),
3156 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003157 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3158 Q.getLocalEndLoc());
3159 break;
3160 }
Richard Trieude756fb2011-05-07 01:36:37 +00003161 // If the nested-name-specifier is an invalid type def, don't emit an
3162 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003163 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3164 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003165 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003166 << TL.getType() << SS.getRange();
3167 }
Douglas Gregor14454802011-02-25 02:25:35 +00003168 return NestedNameSpecifierLoc();
3169 }
Douglas Gregore16af532011-02-28 18:50:33 +00003170 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003171
Douglas Gregore16af532011-02-28 18:50:33 +00003172 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003173 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003174 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003175 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003176
Douglas Gregor14454802011-02-25 02:25:35 +00003177 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003178 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003179 !getDerived().AlwaysRebuild())
3180 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003181
3182 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003183 // nested-name-specifier, do so.
3184 if (SS.location_size() == NNS.getDataLength() &&
3185 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3186 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3187
3188 // Allocate new nested-name-specifier location information.
3189 return SS.getWithLocInContext(SemaRef.Context);
3190}
3191
3192template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003193DeclarationNameInfo
3194TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003195::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003196 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003197 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003198 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003199
3200 switch (Name.getNameKind()) {
3201 case DeclarationName::Identifier:
3202 case DeclarationName::ObjCZeroArgSelector:
3203 case DeclarationName::ObjCOneArgSelector:
3204 case DeclarationName::ObjCMultiArgSelector:
3205 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003206 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003207 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003208 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003209
Douglas Gregorf816bd72009-09-03 22:13:48 +00003210 case DeclarationName::CXXConstructorName:
3211 case DeclarationName::CXXDestructorName:
3212 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003213 TypeSourceInfo *NewTInfo;
3214 CanQualType NewCanTy;
3215 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003216 NewTInfo = getDerived().TransformType(OldTInfo);
3217 if (!NewTInfo)
3218 return DeclarationNameInfo();
3219 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003220 }
3221 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003222 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003223 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003224 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003225 if (NewT.isNull())
3226 return DeclarationNameInfo();
3227 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3228 }
Mike Stump11289f42009-09-09 15:08:12 +00003229
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003230 DeclarationName NewName
3231 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3232 NewCanTy);
3233 DeclarationNameInfo NewNameInfo(NameInfo);
3234 NewNameInfo.setName(NewName);
3235 NewNameInfo.setNamedTypeInfo(NewTInfo);
3236 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003237 }
Mike Stump11289f42009-09-09 15:08:12 +00003238 }
3239
David Blaikie83d382b2011-09-23 05:06:16 +00003240 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003241}
3242
3243template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003244TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003245TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3246 TemplateName Name,
3247 SourceLocation NameLoc,
3248 QualType ObjectType,
3249 NamedDecl *FirstQualifierInScope) {
3250 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3251 TemplateDecl *Template = QTN->getTemplateDecl();
3252 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003253
Douglas Gregor9db53502011-03-02 18:07:45 +00003254 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003255 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003256 Template));
3257 if (!TransTemplate)
3258 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003259
Douglas Gregor9db53502011-03-02 18:07:45 +00003260 if (!getDerived().AlwaysRebuild() &&
3261 SS.getScopeRep() == QTN->getQualifier() &&
3262 TransTemplate == Template)
3263 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003264
Douglas Gregor9db53502011-03-02 18:07:45 +00003265 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3266 TransTemplate);
3267 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003268
Douglas Gregor9db53502011-03-02 18:07:45 +00003269 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3270 if (SS.getScopeRep()) {
3271 // These apply to the scope specifier, not the template.
3272 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003273 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003274 }
3275
Douglas Gregor9db53502011-03-02 18:07:45 +00003276 if (!getDerived().AlwaysRebuild() &&
3277 SS.getScopeRep() == DTN->getQualifier() &&
3278 ObjectType.isNull())
3279 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003280
Douglas Gregor9db53502011-03-02 18:07:45 +00003281 if (DTN->isIdentifier()) {
3282 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003283 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003284 NameLoc,
3285 ObjectType,
3286 FirstQualifierInScope);
3287 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003288
Douglas Gregor9db53502011-03-02 18:07:45 +00003289 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3290 ObjectType);
3291 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003292
Douglas Gregor9db53502011-03-02 18:07:45 +00003293 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3294 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003295 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003296 Template));
3297 if (!TransTemplate)
3298 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003299
Douglas Gregor9db53502011-03-02 18:07:45 +00003300 if (!getDerived().AlwaysRebuild() &&
3301 TransTemplate == Template)
3302 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003303
Douglas Gregor9db53502011-03-02 18:07:45 +00003304 return TemplateName(TransTemplate);
3305 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003306
Douglas Gregor9db53502011-03-02 18:07:45 +00003307 if (SubstTemplateTemplateParmPackStorage *SubstPack
3308 = Name.getAsSubstTemplateTemplateParmPack()) {
3309 TemplateTemplateParmDecl *TransParam
3310 = cast_or_null<TemplateTemplateParmDecl>(
3311 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3312 if (!TransParam)
3313 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003314
Douglas Gregor9db53502011-03-02 18:07:45 +00003315 if (!getDerived().AlwaysRebuild() &&
3316 TransParam == SubstPack->getParameterPack())
3317 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003318
3319 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003320 SubstPack->getArgumentPack());
3321 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003322
Douglas Gregor9db53502011-03-02 18:07:45 +00003323 // These should be getting filtered out before they reach the AST.
3324 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003325}
3326
3327template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003328void TreeTransform<Derived>::InventTemplateArgumentLoc(
3329 const TemplateArgument &Arg,
3330 TemplateArgumentLoc &Output) {
3331 SourceLocation Loc = getDerived().getBaseLocation();
3332 switch (Arg.getKind()) {
3333 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003334 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003335 break;
3336
3337 case TemplateArgument::Type:
3338 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003339 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003340
John McCall0ad16662009-10-29 08:12:44 +00003341 break;
3342
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003343 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003344 case TemplateArgument::TemplateExpansion: {
3345 NestedNameSpecifierLocBuilder Builder;
3346 TemplateName Template = Arg.getAsTemplate();
3347 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3348 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3349 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3350 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003351
Douglas Gregor9d802122011-03-02 17:09:35 +00003352 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003353 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003354 Builder.getWithLocInContext(SemaRef.Context),
3355 Loc);
3356 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003357 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003358 Builder.getWithLocInContext(SemaRef.Context),
3359 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003360
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003361 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003362 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003363
John McCall0ad16662009-10-29 08:12:44 +00003364 case TemplateArgument::Expression:
3365 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3366 break;
3367
3368 case TemplateArgument::Declaration:
3369 case TemplateArgument::Integral:
3370 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003371 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003372 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003373 break;
3374 }
3375}
3376
3377template<typename Derived>
3378bool TreeTransform<Derived>::TransformTemplateArgument(
3379 const TemplateArgumentLoc &Input,
3380 TemplateArgumentLoc &Output) {
3381 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003382 switch (Arg.getKind()) {
3383 case TemplateArgument::Null:
3384 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003385 case TemplateArgument::Pack:
3386 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003387 case TemplateArgument::NullPtr:
3388 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003389
Douglas Gregore922c772009-08-04 22:27:00 +00003390 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003391 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003392 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003393 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003394
3395 DI = getDerived().TransformType(DI);
3396 if (!DI) return true;
3397
3398 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3399 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003400 }
Mike Stump11289f42009-09-09 15:08:12 +00003401
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003402 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003403 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3404 if (QualifierLoc) {
3405 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3406 if (!QualifierLoc)
3407 return true;
3408 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003409
Douglas Gregordf846d12011-03-02 18:46:51 +00003410 CXXScopeSpec SS;
3411 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003412 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003413 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3414 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003415 if (Template.isNull())
3416 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003417
Douglas Gregor9d802122011-03-02 17:09:35 +00003418 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003419 Input.getTemplateNameLoc());
3420 return false;
3421 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003422
3423 case TemplateArgument::TemplateExpansion:
3424 llvm_unreachable("Caller should expand pack expansions");
3425
Douglas Gregore922c772009-08-04 22:27:00 +00003426 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003427 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003428 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003429 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003430
John McCall0ad16662009-10-29 08:12:44 +00003431 Expr *InputExpr = Input.getSourceExpression();
3432 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3433
Chris Lattnercdb591a2011-04-25 20:37:58 +00003434 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003435 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003436 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003437 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003438 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003439 }
Douglas Gregore922c772009-08-04 22:27:00 +00003440 }
Mike Stump11289f42009-09-09 15:08:12 +00003441
Douglas Gregore922c772009-08-04 22:27:00 +00003442 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003443 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003444}
3445
Douglas Gregorfe921a72010-12-20 23:36:19 +00003446/// \brief Iterator adaptor that invents template argument location information
3447/// for each of the template arguments in its underlying iterator.
3448template<typename Derived, typename InputIterator>
3449class TemplateArgumentLocInventIterator {
3450 TreeTransform<Derived> &Self;
3451 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003452
Douglas Gregorfe921a72010-12-20 23:36:19 +00003453public:
3454 typedef TemplateArgumentLoc value_type;
3455 typedef TemplateArgumentLoc reference;
3456 typedef typename std::iterator_traits<InputIterator>::difference_type
3457 difference_type;
3458 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003459
Douglas Gregorfe921a72010-12-20 23:36:19 +00003460 class pointer {
3461 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003462
Douglas Gregorfe921a72010-12-20 23:36:19 +00003463 public:
3464 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003465
Douglas Gregorfe921a72010-12-20 23:36:19 +00003466 const TemplateArgumentLoc *operator->() const { return &Arg; }
3467 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003468
Douglas Gregorfe921a72010-12-20 23:36:19 +00003469 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003470
Douglas Gregorfe921a72010-12-20 23:36:19 +00003471 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3472 InputIterator Iter)
3473 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003474
Douglas Gregorfe921a72010-12-20 23:36:19 +00003475 TemplateArgumentLocInventIterator &operator++() {
3476 ++Iter;
3477 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003478 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003479
Douglas Gregorfe921a72010-12-20 23:36:19 +00003480 TemplateArgumentLocInventIterator operator++(int) {
3481 TemplateArgumentLocInventIterator Old(*this);
3482 ++(*this);
3483 return Old;
3484 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003485
Douglas Gregorfe921a72010-12-20 23:36:19 +00003486 reference operator*() const {
3487 TemplateArgumentLoc Result;
3488 Self.InventTemplateArgumentLoc(*Iter, Result);
3489 return Result;
3490 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003491
Douglas Gregorfe921a72010-12-20 23:36:19 +00003492 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003493
Douglas Gregorfe921a72010-12-20 23:36:19 +00003494 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3495 const TemplateArgumentLocInventIterator &Y) {
3496 return X.Iter == Y.Iter;
3497 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003498
Douglas Gregorfe921a72010-12-20 23:36:19 +00003499 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3500 const TemplateArgumentLocInventIterator &Y) {
3501 return X.Iter != Y.Iter;
3502 }
3503};
Chad Rosier1dcde962012-08-08 18:46:20 +00003504
Douglas Gregor42cafa82010-12-20 17:42:22 +00003505template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003506template<typename InputIterator>
3507bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3508 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003509 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003510 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003511 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003512 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003513
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003514 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3515 // Unpack argument packs, which we translate them into separate
3516 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003517 // FIXME: We could do much better if we could guarantee that the
3518 // TemplateArgumentLocInfo for the pack expansion would be usable for
3519 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003520 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003521 TemplateArgument::pack_iterator>
3522 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003523 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003524 In.getArgument().pack_begin()),
3525 PackLocIterator(*this,
3526 In.getArgument().pack_end()),
3527 Outputs))
3528 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003529
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003530 continue;
3531 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003532
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003533 if (In.getArgument().isPackExpansion()) {
3534 // We have a pack expansion, for which we will be substituting into
3535 // the pattern.
3536 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003537 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003538 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003539 = getSema().getTemplateArgumentPackExpansionPattern(
3540 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003541
Chris Lattner01cf8db2011-07-20 06:58:45 +00003542 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003543 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3544 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003545
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003546 // Determine whether the set of unexpanded parameter packs can and should
3547 // be expanded.
3548 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003549 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003550 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003551 if (getDerived().TryExpandParameterPacks(Ellipsis,
3552 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003553 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003554 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003555 RetainExpansion,
3556 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003557 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003558
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003559 if (!Expand) {
3560 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003561 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003562 // expansion.
3563 TemplateArgumentLoc OutPattern;
3564 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3565 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3566 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003567
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003568 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3569 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003570 if (Out.getArgument().isNull())
3571 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003572
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003573 Outputs.addArgument(Out);
3574 continue;
3575 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003576
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003577 // The transform has determined that we should perform an elementwise
3578 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003579 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003580 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3581
3582 if (getDerived().TransformTemplateArgument(Pattern, Out))
3583 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003584
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003585 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003586 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3587 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003588 if (Out.getArgument().isNull())
3589 return true;
3590 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003591
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003592 Outputs.addArgument(Out);
3593 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003594
Douglas Gregor48d24112011-01-10 20:53:55 +00003595 // If we're supposed to retain a pack expansion, do so by temporarily
3596 // forgetting the partially-substituted parameter pack.
3597 if (RetainExpansion) {
3598 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003599
Douglas Gregor48d24112011-01-10 20:53:55 +00003600 if (getDerived().TransformTemplateArgument(Pattern, Out))
3601 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003602
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003603 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3604 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003605 if (Out.getArgument().isNull())
3606 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003607
Douglas Gregor48d24112011-01-10 20:53:55 +00003608 Outputs.addArgument(Out);
3609 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003610
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003611 continue;
3612 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003613
3614 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003615 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003616 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003617
Douglas Gregor42cafa82010-12-20 17:42:22 +00003618 Outputs.addArgument(Out);
3619 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003620
Douglas Gregor42cafa82010-12-20 17:42:22 +00003621 return false;
3622
3623}
3624
Douglas Gregord6ff3322009-08-04 16:50:30 +00003625//===----------------------------------------------------------------------===//
3626// Type transformation
3627//===----------------------------------------------------------------------===//
3628
3629template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003630QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003631 if (getDerived().AlreadyTransformed(T))
3632 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003633
John McCall550e0c22009-10-21 00:40:46 +00003634 // Temporary workaround. All of these transformations should
3635 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003636 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3637 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003638
John McCall31f82722010-11-12 08:19:04 +00003639 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003640
John McCall550e0c22009-10-21 00:40:46 +00003641 if (!NewDI)
3642 return QualType();
3643
3644 return NewDI->getType();
3645}
3646
3647template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003648TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003649 // Refine the base location to the type's location.
3650 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3651 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003652 if (getDerived().AlreadyTransformed(DI->getType()))
3653 return DI;
3654
3655 TypeLocBuilder TLB;
3656
3657 TypeLoc TL = DI->getTypeLoc();
3658 TLB.reserve(TL.getFullDataSize());
3659
John McCall31f82722010-11-12 08:19:04 +00003660 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003661 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003662 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003663
John McCallbcd03502009-12-07 02:54:59 +00003664 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003665}
3666
3667template<typename Derived>
3668QualType
John McCall31f82722010-11-12 08:19:04 +00003669TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003670 switch (T.getTypeLocClass()) {
3671#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003672#define TYPELOC(CLASS, PARENT) \
3673 case TypeLoc::CLASS: \
3674 return getDerived().Transform##CLASS##Type(TLB, \
3675 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003676#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003677 }
Mike Stump11289f42009-09-09 15:08:12 +00003678
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003679 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003680}
3681
3682/// FIXME: By default, this routine adds type qualifiers only to types
3683/// that can have qualifiers, and silently suppresses those qualifiers
3684/// that are not permitted (e.g., qualifiers on reference or function
3685/// types). This is the right thing for template instantiation, but
3686/// probably not for other clients.
3687template<typename Derived>
3688QualType
3689TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003690 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003691 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003692
John McCall31f82722010-11-12 08:19:04 +00003693 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003694 if (Result.isNull())
3695 return QualType();
3696
3697 // Silently suppress qualifiers if the result type can't be qualified.
3698 // FIXME: this is the right thing for template instantiation, but
3699 // probably not for other clients.
3700 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003701 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003702
John McCall31168b02011-06-15 23:02:42 +00003703 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003704 // resulting type.
3705 if (Quals.hasObjCLifetime()) {
3706 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3707 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003708 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003709 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003710 // A lifetime qualifier applied to a substituted template parameter
3711 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003712 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003713 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003714 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3715 QualType Replacement = SubstTypeParam->getReplacementType();
3716 Qualifiers Qs = Replacement.getQualifiers();
3717 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003718 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003719 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3720 Qs);
3721 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003722 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003723 Replacement);
3724 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003725 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3726 // 'auto' types behave the same way as template parameters.
3727 QualType Deduced = AutoTy->getDeducedType();
3728 Qualifiers Qs = Deduced.getQualifiers();
3729 Qs.removeObjCLifetime();
3730 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3731 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003732 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3733 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003734 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003735 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003736 // Otherwise, complain about the addition of a qualifier to an
3737 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003738 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003739 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003740 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003741
Douglas Gregore46db902011-06-17 22:11:49 +00003742 Quals.removeObjCLifetime();
3743 }
3744 }
3745 }
John McCallcb0f89a2010-06-05 06:41:15 +00003746 if (!Quals.empty()) {
3747 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003748 // BuildQualifiedType might not add qualifiers if they are invalid.
3749 if (Result.hasLocalQualifiers())
3750 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003751 // No location information to preserve.
3752 }
John McCall550e0c22009-10-21 00:40:46 +00003753
3754 return Result;
3755}
3756
Douglas Gregor14454802011-02-25 02:25:35 +00003757template<typename Derived>
3758TypeLoc
3759TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3760 QualType ObjectType,
3761 NamedDecl *UnqualLookup,
3762 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003763 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003764 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003765
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003766 TypeSourceInfo *TSI =
3767 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3768 if (TSI)
3769 return TSI->getTypeLoc();
3770 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003771}
3772
Douglas Gregor579c15f2011-03-02 18:32:08 +00003773template<typename Derived>
3774TypeSourceInfo *
3775TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3776 QualType ObjectType,
3777 NamedDecl *UnqualLookup,
3778 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003779 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003780 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003781
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003782 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3783 UnqualLookup, SS);
3784}
3785
3786template <typename Derived>
3787TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3788 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3789 CXXScopeSpec &SS) {
3790 QualType T = TL.getType();
3791 assert(!getDerived().AlreadyTransformed(T));
3792
Douglas Gregor579c15f2011-03-02 18:32:08 +00003793 TypeLocBuilder TLB;
3794 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003795
Douglas Gregor579c15f2011-03-02 18:32:08 +00003796 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003797 TemplateSpecializationTypeLoc SpecTL =
3798 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003799
Douglas Gregor579c15f2011-03-02 18:32:08 +00003800 TemplateName Template
3801 = getDerived().TransformTemplateName(SS,
3802 SpecTL.getTypePtr()->getTemplateName(),
3803 SpecTL.getTemplateNameLoc(),
3804 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003805 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003806 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003807
3808 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003809 Template);
3810 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003811 DependentTemplateSpecializationTypeLoc SpecTL =
3812 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003813
Douglas Gregor579c15f2011-03-02 18:32:08 +00003814 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003815 = getDerived().RebuildTemplateName(SS,
3816 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003817 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003818 ObjectType, UnqualLookup);
3819 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003820 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003821
3822 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003823 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003824 Template,
3825 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003826 } else {
3827 // Nothing special needs to be done for these.
3828 Result = getDerived().TransformType(TLB, TL);
3829 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003830
3831 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003832 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003833
Douglas Gregor579c15f2011-03-02 18:32:08 +00003834 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3835}
3836
John McCall550e0c22009-10-21 00:40:46 +00003837template <class TyLoc> static inline
3838QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3839 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3840 NewT.setNameLoc(T.getNameLoc());
3841 return T.getType();
3842}
3843
John McCall550e0c22009-10-21 00:40:46 +00003844template<typename Derived>
3845QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003846 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003847 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3848 NewT.setBuiltinLoc(T.getBuiltinLoc());
3849 if (T.needsExtraLocalData())
3850 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3851 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003852}
Mike Stump11289f42009-09-09 15:08:12 +00003853
Douglas Gregord6ff3322009-08-04 16:50:30 +00003854template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003855QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003856 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003857 // FIXME: recurse?
3858 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003859}
Mike Stump11289f42009-09-09 15:08:12 +00003860
Reid Kleckner0503a872013-12-05 01:23:43 +00003861template <typename Derived>
3862QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3863 AdjustedTypeLoc TL) {
3864 // Adjustments applied during transformation are handled elsewhere.
3865 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3866}
3867
Douglas Gregord6ff3322009-08-04 16:50:30 +00003868template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003869QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3870 DecayedTypeLoc TL) {
3871 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3872 if (OriginalType.isNull())
3873 return QualType();
3874
3875 QualType Result = TL.getType();
3876 if (getDerived().AlwaysRebuild() ||
3877 OriginalType != TL.getOriginalLoc().getType())
3878 Result = SemaRef.Context.getDecayedType(OriginalType);
3879 TLB.push<DecayedTypeLoc>(Result);
3880 // Nothing to set for DecayedTypeLoc.
3881 return Result;
3882}
3883
3884template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003885QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003886 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003887 QualType PointeeType
3888 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003889 if (PointeeType.isNull())
3890 return QualType();
3891
3892 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003893 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003894 // A dependent pointer type 'T *' has is being transformed such
3895 // that an Objective-C class type is being replaced for 'T'. The
3896 // resulting pointer type is an ObjCObjectPointerType, not a
3897 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003898 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003899
John McCall8b07ec22010-05-15 11:32:37 +00003900 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3901 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003902 return Result;
3903 }
John McCall31f82722010-11-12 08:19:04 +00003904
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003905 if (getDerived().AlwaysRebuild() ||
3906 PointeeType != TL.getPointeeLoc().getType()) {
3907 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3908 if (Result.isNull())
3909 return QualType();
3910 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003911
John McCall31168b02011-06-15 23:02:42 +00003912 // Objective-C ARC can add lifetime qualifiers to the type that we're
3913 // pointing to.
3914 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003915
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003916 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3917 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003918 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003919}
Mike Stump11289f42009-09-09 15:08:12 +00003920
3921template<typename Derived>
3922QualType
John McCall550e0c22009-10-21 00:40:46 +00003923TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003924 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003925 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003926 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3927 if (PointeeType.isNull())
3928 return QualType();
3929
3930 QualType Result = TL.getType();
3931 if (getDerived().AlwaysRebuild() ||
3932 PointeeType != TL.getPointeeLoc().getType()) {
3933 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003934 TL.getSigilLoc());
3935 if (Result.isNull())
3936 return QualType();
3937 }
3938
Douglas Gregor049211a2010-04-22 16:50:51 +00003939 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003940 NewT.setSigilLoc(TL.getSigilLoc());
3941 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003942}
3943
John McCall70dd5f62009-10-30 00:06:24 +00003944/// Transforms a reference type. Note that somewhat paradoxically we
3945/// don't care whether the type itself is an l-value type or an r-value
3946/// type; we only care if the type was *written* as an l-value type
3947/// or an r-value type.
3948template<typename Derived>
3949QualType
3950TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003951 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003952 const ReferenceType *T = TL.getTypePtr();
3953
3954 // Note that this works with the pointee-as-written.
3955 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3956 if (PointeeType.isNull())
3957 return QualType();
3958
3959 QualType Result = TL.getType();
3960 if (getDerived().AlwaysRebuild() ||
3961 PointeeType != T->getPointeeTypeAsWritten()) {
3962 Result = getDerived().RebuildReferenceType(PointeeType,
3963 T->isSpelledAsLValue(),
3964 TL.getSigilLoc());
3965 if (Result.isNull())
3966 return QualType();
3967 }
3968
John McCall31168b02011-06-15 23:02:42 +00003969 // Objective-C ARC can add lifetime qualifiers to the type that we're
3970 // referring to.
3971 TLB.TypeWasModifiedSafely(
3972 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3973
John McCall70dd5f62009-10-30 00:06:24 +00003974 // r-value references can be rebuilt as l-value references.
3975 ReferenceTypeLoc NewTL;
3976 if (isa<LValueReferenceType>(Result))
3977 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3978 else
3979 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3980 NewTL.setSigilLoc(TL.getSigilLoc());
3981
3982 return Result;
3983}
3984
Mike Stump11289f42009-09-09 15:08:12 +00003985template<typename Derived>
3986QualType
John McCall550e0c22009-10-21 00:40:46 +00003987TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003988 LValueReferenceTypeLoc TL) {
3989 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003990}
3991
Mike Stump11289f42009-09-09 15:08:12 +00003992template<typename Derived>
3993QualType
John McCall550e0c22009-10-21 00:40:46 +00003994TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003995 RValueReferenceTypeLoc TL) {
3996 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003997}
Mike Stump11289f42009-09-09 15:08:12 +00003998
Douglas Gregord6ff3322009-08-04 16:50:30 +00003999template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004000QualType
John McCall550e0c22009-10-21 00:40:46 +00004001TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004002 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004003 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004004 if (PointeeType.isNull())
4005 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004006
Abramo Bagnara509357842011-03-05 14:42:21 +00004007 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004008 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004009 if (OldClsTInfo) {
4010 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4011 if (!NewClsTInfo)
4012 return QualType();
4013 }
4014
4015 const MemberPointerType *T = TL.getTypePtr();
4016 QualType OldClsType = QualType(T->getClass(), 0);
4017 QualType NewClsType;
4018 if (NewClsTInfo)
4019 NewClsType = NewClsTInfo->getType();
4020 else {
4021 NewClsType = getDerived().TransformType(OldClsType);
4022 if (NewClsType.isNull())
4023 return QualType();
4024 }
Mike Stump11289f42009-09-09 15:08:12 +00004025
John McCall550e0c22009-10-21 00:40:46 +00004026 QualType Result = TL.getType();
4027 if (getDerived().AlwaysRebuild() ||
4028 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004029 NewClsType != OldClsType) {
4030 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004031 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004032 if (Result.isNull())
4033 return QualType();
4034 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004035
Reid Kleckner0503a872013-12-05 01:23:43 +00004036 // If we had to adjust the pointee type when building a member pointer, make
4037 // sure to push TypeLoc info for it.
4038 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4039 if (MPT && PointeeType != MPT->getPointeeType()) {
4040 assert(isa<AdjustedType>(MPT->getPointeeType()));
4041 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4042 }
4043
John McCall550e0c22009-10-21 00:40:46 +00004044 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4045 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004046 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004047
4048 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004049}
4050
Mike Stump11289f42009-09-09 15:08:12 +00004051template<typename Derived>
4052QualType
John McCall550e0c22009-10-21 00:40:46 +00004053TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004054 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004055 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004056 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004057 if (ElementType.isNull())
4058 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004059
John McCall550e0c22009-10-21 00:40:46 +00004060 QualType Result = TL.getType();
4061 if (getDerived().AlwaysRebuild() ||
4062 ElementType != T->getElementType()) {
4063 Result = getDerived().RebuildConstantArrayType(ElementType,
4064 T->getSizeModifier(),
4065 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004066 T->getIndexTypeCVRQualifiers(),
4067 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004068 if (Result.isNull())
4069 return QualType();
4070 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004071
4072 // We might have either a ConstantArrayType or a VariableArrayType now:
4073 // a ConstantArrayType is allowed to have an element type which is a
4074 // VariableArrayType if the type is dependent. Fortunately, all array
4075 // types have the same location layout.
4076 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004077 NewTL.setLBracketLoc(TL.getLBracketLoc());
4078 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004079
John McCall550e0c22009-10-21 00:40:46 +00004080 Expr *Size = TL.getSizeExpr();
4081 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004082 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4083 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004084 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4085 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004086 }
4087 NewTL.setSizeExpr(Size);
4088
4089 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004090}
Mike Stump11289f42009-09-09 15:08:12 +00004091
Douglas Gregord6ff3322009-08-04 16:50:30 +00004092template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004093QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004094 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004095 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004096 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004097 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004098 if (ElementType.isNull())
4099 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004100
John McCall550e0c22009-10-21 00:40:46 +00004101 QualType Result = TL.getType();
4102 if (getDerived().AlwaysRebuild() ||
4103 ElementType != T->getElementType()) {
4104 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004105 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004106 T->getIndexTypeCVRQualifiers(),
4107 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004108 if (Result.isNull())
4109 return QualType();
4110 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004111
John McCall550e0c22009-10-21 00:40:46 +00004112 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4113 NewTL.setLBracketLoc(TL.getLBracketLoc());
4114 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004115 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004116
4117 return Result;
4118}
4119
4120template<typename Derived>
4121QualType
4122TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004123 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004124 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004125 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4126 if (ElementType.isNull())
4127 return QualType();
4128
John McCalldadc5752010-08-24 06:29:42 +00004129 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004130 = getDerived().TransformExpr(T->getSizeExpr());
4131 if (SizeResult.isInvalid())
4132 return QualType();
4133
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004134 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004135
4136 QualType Result = TL.getType();
4137 if (getDerived().AlwaysRebuild() ||
4138 ElementType != T->getElementType() ||
4139 Size != T->getSizeExpr()) {
4140 Result = getDerived().RebuildVariableArrayType(ElementType,
4141 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004142 Size,
John McCall550e0c22009-10-21 00:40:46 +00004143 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004144 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004145 if (Result.isNull())
4146 return QualType();
4147 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004148
Serge Pavlov774c6d02014-02-06 03:49:11 +00004149 // We might have constant size array now, but fortunately it has the same
4150 // location layout.
4151 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004152 NewTL.setLBracketLoc(TL.getLBracketLoc());
4153 NewTL.setRBracketLoc(TL.getRBracketLoc());
4154 NewTL.setSizeExpr(Size);
4155
4156 return Result;
4157}
4158
4159template<typename Derived>
4160QualType
4161TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004162 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004163 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004164 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4165 if (ElementType.isNull())
4166 return QualType();
4167
Richard Smith764d2fe2011-12-20 02:08:33 +00004168 // Array bounds are constant expressions.
4169 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4170 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004171
John McCall33ddac02011-01-19 10:06:00 +00004172 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4173 Expr *origSize = TL.getSizeExpr();
4174 if (!origSize) origSize = T->getSizeExpr();
4175
4176 ExprResult sizeResult
4177 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004178 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004179 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004180 return QualType();
4181
John McCall33ddac02011-01-19 10:06:00 +00004182 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004183
4184 QualType Result = TL.getType();
4185 if (getDerived().AlwaysRebuild() ||
4186 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004187 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004188 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4189 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004190 size,
John McCall550e0c22009-10-21 00:40:46 +00004191 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004192 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004193 if (Result.isNull())
4194 return QualType();
4195 }
John McCall550e0c22009-10-21 00:40:46 +00004196
4197 // We might have any sort of array type now, but fortunately they
4198 // all have the same location layout.
4199 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4200 NewTL.setLBracketLoc(TL.getLBracketLoc());
4201 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004202 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004203
4204 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004205}
Mike Stump11289f42009-09-09 15:08:12 +00004206
4207template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004208QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004209 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004210 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004211 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004212
4213 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004214 QualType ElementType = getDerived().TransformType(T->getElementType());
4215 if (ElementType.isNull())
4216 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004217
Richard Smith764d2fe2011-12-20 02:08:33 +00004218 // Vector sizes are constant expressions.
4219 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4220 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004221
John McCalldadc5752010-08-24 06:29:42 +00004222 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004223 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004224 if (Size.isInvalid())
4225 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004226
John McCall550e0c22009-10-21 00:40:46 +00004227 QualType Result = TL.getType();
4228 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004229 ElementType != T->getElementType() ||
4230 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004231 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004232 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004233 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004234 if (Result.isNull())
4235 return QualType();
4236 }
John McCall550e0c22009-10-21 00:40:46 +00004237
4238 // Result might be dependent or not.
4239 if (isa<DependentSizedExtVectorType>(Result)) {
4240 DependentSizedExtVectorTypeLoc NewTL
4241 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4242 NewTL.setNameLoc(TL.getNameLoc());
4243 } else {
4244 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4245 NewTL.setNameLoc(TL.getNameLoc());
4246 }
4247
4248 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004249}
Mike Stump11289f42009-09-09 15:08:12 +00004250
4251template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004252QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004253 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004254 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004255 QualType ElementType = getDerived().TransformType(T->getElementType());
4256 if (ElementType.isNull())
4257 return QualType();
4258
John McCall550e0c22009-10-21 00:40:46 +00004259 QualType Result = TL.getType();
4260 if (getDerived().AlwaysRebuild() ||
4261 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004262 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004263 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004264 if (Result.isNull())
4265 return QualType();
4266 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004267
John McCall550e0c22009-10-21 00:40:46 +00004268 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4269 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004270
John McCall550e0c22009-10-21 00:40:46 +00004271 return Result;
4272}
4273
4274template<typename Derived>
4275QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004276 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004277 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004278 QualType ElementType = getDerived().TransformType(T->getElementType());
4279 if (ElementType.isNull())
4280 return QualType();
4281
4282 QualType Result = TL.getType();
4283 if (getDerived().AlwaysRebuild() ||
4284 ElementType != T->getElementType()) {
4285 Result = getDerived().RebuildExtVectorType(ElementType,
4286 T->getNumElements(),
4287 /*FIXME*/ SourceLocation());
4288 if (Result.isNull())
4289 return QualType();
4290 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004291
John McCall550e0c22009-10-21 00:40:46 +00004292 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4293 NewTL.setNameLoc(TL.getNameLoc());
4294
4295 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004296}
Mike Stump11289f42009-09-09 15:08:12 +00004297
David Blaikie05785d12013-02-20 22:23:23 +00004298template <typename Derived>
4299ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4300 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4301 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004302 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004303 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004304
Douglas Gregor715e4612011-01-14 22:40:04 +00004305 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004306 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004307 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004308 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004309 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004310
Douglas Gregor715e4612011-01-14 22:40:04 +00004311 TypeLocBuilder TLB;
4312 TypeLoc NewTL = OldDI->getTypeLoc();
4313 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004314
4315 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004316 OldExpansionTL.getPatternLoc());
4317 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004318 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004319
4320 Result = RebuildPackExpansionType(Result,
4321 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004322 OldExpansionTL.getEllipsisLoc(),
4323 NumExpansions);
4324 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004325 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004326
Douglas Gregor715e4612011-01-14 22:40:04 +00004327 PackExpansionTypeLoc NewExpansionTL
4328 = TLB.push<PackExpansionTypeLoc>(Result);
4329 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4330 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4331 } else
4332 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004333 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004334 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004335
John McCall8fb0d9d2011-05-01 22:35:37 +00004336 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004337 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004338
4339 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4340 OldParm->getDeclContext(),
4341 OldParm->getInnerLocStart(),
4342 OldParm->getLocation(),
4343 OldParm->getIdentifier(),
4344 NewDI->getType(),
4345 NewDI,
4346 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004347 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004348 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4349 OldParm->getFunctionScopeIndex() + indexAdjustment);
4350 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004351}
4352
4353template<typename Derived>
4354bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004355 TransformFunctionTypeParams(SourceLocation Loc,
4356 ParmVarDecl **Params, unsigned NumParams,
4357 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004358 SmallVectorImpl<QualType> &OutParamTypes,
4359 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004360 int indexAdjustment = 0;
4361
Douglas Gregordd472162011-01-07 00:20:55 +00004362 for (unsigned i = 0; i != NumParams; ++i) {
4363 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004364 assert(OldParm->getFunctionScopeIndex() == i);
4365
David Blaikie05785d12013-02-20 22:23:23 +00004366 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004367 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004368 if (OldParm->isParameterPack()) {
4369 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004370 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004371
Douglas Gregor5499af42011-01-05 23:12:31 +00004372 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004373 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004374 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004375 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4376 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004377 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4378
Douglas Gregor5499af42011-01-05 23:12:31 +00004379 // Determine whether we should expand the parameter packs.
4380 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004381 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004382 Optional<unsigned> OrigNumExpansions =
4383 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004384 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004385 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4386 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004387 Unexpanded,
4388 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004389 RetainExpansion,
4390 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004391 return true;
4392 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004393
Douglas Gregor5499af42011-01-05 23:12:31 +00004394 if (ShouldExpand) {
4395 // Expand the function parameter pack into multiple, separate
4396 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004397 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004398 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004399 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004400 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004401 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004402 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004403 OrigNumExpansions,
4404 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004405 if (!NewParm)
4406 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004407
Douglas Gregordd472162011-01-07 00:20:55 +00004408 OutParamTypes.push_back(NewParm->getType());
4409 if (PVars)
4410 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004411 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004412
4413 // If we're supposed to retain a pack expansion, do so by temporarily
4414 // forgetting the partially-substituted parameter pack.
4415 if (RetainExpansion) {
4416 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004417 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004418 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004419 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004420 OrigNumExpansions,
4421 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004422 if (!NewParm)
4423 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004424
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004425 OutParamTypes.push_back(NewParm->getType());
4426 if (PVars)
4427 PVars->push_back(NewParm);
4428 }
4429
John McCall8fb0d9d2011-05-01 22:35:37 +00004430 // The next parameter should have the same adjustment as the
4431 // last thing we pushed, but we post-incremented indexAdjustment
4432 // on every push. Also, if we push nothing, the adjustment should
4433 // go down by one.
4434 indexAdjustment--;
4435
Douglas Gregor5499af42011-01-05 23:12:31 +00004436 // We're done with the pack expansion.
4437 continue;
4438 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004439
4440 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004441 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004442 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4443 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004444 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004445 NumExpansions,
4446 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004447 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004448 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004449 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004450 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004451
John McCall58f10c32010-03-11 09:03:00 +00004452 if (!NewParm)
4453 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004454
Douglas Gregordd472162011-01-07 00:20:55 +00004455 OutParamTypes.push_back(NewParm->getType());
4456 if (PVars)
4457 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004458 continue;
4459 }
John McCall58f10c32010-03-11 09:03:00 +00004460
4461 // Deal with the possibility that we don't have a parameter
4462 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004463 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004464 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004465 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004466 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004467 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004468 = dyn_cast<PackExpansionType>(OldType)) {
4469 // We have a function parameter pack that may need to be expanded.
4470 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004471 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004472 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004473
Douglas Gregor5499af42011-01-05 23:12:31 +00004474 // Determine whether we should expand the parameter packs.
4475 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004476 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004477 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004478 Unexpanded,
4479 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004480 RetainExpansion,
4481 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004482 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004483 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004484
Douglas Gregor5499af42011-01-05 23:12:31 +00004485 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004486 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004487 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004488 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004489 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4490 QualType NewType = getDerived().TransformType(Pattern);
4491 if (NewType.isNull())
4492 return true;
John McCall58f10c32010-03-11 09:03:00 +00004493
Douglas Gregordd472162011-01-07 00:20:55 +00004494 OutParamTypes.push_back(NewType);
4495 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004496 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004497 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004498
Douglas Gregor5499af42011-01-05 23:12:31 +00004499 // We're done with the pack expansion.
4500 continue;
4501 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004502
Douglas Gregor48d24112011-01-10 20:53:55 +00004503 // If we're supposed to retain a pack expansion, do so by temporarily
4504 // forgetting the partially-substituted parameter pack.
4505 if (RetainExpansion) {
4506 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4507 QualType NewType = getDerived().TransformType(Pattern);
4508 if (NewType.isNull())
4509 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004510
Douglas Gregor48d24112011-01-10 20:53:55 +00004511 OutParamTypes.push_back(NewType);
4512 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004513 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004514 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004515
Chad Rosier1dcde962012-08-08 18:46:20 +00004516 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004517 // expansion.
4518 OldType = Expansion->getPattern();
4519 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004520 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4521 NewType = getDerived().TransformType(OldType);
4522 } else {
4523 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004524 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004525
Douglas Gregor5499af42011-01-05 23:12:31 +00004526 if (NewType.isNull())
4527 return true;
4528
4529 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004530 NewType = getSema().Context.getPackExpansionType(NewType,
4531 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004532
Douglas Gregordd472162011-01-07 00:20:55 +00004533 OutParamTypes.push_back(NewType);
4534 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004535 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004536 }
4537
John McCall8fb0d9d2011-05-01 22:35:37 +00004538#ifndef NDEBUG
4539 if (PVars) {
4540 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4541 if (ParmVarDecl *parm = (*PVars)[i])
4542 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004543 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004544#endif
4545
4546 return false;
4547}
John McCall58f10c32010-03-11 09:03:00 +00004548
4549template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004550QualType
John McCall550e0c22009-10-21 00:40:46 +00004551TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004552 FunctionProtoTypeLoc TL) {
NAKAMURA Takumi23224152014-10-17 12:48:37 +00004553 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
Douglas Gregor3024f072012-04-16 07:05:22 +00004554}
4555
NAKAMURA Takumi23224152014-10-17 12:48:37 +00004556template<typename Derived>
4557QualType
4558TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4559 FunctionProtoTypeLoc TL,
4560 CXXRecordDecl *ThisContext,
4561 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004562 // Transform the parameters and return type.
4563 //
Richard Smithf623c962012-04-17 00:58:00 +00004564 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004565 // When the function has a trailing return type, we instantiate the
4566 // parameters before the return type, since the return type can then refer
4567 // to the parameters themselves (via decltype, sizeof, etc.).
4568 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004569 SmallVector<QualType, 4> ParamTypes;
4570 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004571 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004572
Douglas Gregor7fb25412010-10-01 18:44:50 +00004573 QualType ResultType;
4574
Richard Smith1226c602012-08-14 22:51:13 +00004575 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004576 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004577 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004578 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004579 return QualType();
4580
Douglas Gregor3024f072012-04-16 07:05:22 +00004581 {
4582 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004583 // If a declaration declares a member function or member function
4584 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004585 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004586 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004587 // declarator.
4588 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004589
Alp Toker42a16a62014-01-25 23:51:36 +00004590 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004591 if (ResultType.isNull())
4592 return QualType();
4593 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004594 }
4595 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004596 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004597 if (ResultType.isNull())
4598 return QualType();
4599
Alp Toker9cacbab2014-01-20 20:26:09 +00004600 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004601 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004602 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004603 return QualType();
4604 }
4605
NAKAMURA Takumi23224152014-10-17 12:48:37 +00004606 // FIXME: Need to transform the exception-specification too.
Richard Smithf623c962012-04-17 00:58:00 +00004607
John McCall550e0c22009-10-21 00:40:46 +00004608 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004609 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004610 T->getNumParams() != ParamTypes.size() ||
4611 !std::equal(T->param_type_begin(), T->param_type_end(),
NAKAMURA Takumi23224152014-10-17 12:48:37 +00004612 ParamTypes.begin())) {
4613 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
4614 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004615 if (Result.isNull())
4616 return QualType();
4617 }
Mike Stump11289f42009-09-09 15:08:12 +00004618
John McCall550e0c22009-10-21 00:40:46 +00004619 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004620 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004621 NewTL.setLParenLoc(TL.getLParenLoc());
4622 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004623 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004624 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4625 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004626
4627 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004628}
Mike Stump11289f42009-09-09 15:08:12 +00004629
Douglas Gregord6ff3322009-08-04 16:50:30 +00004630template<typename Derived>
4631QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004632 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004633 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004634 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004635 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004636 if (ResultType.isNull())
4637 return QualType();
4638
4639 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004640 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004641 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4642
4643 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004644 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004645 NewTL.setLParenLoc(TL.getLParenLoc());
4646 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004647 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004648
4649 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004650}
Mike Stump11289f42009-09-09 15:08:12 +00004651
John McCallb96ec562009-12-04 22:46:56 +00004652template<typename Derived> QualType
4653TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004654 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004655 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004656 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004657 if (!D)
4658 return QualType();
4659
4660 QualType Result = TL.getType();
4661 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4662 Result = getDerived().RebuildUnresolvedUsingType(D);
4663 if (Result.isNull())
4664 return QualType();
4665 }
4666
4667 // We might get an arbitrary type spec type back. We should at
4668 // least always get a type spec type, though.
4669 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4670 NewTL.setNameLoc(TL.getNameLoc());
4671
4672 return Result;
4673}
4674
Douglas Gregord6ff3322009-08-04 16:50:30 +00004675template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004676QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004677 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004678 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004679 TypedefNameDecl *Typedef
4680 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4681 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004682 if (!Typedef)
4683 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004684
John McCall550e0c22009-10-21 00:40:46 +00004685 QualType Result = TL.getType();
4686 if (getDerived().AlwaysRebuild() ||
4687 Typedef != T->getDecl()) {
4688 Result = getDerived().RebuildTypedefType(Typedef);
4689 if (Result.isNull())
4690 return QualType();
4691 }
Mike Stump11289f42009-09-09 15:08:12 +00004692
John McCall550e0c22009-10-21 00:40:46 +00004693 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4694 NewTL.setNameLoc(TL.getNameLoc());
4695
4696 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004697}
Mike Stump11289f42009-09-09 15:08:12 +00004698
Douglas Gregord6ff3322009-08-04 16:50:30 +00004699template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004700QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004701 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004702 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004703 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4704 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004705
John McCalldadc5752010-08-24 06:29:42 +00004706 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004707 if (E.isInvalid())
4708 return QualType();
4709
Eli Friedmane4f22df2012-02-29 04:03:55 +00004710 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4711 if (E.isInvalid())
4712 return QualType();
4713
John McCall550e0c22009-10-21 00:40:46 +00004714 QualType Result = TL.getType();
4715 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004716 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004717 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004718 if (Result.isNull())
4719 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004720 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004721 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004722
John McCall550e0c22009-10-21 00:40:46 +00004723 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004724 NewTL.setTypeofLoc(TL.getTypeofLoc());
4725 NewTL.setLParenLoc(TL.getLParenLoc());
4726 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004727
4728 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004729}
Mike Stump11289f42009-09-09 15:08:12 +00004730
4731template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004732QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004733 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004734 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4735 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4736 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004737 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004738
John McCall550e0c22009-10-21 00:40:46 +00004739 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004740 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4741 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004742 if (Result.isNull())
4743 return QualType();
4744 }
Mike Stump11289f42009-09-09 15:08:12 +00004745
John McCall550e0c22009-10-21 00:40:46 +00004746 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004747 NewTL.setTypeofLoc(TL.getTypeofLoc());
4748 NewTL.setLParenLoc(TL.getLParenLoc());
4749 NewTL.setRParenLoc(TL.getRParenLoc());
4750 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004751
4752 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004753}
Mike Stump11289f42009-09-09 15:08:12 +00004754
4755template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004756QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004757 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004758 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004759
Douglas Gregore922c772009-08-04 22:27:00 +00004760 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004761 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4762 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004763
John McCalldadc5752010-08-24 06:29:42 +00004764 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004765 if (E.isInvalid())
4766 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004767
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004768 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004769 if (E.isInvalid())
4770 return QualType();
4771
John McCall550e0c22009-10-21 00:40:46 +00004772 QualType Result = TL.getType();
4773 if (getDerived().AlwaysRebuild() ||
4774 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004775 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004776 if (Result.isNull())
4777 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004778 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004779 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004780
John McCall550e0c22009-10-21 00:40:46 +00004781 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4782 NewTL.setNameLoc(TL.getNameLoc());
4783
4784 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004785}
4786
4787template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004788QualType TreeTransform<Derived>::TransformUnaryTransformType(
4789 TypeLocBuilder &TLB,
4790 UnaryTransformTypeLoc TL) {
4791 QualType Result = TL.getType();
4792 if (Result->isDependentType()) {
4793 const UnaryTransformType *T = TL.getTypePtr();
4794 QualType NewBase =
4795 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4796 Result = getDerived().RebuildUnaryTransformType(NewBase,
4797 T->getUTTKind(),
4798 TL.getKWLoc());
4799 if (Result.isNull())
4800 return QualType();
4801 }
4802
4803 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4804 NewTL.setKWLoc(TL.getKWLoc());
4805 NewTL.setParensRange(TL.getParensRange());
4806 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4807 return Result;
4808}
4809
4810template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004811QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4812 AutoTypeLoc TL) {
4813 const AutoType *T = TL.getTypePtr();
4814 QualType OldDeduced = T->getDeducedType();
4815 QualType NewDeduced;
4816 if (!OldDeduced.isNull()) {
4817 NewDeduced = getDerived().TransformType(OldDeduced);
4818 if (NewDeduced.isNull())
4819 return QualType();
4820 }
4821
4822 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004823 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4824 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004825 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004826 if (Result.isNull())
4827 return QualType();
4828 }
4829
4830 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4831 NewTL.setNameLoc(TL.getNameLoc());
4832
4833 return Result;
4834}
4835
4836template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004837QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004838 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004839 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004840 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004841 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4842 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004843 if (!Record)
4844 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004845
John McCall550e0c22009-10-21 00:40:46 +00004846 QualType Result = TL.getType();
4847 if (getDerived().AlwaysRebuild() ||
4848 Record != T->getDecl()) {
4849 Result = getDerived().RebuildRecordType(Record);
4850 if (Result.isNull())
4851 return QualType();
4852 }
Mike Stump11289f42009-09-09 15:08:12 +00004853
John McCall550e0c22009-10-21 00:40:46 +00004854 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4855 NewTL.setNameLoc(TL.getNameLoc());
4856
4857 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004858}
Mike Stump11289f42009-09-09 15:08:12 +00004859
4860template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004861QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004862 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004863 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004864 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004865 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4866 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004867 if (!Enum)
4868 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004869
John McCall550e0c22009-10-21 00:40:46 +00004870 QualType Result = TL.getType();
4871 if (getDerived().AlwaysRebuild() ||
4872 Enum != T->getDecl()) {
4873 Result = getDerived().RebuildEnumType(Enum);
4874 if (Result.isNull())
4875 return QualType();
4876 }
Mike Stump11289f42009-09-09 15:08:12 +00004877
John McCall550e0c22009-10-21 00:40:46 +00004878 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4879 NewTL.setNameLoc(TL.getNameLoc());
4880
4881 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004882}
John McCallfcc33b02009-09-05 00:15:47 +00004883
John McCalle78aac42010-03-10 03:28:59 +00004884template<typename Derived>
4885QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4886 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004887 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004888 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4889 TL.getTypePtr()->getDecl());
4890 if (!D) return QualType();
4891
4892 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4893 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4894 return T;
4895}
4896
Douglas Gregord6ff3322009-08-04 16:50:30 +00004897template<typename Derived>
4898QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004899 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004900 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004901 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004902}
4903
Mike Stump11289f42009-09-09 15:08:12 +00004904template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004905QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004906 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004907 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004908 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004909
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004910 // Substitute into the replacement type, which itself might involve something
4911 // that needs to be transformed. This only tends to occur with default
4912 // template arguments of template template parameters.
4913 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4914 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4915 if (Replacement.isNull())
4916 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004917
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004918 // Always canonicalize the replacement type.
4919 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4920 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004921 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004922 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004923
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004924 // Propagate type-source information.
4925 SubstTemplateTypeParmTypeLoc NewTL
4926 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4927 NewTL.setNameLoc(TL.getNameLoc());
4928 return Result;
4929
John McCallcebee162009-10-18 09:09:24 +00004930}
4931
4932template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004933QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4934 TypeLocBuilder &TLB,
4935 SubstTemplateTypeParmPackTypeLoc TL) {
4936 return TransformTypeSpecType(TLB, TL);
4937}
4938
4939template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004940QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004941 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004942 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004943 const TemplateSpecializationType *T = TL.getTypePtr();
4944
Douglas Gregordf846d12011-03-02 18:46:51 +00004945 // The nested-name-specifier never matters in a TemplateSpecializationType,
4946 // because we can't have a dependent nested-name-specifier anyway.
4947 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004948 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004949 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4950 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004951 if (Template.isNull())
4952 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004953
John McCall31f82722010-11-12 08:19:04 +00004954 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4955}
4956
Eli Friedman0dfb8892011-10-06 23:00:33 +00004957template<typename Derived>
4958QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4959 AtomicTypeLoc TL) {
4960 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4961 if (ValueType.isNull())
4962 return QualType();
4963
4964 QualType Result = TL.getType();
4965 if (getDerived().AlwaysRebuild() ||
4966 ValueType != TL.getValueLoc().getType()) {
4967 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4968 if (Result.isNull())
4969 return QualType();
4970 }
4971
4972 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4973 NewTL.setKWLoc(TL.getKWLoc());
4974 NewTL.setLParenLoc(TL.getLParenLoc());
4975 NewTL.setRParenLoc(TL.getRParenLoc());
4976
4977 return Result;
4978}
4979
Chad Rosier1dcde962012-08-08 18:46:20 +00004980 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004981 /// container that provides a \c getArgLoc() member function.
4982 ///
4983 /// This iterator is intended to be used with the iterator form of
4984 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4985 template<typename ArgLocContainer>
4986 class TemplateArgumentLocContainerIterator {
4987 ArgLocContainer *Container;
4988 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004989
Douglas Gregorfe921a72010-12-20 23:36:19 +00004990 public:
4991 typedef TemplateArgumentLoc value_type;
4992 typedef TemplateArgumentLoc reference;
4993 typedef int difference_type;
4994 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004995
Douglas Gregorfe921a72010-12-20 23:36:19 +00004996 class pointer {
4997 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004998
Douglas Gregorfe921a72010-12-20 23:36:19 +00004999 public:
5000 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005001
Douglas Gregorfe921a72010-12-20 23:36:19 +00005002 const TemplateArgumentLoc *operator->() const {
5003 return &Arg;
5004 }
5005 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005006
5007
Douglas Gregorfe921a72010-12-20 23:36:19 +00005008 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005009
Douglas Gregorfe921a72010-12-20 23:36:19 +00005010 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5011 unsigned Index)
5012 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005013
Douglas Gregorfe921a72010-12-20 23:36:19 +00005014 TemplateArgumentLocContainerIterator &operator++() {
5015 ++Index;
5016 return *this;
5017 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005018
Douglas Gregorfe921a72010-12-20 23:36:19 +00005019 TemplateArgumentLocContainerIterator operator++(int) {
5020 TemplateArgumentLocContainerIterator Old(*this);
5021 ++(*this);
5022 return Old;
5023 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005024
Douglas Gregorfe921a72010-12-20 23:36:19 +00005025 TemplateArgumentLoc operator*() const {
5026 return Container->getArgLoc(Index);
5027 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005028
Douglas Gregorfe921a72010-12-20 23:36:19 +00005029 pointer operator->() const {
5030 return pointer(Container->getArgLoc(Index));
5031 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005032
Douglas Gregorfe921a72010-12-20 23:36:19 +00005033 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005034 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005035 return X.Container == Y.Container && X.Index == Y.Index;
5036 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005037
Douglas Gregorfe921a72010-12-20 23:36:19 +00005038 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005039 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005040 return !(X == Y);
5041 }
5042 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005043
5044
John McCall31f82722010-11-12 08:19:04 +00005045template <typename Derived>
5046QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5047 TypeLocBuilder &TLB,
5048 TemplateSpecializationTypeLoc TL,
5049 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005050 TemplateArgumentListInfo NewTemplateArgs;
5051 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5052 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005053 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5054 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005055 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005056 ArgIterator(TL, TL.getNumArgs()),
5057 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005058 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005059
John McCall0ad16662009-10-29 08:12:44 +00005060 // FIXME: maybe don't rebuild if all the template arguments are the same.
5061
5062 QualType Result =
5063 getDerived().RebuildTemplateSpecializationType(Template,
5064 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005065 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005066
5067 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005068 // Specializations of template template parameters are represented as
5069 // TemplateSpecializationTypes, and substitution of type alias templates
5070 // within a dependent context can transform them into
5071 // DependentTemplateSpecializationTypes.
5072 if (isa<DependentTemplateSpecializationType>(Result)) {
5073 DependentTemplateSpecializationTypeLoc NewTL
5074 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005075 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005076 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005077 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005078 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005079 NewTL.setLAngleLoc(TL.getLAngleLoc());
5080 NewTL.setRAngleLoc(TL.getRAngleLoc());
5081 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5082 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5083 return Result;
5084 }
5085
John McCall0ad16662009-10-29 08:12:44 +00005086 TemplateSpecializationTypeLoc NewTL
5087 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005088 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005089 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5090 NewTL.setLAngleLoc(TL.getLAngleLoc());
5091 NewTL.setRAngleLoc(TL.getRAngleLoc());
5092 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5093 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005094 }
Mike Stump11289f42009-09-09 15:08:12 +00005095
John McCall0ad16662009-10-29 08:12:44 +00005096 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005097}
Mike Stump11289f42009-09-09 15:08:12 +00005098
Douglas Gregor5a064722011-02-28 17:23:35 +00005099template <typename Derived>
5100QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5101 TypeLocBuilder &TLB,
5102 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005103 TemplateName Template,
5104 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005105 TemplateArgumentListInfo NewTemplateArgs;
5106 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5107 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5108 typedef TemplateArgumentLocContainerIterator<
5109 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005110 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005111 ArgIterator(TL, TL.getNumArgs()),
5112 NewTemplateArgs))
5113 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005114
Douglas Gregor5a064722011-02-28 17:23:35 +00005115 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005116
Douglas Gregor5a064722011-02-28 17:23:35 +00005117 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5118 QualType Result
5119 = getSema().Context.getDependentTemplateSpecializationType(
5120 TL.getTypePtr()->getKeyword(),
5121 DTN->getQualifier(),
5122 DTN->getIdentifier(),
5123 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005124
Douglas Gregor5a064722011-02-28 17:23:35 +00005125 DependentTemplateSpecializationTypeLoc NewTL
5126 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005127 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005128 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005129 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005130 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005131 NewTL.setLAngleLoc(TL.getLAngleLoc());
5132 NewTL.setRAngleLoc(TL.getRAngleLoc());
5133 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5134 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5135 return Result;
5136 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005137
5138 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005139 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005140 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005141 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005142
Douglas Gregor5a064722011-02-28 17:23:35 +00005143 if (!Result.isNull()) {
5144 /// FIXME: Wrap this in an elaborated-type-specifier?
5145 TemplateSpecializationTypeLoc NewTL
5146 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005147 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005148 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005149 NewTL.setLAngleLoc(TL.getLAngleLoc());
5150 NewTL.setRAngleLoc(TL.getRAngleLoc());
5151 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5152 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5153 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005154
Douglas Gregor5a064722011-02-28 17:23:35 +00005155 return Result;
5156}
5157
Mike Stump11289f42009-09-09 15:08:12 +00005158template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005159QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005160TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005161 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005162 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005163
Douglas Gregor844cb502011-03-01 18:12:44 +00005164 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005165 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005166 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005167 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005168 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5169 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005170 return QualType();
5171 }
Mike Stump11289f42009-09-09 15:08:12 +00005172
John McCall31f82722010-11-12 08:19:04 +00005173 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5174 if (NamedT.isNull())
5175 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005176
Richard Smith3f1b5d02011-05-05 21:57:07 +00005177 // C++0x [dcl.type.elab]p2:
5178 // If the identifier resolves to a typedef-name or the simple-template-id
5179 // resolves to an alias template specialization, the
5180 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005181 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5182 if (const TemplateSpecializationType *TST =
5183 NamedT->getAs<TemplateSpecializationType>()) {
5184 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005185 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5186 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005187 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5188 diag::err_tag_reference_non_tag) << 4;
5189 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5190 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005191 }
5192 }
5193
John McCall550e0c22009-10-21 00:40:46 +00005194 QualType Result = TL.getType();
5195 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005196 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005197 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005198 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005199 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005200 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005201 if (Result.isNull())
5202 return QualType();
5203 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005204
Abramo Bagnara6150c882010-05-11 21:36:43 +00005205 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005206 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005207 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005208 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005209}
Mike Stump11289f42009-09-09 15:08:12 +00005210
5211template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005212QualType TreeTransform<Derived>::TransformAttributedType(
5213 TypeLocBuilder &TLB,
5214 AttributedTypeLoc TL) {
5215 const AttributedType *oldType = TL.getTypePtr();
5216 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5217 if (modifiedType.isNull())
5218 return QualType();
5219
5220 QualType result = TL.getType();
5221
5222 // FIXME: dependent operand expressions?
5223 if (getDerived().AlwaysRebuild() ||
5224 modifiedType != oldType->getModifiedType()) {
5225 // TODO: this is really lame; we should really be rebuilding the
5226 // equivalent type from first principles.
5227 QualType equivalentType
5228 = getDerived().TransformType(oldType->getEquivalentType());
5229 if (equivalentType.isNull())
5230 return QualType();
5231 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5232 modifiedType,
5233 equivalentType);
5234 }
5235
5236 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5237 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5238 if (TL.hasAttrOperand())
5239 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5240 if (TL.hasAttrExprOperand())
5241 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5242 else if (TL.hasAttrEnumOperand())
5243 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5244
5245 return result;
5246}
5247
5248template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005249QualType
5250TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5251 ParenTypeLoc TL) {
5252 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5253 if (Inner.isNull())
5254 return QualType();
5255
5256 QualType Result = TL.getType();
5257 if (getDerived().AlwaysRebuild() ||
5258 Inner != TL.getInnerLoc().getType()) {
5259 Result = getDerived().RebuildParenType(Inner);
5260 if (Result.isNull())
5261 return QualType();
5262 }
5263
5264 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5265 NewTL.setLParenLoc(TL.getLParenLoc());
5266 NewTL.setRParenLoc(TL.getRParenLoc());
5267 return Result;
5268}
5269
5270template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005271QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005272 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005273 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005274
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005275 NestedNameSpecifierLoc QualifierLoc
5276 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5277 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005278 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005279
John McCallc392f372010-06-11 00:33:02 +00005280 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005281 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005282 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005283 QualifierLoc,
5284 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005285 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005286 if (Result.isNull())
5287 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005288
Abramo Bagnarad7548482010-05-19 21:37:53 +00005289 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5290 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005291 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5292
Abramo Bagnarad7548482010-05-19 21:37:53 +00005293 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005294 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005295 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005296 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005297 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005298 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005299 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005300 NewTL.setNameLoc(TL.getNameLoc());
5301 }
John McCall550e0c22009-10-21 00:40:46 +00005302 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005303}
Mike Stump11289f42009-09-09 15:08:12 +00005304
Douglas Gregord6ff3322009-08-04 16:50:30 +00005305template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005306QualType TreeTransform<Derived>::
5307 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005308 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005309 NestedNameSpecifierLoc QualifierLoc;
5310 if (TL.getQualifierLoc()) {
5311 QualifierLoc
5312 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5313 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005314 return QualType();
5315 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005316
John McCall31f82722010-11-12 08:19:04 +00005317 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005318 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005319}
5320
5321template<typename Derived>
5322QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005323TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5324 DependentTemplateSpecializationTypeLoc TL,
5325 NestedNameSpecifierLoc QualifierLoc) {
5326 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005327
Douglas Gregora7a795b2011-03-01 20:11:18 +00005328 TemplateArgumentListInfo NewTemplateArgs;
5329 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5330 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005331
Douglas Gregora7a795b2011-03-01 20:11:18 +00005332 typedef TemplateArgumentLocContainerIterator<
5333 DependentTemplateSpecializationTypeLoc> ArgIterator;
5334 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5335 ArgIterator(TL, TL.getNumArgs()),
5336 NewTemplateArgs))
5337 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005338
Douglas Gregora7a795b2011-03-01 20:11:18 +00005339 QualType Result
5340 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5341 QualifierLoc,
5342 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005343 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005344 NewTemplateArgs);
5345 if (Result.isNull())
5346 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005347
Douglas Gregora7a795b2011-03-01 20:11:18 +00005348 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5349 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005350
Douglas Gregora7a795b2011-03-01 20:11:18 +00005351 // Copy information relevant to the template specialization.
5352 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005353 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005354 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005355 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005356 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5357 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005358 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005359 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005360
Douglas Gregora7a795b2011-03-01 20:11:18 +00005361 // Copy information relevant to the elaborated type.
5362 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005363 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005364 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005365 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5366 DependentTemplateSpecializationTypeLoc SpecTL
5367 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005368 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005369 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005370 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005371 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005372 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5373 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005374 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005375 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005376 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005377 TemplateSpecializationTypeLoc SpecTL
5378 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005379 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005380 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005381 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5382 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005383 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005384 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005385 }
5386 return Result;
5387}
5388
5389template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005390QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5391 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005392 QualType Pattern
5393 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005394 if (Pattern.isNull())
5395 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005396
5397 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005398 if (getDerived().AlwaysRebuild() ||
5399 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005400 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005401 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005402 TL.getEllipsisLoc(),
5403 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005404 if (Result.isNull())
5405 return QualType();
5406 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005407
Douglas Gregor822d0302011-01-12 17:07:58 +00005408 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5409 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5410 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005411}
5412
5413template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005414QualType
5415TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005416 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005417 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005418 TLB.pushFullCopy(TL);
5419 return TL.getType();
5420}
5421
5422template<typename Derived>
5423QualType
5424TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005425 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005426 // ObjCObjectType is never dependent.
5427 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005428 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005429}
Mike Stump11289f42009-09-09 15:08:12 +00005430
5431template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005432QualType
5433TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005434 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005435 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005436 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005437 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005438}
5439
Douglas Gregord6ff3322009-08-04 16:50:30 +00005440//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005441// Statement transformation
5442//===----------------------------------------------------------------------===//
5443template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005444StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005445TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005446 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005447}
5448
5449template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005450StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005451TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5452 return getDerived().TransformCompoundStmt(S, false);
5453}
5454
5455template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005456StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005457TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005458 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005459 Sema::CompoundScopeRAII CompoundScope(getSema());
5460
John McCall1ababa62010-08-27 19:56:05 +00005461 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005462 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005463 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005464 for (auto *B : S->body()) {
5465 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005466 if (Result.isInvalid()) {
5467 // Immediately fail if this was a DeclStmt, since it's very
5468 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005469 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005470 return StmtError();
5471
5472 // Otherwise, just keep processing substatements and fail later.
5473 SubStmtInvalid = true;
5474 continue;
5475 }
Mike Stump11289f42009-09-09 15:08:12 +00005476
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005477 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005478 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005479 }
Mike Stump11289f42009-09-09 15:08:12 +00005480
John McCall1ababa62010-08-27 19:56:05 +00005481 if (SubStmtInvalid)
5482 return StmtError();
5483
Douglas Gregorebe10102009-08-20 07:17:43 +00005484 if (!getDerived().AlwaysRebuild() &&
5485 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005486 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005487
5488 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005489 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005490 S->getRBracLoc(),
5491 IsStmtExpr);
5492}
Mike Stump11289f42009-09-09 15:08:12 +00005493
Douglas Gregorebe10102009-08-20 07:17:43 +00005494template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005495StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005496TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005497 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005498 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005499 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5500 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005501
Eli Friedman06577382009-11-19 03:14:00 +00005502 // Transform the left-hand case value.
5503 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005504 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005505 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005506 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005507
Eli Friedman06577382009-11-19 03:14:00 +00005508 // Transform the right-hand case value (for the GNU case-range extension).
5509 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005510 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005511 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005512 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005513 }
Mike Stump11289f42009-09-09 15:08:12 +00005514
Douglas Gregorebe10102009-08-20 07:17:43 +00005515 // Build the case statement.
5516 // Case statements are always rebuilt so that they will attached to their
5517 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005518 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005519 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005520 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005521 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005522 S->getColonLoc());
5523 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005524 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005525
Douglas Gregorebe10102009-08-20 07:17:43 +00005526 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005527 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005528 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005529 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005530
Douglas Gregorebe10102009-08-20 07:17:43 +00005531 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005532 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005533}
5534
5535template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005536StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005537TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005538 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005539 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005540 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005541 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005542
Douglas Gregorebe10102009-08-20 07:17:43 +00005543 // Default statements are always rebuilt
5544 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005545 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005546}
Mike Stump11289f42009-09-09 15:08:12 +00005547
Douglas Gregorebe10102009-08-20 07:17:43 +00005548template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005549StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005550TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005551 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005552 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005553 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005554
Chris Lattnercab02a62011-02-17 20:34:02 +00005555 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5556 S->getDecl());
5557 if (!LD)
5558 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005559
5560
Douglas Gregorebe10102009-08-20 07:17:43 +00005561 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005562 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005563 cast<LabelDecl>(LD), SourceLocation(),
5564 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005565}
Mike Stump11289f42009-09-09 15:08:12 +00005566
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005567template <typename Derived>
5568const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
5569 if (!R)
5570 return R;
5571
5572 switch (R->getKind()) {
5573// Transform attributes with a pragma spelling by calling TransformXXXAttr.
5574#define ATTR(X)
5575#define PRAGMA_SPELLING_ATTR(X) \
5576 case attr::X: \
5577 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
5578#include "clang/Basic/AttrList.inc"
5579 default:
5580 return R;
5581 }
5582}
5583
5584template <typename Derived>
5585StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5586 bool AttrsChanged = false;
5587 SmallVector<const Attr *, 1> Attrs;
5588
5589 // Visit attributes and keep track if any are transformed.
5590 for (const auto *I : S->getAttrs()) {
5591 const Attr *R = getDerived().TransformAttr(I);
5592 AttrsChanged |= (I != R);
5593 Attrs.push_back(R);
5594 }
5595
Richard Smithc202b282012-04-14 00:33:13 +00005596 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5597 if (SubStmt.isInvalid())
5598 return StmtError();
5599
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005600 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00005601 return S;
5602
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005603 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00005604 SubStmt.get());
5605}
5606
5607template<typename Derived>
5608StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005609TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005610 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005611 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005612 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005613 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005614 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005615 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005616 getDerived().TransformDefinition(
5617 S->getConditionVariable()->getLocation(),
5618 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005619 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005620 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005621 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005622 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005623
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005624 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005625 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005626
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005627 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005628 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005629 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005630 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005631 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005632 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005633
John McCallb268a282010-08-23 23:25:46 +00005634 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005635 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005636 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005637
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005638 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005639 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005640 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005641
Douglas Gregorebe10102009-08-20 07:17:43 +00005642 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005643 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005644 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005645 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005646
Douglas Gregorebe10102009-08-20 07:17:43 +00005647 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005648 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005649 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005650 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005651
Douglas Gregorebe10102009-08-20 07:17:43 +00005652 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005653 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005654 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005655 Then.get() == S->getThen() &&
5656 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005657 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005658
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005659 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005660 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005661 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005662}
5663
5664template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005665StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005666TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005667 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005668 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005669 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005670 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005671 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005672 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005673 getDerived().TransformDefinition(
5674 S->getConditionVariable()->getLocation(),
5675 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005676 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005677 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005678 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005679 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005680
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005681 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005682 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005683 }
Mike Stump11289f42009-09-09 15:08:12 +00005684
Douglas Gregorebe10102009-08-20 07:17:43 +00005685 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005686 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005687 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005688 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005689 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005690 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005691
Douglas Gregorebe10102009-08-20 07:17:43 +00005692 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005693 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005694 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005695 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005696
Douglas Gregorebe10102009-08-20 07:17:43 +00005697 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005698 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5699 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005700}
Mike Stump11289f42009-09-09 15:08:12 +00005701
Douglas Gregorebe10102009-08-20 07:17:43 +00005702template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005703StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005704TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005705 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005706 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005707 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005708 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005709 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005710 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005711 getDerived().TransformDefinition(
5712 S->getConditionVariable()->getLocation(),
5713 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005714 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005715 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005716 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005717 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005718
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005719 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005720 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005721
5722 if (S->getCond()) {
5723 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005724 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5725 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005726 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005727 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005728 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005729 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005730 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005731 }
Mike Stump11289f42009-09-09 15:08:12 +00005732
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005733 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005734 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005735 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005736
Douglas Gregorebe10102009-08-20 07:17:43 +00005737 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005738 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005739 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005740 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005741
Douglas Gregorebe10102009-08-20 07:17:43 +00005742 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005743 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005744 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005745 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005746 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005747
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005748 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005749 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005750}
Mike Stump11289f42009-09-09 15:08:12 +00005751
Douglas Gregorebe10102009-08-20 07:17:43 +00005752template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005753StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005754TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005755 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005756 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005757 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005758 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005759
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005760 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005761 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005762 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005763 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005764
Douglas Gregorebe10102009-08-20 07:17:43 +00005765 if (!getDerived().AlwaysRebuild() &&
5766 Cond.get() == S->getCond() &&
5767 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005768 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005769
John McCallb268a282010-08-23 23:25:46 +00005770 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5771 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005772 S->getRParenLoc());
5773}
Mike Stump11289f42009-09-09 15:08:12 +00005774
Douglas Gregorebe10102009-08-20 07:17:43 +00005775template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005776StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005777TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005778 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005779 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005780 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005781 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005782
Douglas Gregorebe10102009-08-20 07:17:43 +00005783 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005784 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005785 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005786 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005787 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005788 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005789 getDerived().TransformDefinition(
5790 S->getConditionVariable()->getLocation(),
5791 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005792 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005793 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005794 } else {
5795 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005796
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005797 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005798 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005799
5800 if (S->getCond()) {
5801 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005802 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5803 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005804 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005805 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005806 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005807
John McCallb268a282010-08-23 23:25:46 +00005808 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005809 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005810 }
Mike Stump11289f42009-09-09 15:08:12 +00005811
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005812 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005813 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005814 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005815
Douglas Gregorebe10102009-08-20 07:17:43 +00005816 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005817 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005818 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005819 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005820
Richard Smith945f8d32013-01-14 22:39:08 +00005821 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005822 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005823 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005824
Douglas Gregorebe10102009-08-20 07:17:43 +00005825 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005826 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005827 if (Body.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 if (!getDerived().AlwaysRebuild() &&
5831 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005832 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005833 Inc.get() == S->getInc() &&
5834 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005835 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005836
Douglas Gregorebe10102009-08-20 07:17:43 +00005837 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005838 Init.get(), FullCond, ConditionVar,
5839 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005840}
5841
5842template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005843StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005844TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005845 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5846 S->getLabel());
5847 if (!LD)
5848 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005849
Douglas Gregorebe10102009-08-20 07:17:43 +00005850 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005851 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005852 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005853}
5854
5855template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005856StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005857TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005858 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005859 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005860 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005861 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00005862
Douglas Gregorebe10102009-08-20 07:17:43 +00005863 if (!getDerived().AlwaysRebuild() &&
5864 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005865 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005866
5867 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005868 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005869}
5870
5871template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005872StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005873TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005874 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005875}
Mike Stump11289f42009-09-09 15:08:12 +00005876
Douglas Gregorebe10102009-08-20 07:17:43 +00005877template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005878StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005879TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005880 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005881}
Mike Stump11289f42009-09-09 15:08:12 +00005882
Douglas Gregorebe10102009-08-20 07:17:43 +00005883template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005884StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005885TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00005886 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
5887 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00005888 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005889 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005890
Mike Stump11289f42009-09-09 15:08:12 +00005891 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005892 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005893 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005894}
Mike Stump11289f42009-09-09 15:08:12 +00005895
Douglas Gregorebe10102009-08-20 07:17:43 +00005896template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005897StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005898TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005899 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005900 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005901 for (auto *D : S->decls()) {
5902 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005903 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005904 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005905
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005906 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005907 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005908
Douglas Gregorebe10102009-08-20 07:17:43 +00005909 Decls.push_back(Transformed);
5910 }
Mike Stump11289f42009-09-09 15:08:12 +00005911
Douglas Gregorebe10102009-08-20 07:17:43 +00005912 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005913 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005914
Rafael Espindolaab417692013-07-09 12:05:01 +00005915 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005916}
Mike Stump11289f42009-09-09 15:08:12 +00005917
Douglas Gregorebe10102009-08-20 07:17:43 +00005918template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005919StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005920TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005921
Benjamin Kramerf0623432012-08-23 22:51:59 +00005922 SmallVector<Expr*, 8> Constraints;
5923 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005924 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005925
John McCalldadc5752010-08-24 06:29:42 +00005926 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005927 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005928
5929 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005930
Anders Carlssonaaeef072010-01-24 05:50:09 +00005931 // Go through the outputs.
5932 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005933 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005934
Anders Carlssonaaeef072010-01-24 05:50:09 +00005935 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005936 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005937
Anders Carlssonaaeef072010-01-24 05:50:09 +00005938 // Transform the output expr.
5939 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005940 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005941 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005942 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005943
Anders Carlssonaaeef072010-01-24 05:50:09 +00005944 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005945
John McCallb268a282010-08-23 23:25:46 +00005946 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005947 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005948
Anders Carlssonaaeef072010-01-24 05:50:09 +00005949 // Go through the inputs.
5950 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005951 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005952
Anders Carlssonaaeef072010-01-24 05:50:09 +00005953 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005954 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005955
Anders Carlssonaaeef072010-01-24 05:50:09 +00005956 // Transform the input expr.
5957 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005958 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005959 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005960 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005961
Anders Carlssonaaeef072010-01-24 05:50:09 +00005962 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005963
John McCallb268a282010-08-23 23:25:46 +00005964 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005965 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005966
Anders Carlssonaaeef072010-01-24 05:50:09 +00005967 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005968 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005969
5970 // Go through the clobbers.
5971 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005972 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005973
5974 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005975 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00005976 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5977 S->isVolatile(), S->getNumOutputs(),
5978 S->getNumInputs(), Names.data(),
5979 Constraints, Exprs, AsmString.get(),
5980 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005981}
5982
Chad Rosier32503022012-06-11 20:47:18 +00005983template<typename Derived>
5984StmtResult
5985TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005986 ArrayRef<Token> AsmToks =
5987 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005988
John McCallf413f5e2013-05-03 00:10:13 +00005989 bool HadError = false, HadChange = false;
5990
5991 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5992 SmallVector<Expr*, 8> TransformedExprs;
5993 TransformedExprs.reserve(SrcExprs.size());
5994 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5995 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5996 if (!Result.isUsable()) {
5997 HadError = true;
5998 } else {
5999 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006000 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006001 }
6002 }
6003
6004 if (HadError) return StmtError();
6005 if (!HadChange && !getDerived().AlwaysRebuild())
6006 return Owned(S);
6007
Chad Rosierb6f46c12012-08-15 16:53:30 +00006008 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006009 AsmToks, S->getAsmString(),
6010 S->getNumOutputs(), S->getNumInputs(),
6011 S->getAllConstraints(), S->getClobbers(),
6012 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006013}
Douglas Gregorebe10102009-08-20 07:17:43 +00006014
6015template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006016StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006017TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006018 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006019 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006020 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006021 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006022
Douglas Gregor96c79492010-04-23 22:50:49 +00006023 // Transform the @catch statements (if present).
6024 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006025 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006026 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006027 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006028 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006029 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006030 if (Catch.get() != S->getCatchStmt(I))
6031 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006032 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006033 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006034
Douglas Gregor306de2f2010-04-22 23:59:56 +00006035 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006036 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006037 if (S->getFinallyStmt()) {
6038 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6039 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006040 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006041 }
6042
6043 // If nothing changed, just retain this statement.
6044 if (!getDerived().AlwaysRebuild() &&
6045 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006046 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006047 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006048 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006049
Douglas Gregor306de2f2010-04-22 23:59:56 +00006050 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006051 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006052 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006053}
Mike Stump11289f42009-09-09 15:08:12 +00006054
Douglas Gregorebe10102009-08-20 07:17:43 +00006055template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006056StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006057TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006058 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006059 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006060 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006061 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006062 if (FromVar->getTypeSourceInfo()) {
6063 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6064 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006065 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006066 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006067
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006068 QualType T;
6069 if (TSInfo)
6070 T = TSInfo->getType();
6071 else {
6072 T = getDerived().TransformType(FromVar->getType());
6073 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006074 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006075 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006076
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006077 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6078 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006079 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006080 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006081
John McCalldadc5752010-08-24 06:29:42 +00006082 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006083 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006084 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006085
6086 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006087 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006088 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006089}
Mike Stump11289f42009-09-09 15:08:12 +00006090
Douglas Gregorebe10102009-08-20 07:17:43 +00006091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006092StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006093TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006094 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006095 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006096 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006097 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006098
Douglas Gregor306de2f2010-04-22 23:59:56 +00006099 // If nothing changed, just retain this statement.
6100 if (!getDerived().AlwaysRebuild() &&
6101 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006102 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006103
6104 // Build a new statement.
6105 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006106 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006107}
Mike Stump11289f42009-09-09 15:08:12 +00006108
Douglas Gregorebe10102009-08-20 07:17:43 +00006109template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006110StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006111TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006112 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006113 if (S->getThrowExpr()) {
6114 Operand = getDerived().TransformExpr(S->getThrowExpr());
6115 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006116 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006117 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006118
Douglas Gregor2900c162010-04-22 21:44:01 +00006119 if (!getDerived().AlwaysRebuild() &&
6120 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006121 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006122
John McCallb268a282010-08-23 23:25:46 +00006123 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006124}
Mike Stump11289f42009-09-09 15:08:12 +00006125
Douglas Gregorebe10102009-08-20 07:17:43 +00006126template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006127StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006128TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006129 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006130 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006131 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006132 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006133 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006134 Object =
6135 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6136 Object.get());
6137 if (Object.isInvalid())
6138 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006139
Douglas Gregor6148de72010-04-22 22:01:21 +00006140 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006141 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006142 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006143 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006144
Douglas Gregor6148de72010-04-22 22:01:21 +00006145 // If nothing change, just retain the current statement.
6146 if (!getDerived().AlwaysRebuild() &&
6147 Object.get() == S->getSynchExpr() &&
6148 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006149 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006150
6151 // Build a new statement.
6152 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006153 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006154}
6155
6156template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006157StmtResult
John McCall31168b02011-06-15 23:02:42 +00006158TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6159 ObjCAutoreleasePoolStmt *S) {
6160 // Transform the body.
6161 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6162 if (Body.isInvalid())
6163 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006164
John McCall31168b02011-06-15 23:02:42 +00006165 // If nothing changed, just retain this statement.
6166 if (!getDerived().AlwaysRebuild() &&
6167 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006168 return S;
John McCall31168b02011-06-15 23:02:42 +00006169
6170 // Build a new statement.
6171 return getDerived().RebuildObjCAutoreleasePoolStmt(
6172 S->getAtLoc(), Body.get());
6173}
6174
6175template<typename Derived>
6176StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006177TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006178 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006179 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006180 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006181 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006182 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006183
Douglas Gregorf68a5082010-04-22 23:10:45 +00006184 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006185 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006186 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006187 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006188
Douglas Gregorf68a5082010-04-22 23:10:45 +00006189 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006190 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006191 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006192 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006193
Douglas Gregorf68a5082010-04-22 23:10:45 +00006194 // If nothing changed, just retain this statement.
6195 if (!getDerived().AlwaysRebuild() &&
6196 Element.get() == S->getElement() &&
6197 Collection.get() == S->getCollection() &&
6198 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006199 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006200
Douglas Gregorf68a5082010-04-22 23:10:45 +00006201 // Build a new statement.
6202 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006203 Element.get(),
6204 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006205 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006206 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006207}
6208
David Majnemer5f7efef2013-10-15 09:50:08 +00006209template <typename Derived>
6210StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006211 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006212 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006213 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6214 TypeSourceInfo *T =
6215 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006216 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006217 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006218
David Majnemer5f7efef2013-10-15 09:50:08 +00006219 Var = getDerived().RebuildExceptionDecl(
6220 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6221 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006222 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006223 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006224 }
Mike Stump11289f42009-09-09 15:08:12 +00006225
Douglas Gregorebe10102009-08-20 07:17:43 +00006226 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006227 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006228 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006229 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006230
David Majnemer5f7efef2013-10-15 09:50:08 +00006231 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006232 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006233 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006234
David Majnemer5f7efef2013-10-15 09:50:08 +00006235 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006236}
Mike Stump11289f42009-09-09 15:08:12 +00006237
David Majnemer5f7efef2013-10-15 09:50:08 +00006238template <typename Derived>
6239StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006240 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006241 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006242 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006243 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006244
Douglas Gregorebe10102009-08-20 07:17:43 +00006245 // Transform the handlers.
6246 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006247 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006248 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006249 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006250 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006251 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006252
Douglas Gregorebe10102009-08-20 07:17:43 +00006253 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006254 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006255 }
Mike Stump11289f42009-09-09 15:08:12 +00006256
David Majnemer5f7efef2013-10-15 09:50:08 +00006257 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006258 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006259 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006260
John McCallb268a282010-08-23 23:25:46 +00006261 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006262 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006263}
Mike Stump11289f42009-09-09 15:08:12 +00006264
Richard Smith02e85f32011-04-14 22:09:26 +00006265template<typename Derived>
6266StmtResult
6267TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6268 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6269 if (Range.isInvalid())
6270 return StmtError();
6271
6272 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6273 if (BeginEnd.isInvalid())
6274 return StmtError();
6275
6276 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6277 if (Cond.isInvalid())
6278 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006279 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006280 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006281 if (Cond.isInvalid())
6282 return StmtError();
6283 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006284 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006285
6286 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6287 if (Inc.isInvalid())
6288 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006289 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006290 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006291
6292 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6293 if (LoopVar.isInvalid())
6294 return StmtError();
6295
6296 StmtResult NewStmt = S;
6297 if (getDerived().AlwaysRebuild() ||
6298 Range.get() != S->getRangeStmt() ||
6299 BeginEnd.get() != S->getBeginEndStmt() ||
6300 Cond.get() != S->getCond() ||
6301 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006302 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006303 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6304 S->getColonLoc(), Range.get(),
6305 BeginEnd.get(), Cond.get(),
6306 Inc.get(), LoopVar.get(),
6307 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006308 if (NewStmt.isInvalid())
6309 return StmtError();
6310 }
Richard Smith02e85f32011-04-14 22:09:26 +00006311
6312 StmtResult Body = getDerived().TransformStmt(S->getBody());
6313 if (Body.isInvalid())
6314 return StmtError();
6315
6316 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6317 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006318 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006319 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6320 S->getColonLoc(), Range.get(),
6321 BeginEnd.get(), Cond.get(),
6322 Inc.get(), LoopVar.get(),
6323 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006324 if (NewStmt.isInvalid())
6325 return StmtError();
6326 }
Richard Smith02e85f32011-04-14 22:09:26 +00006327
6328 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006329 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006330
6331 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6332}
6333
John Wiegley1c0675e2011-04-28 01:08:34 +00006334template<typename Derived>
6335StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006336TreeTransform<Derived>::TransformMSDependentExistsStmt(
6337 MSDependentExistsStmt *S) {
6338 // Transform the nested-name-specifier, if any.
6339 NestedNameSpecifierLoc QualifierLoc;
6340 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006341 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006342 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6343 if (!QualifierLoc)
6344 return StmtError();
6345 }
6346
6347 // Transform the declaration name.
6348 DeclarationNameInfo NameInfo = S->getNameInfo();
6349 if (NameInfo.getName()) {
6350 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6351 if (!NameInfo.getName())
6352 return StmtError();
6353 }
6354
6355 // Check whether anything changed.
6356 if (!getDerived().AlwaysRebuild() &&
6357 QualifierLoc == S->getQualifierLoc() &&
6358 NameInfo.getName() == S->getNameInfo().getName())
6359 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006360
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006361 // Determine whether this name exists, if we can.
6362 CXXScopeSpec SS;
6363 SS.Adopt(QualifierLoc);
6364 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006365 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006366 case Sema::IER_Exists:
6367 if (S->isIfExists())
6368 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006369
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006370 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6371
6372 case Sema::IER_DoesNotExist:
6373 if (S->isIfNotExists())
6374 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006375
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006376 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006377
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006378 case Sema::IER_Dependent:
6379 Dependent = true;
6380 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006381
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006382 case Sema::IER_Error:
6383 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006384 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006385
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006386 // We need to continue with the instantiation, so do so now.
6387 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6388 if (SubStmt.isInvalid())
6389 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006390
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006391 // If we have resolved the name, just transform to the substatement.
6392 if (!Dependent)
6393 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006394
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006395 // The name is still dependent, so build a dependent expression again.
6396 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6397 S->isIfExists(),
6398 QualifierLoc,
6399 NameInfo,
6400 SubStmt.get());
6401}
6402
6403template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006404ExprResult
6405TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6406 NestedNameSpecifierLoc QualifierLoc;
6407 if (E->getQualifierLoc()) {
6408 QualifierLoc
6409 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6410 if (!QualifierLoc)
6411 return ExprError();
6412 }
6413
6414 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6415 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6416 if (!PD)
6417 return ExprError();
6418
6419 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6420 if (Base.isInvalid())
6421 return ExprError();
6422
6423 return new (SemaRef.getASTContext())
6424 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6425 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6426 QualifierLoc, E->getMemberLoc());
6427}
6428
David Majnemerfad8f482013-10-15 09:33:02 +00006429template <typename Derived>
6430StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006431 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006432 if (TryBlock.isInvalid())
6433 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006434
6435 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006436 if (Handler.isInvalid())
6437 return StmtError();
6438
David Majnemerfad8f482013-10-15 09:33:02 +00006439 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6440 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006441 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006442
Warren Huntf6be4cb2014-07-25 20:52:51 +00006443 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6444 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006445}
6446
David Majnemerfad8f482013-10-15 09:33:02 +00006447template <typename Derived>
6448StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006449 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006450 if (Block.isInvalid())
6451 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006452
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006453 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006454}
6455
David Majnemerfad8f482013-10-15 09:33:02 +00006456template <typename Derived>
6457StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006458 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006459 if (FilterExpr.isInvalid())
6460 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006461
David Majnemer7e755502013-10-15 09:30:14 +00006462 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006463 if (Block.isInvalid())
6464 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006465
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006466 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6467 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006468}
6469
David Majnemerfad8f482013-10-15 09:33:02 +00006470template <typename Derived>
6471StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6472 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006473 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6474 else
6475 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6476}
6477
Nico Weber9b982072014-07-07 00:12:30 +00006478template<typename Derived>
6479StmtResult
6480TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6481 return S;
6482}
6483
Alexander Musman64d33f12014-06-04 07:53:32 +00006484//===----------------------------------------------------------------------===//
6485// OpenMP directive transformation
6486//===----------------------------------------------------------------------===//
6487template <typename Derived>
6488StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6489 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006490
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006491 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006492 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006493 ArrayRef<OMPClause *> Clauses = D->clauses();
6494 TClauses.reserve(Clauses.size());
6495 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6496 I != E; ++I) {
6497 if (*I) {
6498 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevc5e02582014-06-16 07:08:35 +00006499 if (Clause)
6500 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006501 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006502 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006503 }
6504 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006505 StmtResult AssociatedStmt;
6506 if (D->hasAssociatedStmt()) {
6507 if (!D->getAssociatedStmt()) {
6508 return StmtError();
6509 }
6510 AssociatedStmt = getDerived().TransformStmt(D->getAssociatedStmt());
6511 if (AssociatedStmt.isInvalid()) {
6512 return StmtError();
6513 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006514 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006515 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006516 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006517 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006518
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006519 // Transform directive name for 'omp critical' directive.
6520 DeclarationNameInfo DirName;
6521 if (D->getDirectiveKind() == OMPD_critical) {
6522 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6523 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6524 }
6525
Alexander Musman64d33f12014-06-04 07:53:32 +00006526 return getDerived().RebuildOMPExecutableDirective(
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006527 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
6528 D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006529}
6530
Alexander Musman64d33f12014-06-04 07:53:32 +00006531template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006532StmtResult
6533TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6534 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006535 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6536 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006537 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6538 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6539 return Res;
6540}
6541
Alexander Musman64d33f12014-06-04 07:53:32 +00006542template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006543StmtResult
6544TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6545 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006546 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6547 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006548 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6549 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006550 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006551}
6552
Alexey Bataevf29276e2014-06-18 04:14:57 +00006553template <typename Derived>
6554StmtResult
6555TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6556 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006557 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6558 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006559 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6560 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6561 return Res;
6562}
6563
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006564template <typename Derived>
6565StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00006566TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
6567 DeclarationNameInfo DirName;
6568 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
6569 D->getLocStart());
6570 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6571 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6572 return Res;
6573}
6574
6575template <typename Derived>
6576StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006577TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6578 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006579 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6580 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006581 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6582 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6583 return Res;
6584}
6585
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006586template <typename Derived>
6587StmtResult
6588TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6589 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006590 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6591 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006592 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6593 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6594 return Res;
6595}
6596
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006597template <typename Derived>
6598StmtResult
6599TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6600 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006601 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6602 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006603 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6604 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6605 return Res;
6606}
6607
Alexey Bataev4acb8592014-07-07 13:01:15 +00006608template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006609StmtResult
6610TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6611 DeclarationNameInfo DirName;
6612 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6613 D->getLocStart());
6614 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6615 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6616 return Res;
6617}
6618
6619template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006620StmtResult
6621TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6622 getDerived().getSema().StartOpenMPDSABlock(
6623 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
6624 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6625 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6626 return Res;
6627}
6628
6629template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00006630StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6631 OMPParallelForDirective *D) {
6632 DeclarationNameInfo DirName;
6633 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6634 nullptr, D->getLocStart());
6635 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6636 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6637 return Res;
6638}
6639
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006640template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00006641StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
6642 OMPParallelForSimdDirective *D) {
6643 DeclarationNameInfo DirName;
6644 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
6645 nullptr, D->getLocStart());
6646 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6647 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6648 return Res;
6649}
6650
6651template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006652StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
6653 OMPParallelSectionsDirective *D) {
6654 DeclarationNameInfo DirName;
6655 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
6656 nullptr, D->getLocStart());
6657 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6658 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6659 return Res;
6660}
6661
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00006662template <typename Derived>
6663StmtResult
6664TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
6665 DeclarationNameInfo DirName;
6666 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
6667 D->getLocStart());
6668 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6669 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6670 return Res;
6671}
6672
Alexey Bataev68446b72014-07-18 07:47:19 +00006673template <typename Derived>
6674StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
6675 OMPTaskyieldDirective *D) {
6676 DeclarationNameInfo DirName;
6677 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
6678 D->getLocStart());
6679 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6680 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6681 return Res;
6682}
6683
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00006684template <typename Derived>
6685StmtResult
6686TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
6687 DeclarationNameInfo DirName;
6688 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
6689 D->getLocStart());
6690 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6691 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6692 return Res;
6693}
6694
Alexey Bataev2df347a2014-07-18 10:17:07 +00006695template <typename Derived>
6696StmtResult
6697TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
6698 DeclarationNameInfo DirName;
6699 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
6700 D->getLocStart());
6701 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6702 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6703 return Res;
6704}
6705
Alexey Bataev6125da92014-07-21 11:26:11 +00006706template <typename Derived>
6707StmtResult
6708TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
6709 DeclarationNameInfo DirName;
6710 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
6711 D->getLocStart());
6712 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6713 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6714 return Res;
6715}
6716
Alexey Bataev9fb6e642014-07-22 06:45:04 +00006717template <typename Derived>
6718StmtResult
6719TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
6720 DeclarationNameInfo DirName;
6721 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
6722 D->getLocStart());
6723 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6724 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6725 return Res;
6726}
6727
Alexey Bataev0162e452014-07-22 10:10:35 +00006728template <typename Derived>
6729StmtResult
6730TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
6731 DeclarationNameInfo DirName;
6732 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
6733 D->getLocStart());
6734 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6735 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6736 return Res;
6737}
6738
Alexey Bataev0bd520b2014-09-19 08:19:49 +00006739template <typename Derived>
6740StmtResult
6741TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
6742 DeclarationNameInfo DirName;
6743 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
6744 D->getLocStart());
6745 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6746 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6747 return Res;
6748}
6749
Alexey Bataev13314bf2014-10-09 04:18:56 +00006750template <typename Derived>
6751StmtResult
6752TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
6753 DeclarationNameInfo DirName;
6754 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
6755 D->getLocStart());
6756 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6757 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6758 return Res;
6759}
6760
Alexander Musman64d33f12014-06-04 07:53:32 +00006761//===----------------------------------------------------------------------===//
6762// OpenMP clause transformation
6763//===----------------------------------------------------------------------===//
6764template <typename Derived>
6765OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006766 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6767 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006768 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006769 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006770 C->getLParenLoc(), C->getLocEnd());
6771}
6772
Alexander Musman64d33f12014-06-04 07:53:32 +00006773template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00006774OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
6775 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6776 if (Cond.isInvalid())
6777 return nullptr;
6778 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
6779 C->getLParenLoc(), C->getLocEnd());
6780}
6781
6782template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006783OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006784TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6785 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6786 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006787 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006788 return getDerived().RebuildOMPNumThreadsClause(
6789 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006790}
6791
Alexey Bataev62c87d22014-03-21 04:51:18 +00006792template <typename Derived>
6793OMPClause *
6794TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6795 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6796 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006797 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006798 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006799 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006800}
6801
Alexander Musman8bd31e62014-05-27 15:12:19 +00006802template <typename Derived>
6803OMPClause *
6804TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6805 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6806 if (E.isInvalid())
6807 return 0;
6808 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006809 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006810}
6811
Alexander Musman64d33f12014-06-04 07:53:32 +00006812template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006813OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006814TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006815 return getDerived().RebuildOMPDefaultClause(
6816 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6817 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006818}
6819
Alexander Musman64d33f12014-06-04 07:53:32 +00006820template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006821OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006822TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006823 return getDerived().RebuildOMPProcBindClause(
6824 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6825 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006826}
6827
Alexander Musman64d33f12014-06-04 07:53:32 +00006828template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006829OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00006830TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
6831 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
6832 if (E.isInvalid())
6833 return nullptr;
6834 return getDerived().RebuildOMPScheduleClause(
6835 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
6836 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
6837}
6838
6839template <typename Derived>
6840OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00006841TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
6842 // No need to rebuild this clause, no template-dependent parameters.
6843 return C;
6844}
6845
6846template <typename Derived>
6847OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00006848TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
6849 // No need to rebuild this clause, no template-dependent parameters.
6850 return C;
6851}
6852
6853template <typename Derived>
6854OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00006855TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
6856 // No need to rebuild this clause, no template-dependent parameters.
6857 return C;
6858}
6859
6860template <typename Derived>
6861OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00006862TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
6863 // No need to rebuild this clause, no template-dependent parameters.
6864 return C;
6865}
6866
6867template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00006868OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
6869 // No need to rebuild this clause, no template-dependent parameters.
6870 return C;
6871}
6872
6873template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00006874OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
6875 // No need to rebuild this clause, no template-dependent parameters.
6876 return C;
6877}
6878
6879template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00006880OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00006881TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
6882 // No need to rebuild this clause, no template-dependent parameters.
6883 return C;
6884}
6885
6886template <typename Derived>
6887OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00006888TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
6889 // No need to rebuild this clause, no template-dependent parameters.
6890 return C;
6891}
6892
6893template <typename Derived>
6894OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00006895TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
6896 // No need to rebuild this clause, no template-dependent parameters.
6897 return C;
6898}
6899
6900template <typename Derived>
6901OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006902TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006903 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006904 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006905 for (auto *VE : C->varlists()) {
6906 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006907 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006908 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006909 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006910 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006911 return getDerived().RebuildOMPPrivateClause(
6912 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006913}
6914
Alexander Musman64d33f12014-06-04 07:53:32 +00006915template <typename Derived>
6916OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
6917 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006918 llvm::SmallVector<Expr *, 16> Vars;
6919 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006920 for (auto *VE : C->varlists()) {
6921 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006922 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006923 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006924 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006925 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006926 return getDerived().RebuildOMPFirstprivateClause(
6927 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006928}
6929
Alexander Musman64d33f12014-06-04 07:53:32 +00006930template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006931OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00006932TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
6933 llvm::SmallVector<Expr *, 16> Vars;
6934 Vars.reserve(C->varlist_size());
6935 for (auto *VE : C->varlists()) {
6936 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6937 if (EVar.isInvalid())
6938 return nullptr;
6939 Vars.push_back(EVar.get());
6940 }
6941 return getDerived().RebuildOMPLastprivateClause(
6942 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6943}
6944
6945template <typename Derived>
6946OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006947TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6948 llvm::SmallVector<Expr *, 16> Vars;
6949 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006950 for (auto *VE : C->varlists()) {
6951 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006952 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006953 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006954 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006955 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006956 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
6957 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006958}
6959
Alexander Musman64d33f12014-06-04 07:53:32 +00006960template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006961OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00006962TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
6963 llvm::SmallVector<Expr *, 16> Vars;
6964 Vars.reserve(C->varlist_size());
6965 for (auto *VE : C->varlists()) {
6966 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6967 if (EVar.isInvalid())
6968 return nullptr;
6969 Vars.push_back(EVar.get());
6970 }
6971 CXXScopeSpec ReductionIdScopeSpec;
6972 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
6973
6974 DeclarationNameInfo NameInfo = C->getNameInfo();
6975 if (NameInfo.getName()) {
6976 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6977 if (!NameInfo.getName())
6978 return nullptr;
6979 }
6980 return getDerived().RebuildOMPReductionClause(
6981 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
6982 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
6983}
6984
6985template <typename Derived>
6986OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006987TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6988 llvm::SmallVector<Expr *, 16> Vars;
6989 Vars.reserve(C->varlist_size());
6990 for (auto *VE : C->varlists()) {
6991 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6992 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006993 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006994 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00006995 }
6996 ExprResult Step = getDerived().TransformExpr(C->getStep());
6997 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006998 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006999 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
7000 C->getLParenLoc(),
7001 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007002}
7003
Alexander Musman64d33f12014-06-04 07:53:32 +00007004template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007005OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007006TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7007 llvm::SmallVector<Expr *, 16> Vars;
7008 Vars.reserve(C->varlist_size());
7009 for (auto *VE : C->varlists()) {
7010 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7011 if (EVar.isInvalid())
7012 return nullptr;
7013 Vars.push_back(EVar.get());
7014 }
7015 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7016 if (Alignment.isInvalid())
7017 return nullptr;
7018 return getDerived().RebuildOMPAlignedClause(
7019 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7020 C->getColonLoc(), C->getLocEnd());
7021}
7022
Alexander Musman64d33f12014-06-04 07:53:32 +00007023template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007024OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007025TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7026 llvm::SmallVector<Expr *, 16> Vars;
7027 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007028 for (auto *VE : C->varlists()) {
7029 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007030 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007031 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007032 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007033 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007034 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7035 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007036}
7037
Alexey Bataevbae9a792014-06-27 10:37:06 +00007038template <typename Derived>
7039OMPClause *
7040TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7041 llvm::SmallVector<Expr *, 16> Vars;
7042 Vars.reserve(C->varlist_size());
7043 for (auto *VE : C->varlists()) {
7044 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7045 if (EVar.isInvalid())
7046 return nullptr;
7047 Vars.push_back(EVar.get());
7048 }
7049 return getDerived().RebuildOMPCopyprivateClause(
7050 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7051}
7052
Alexey Bataev6125da92014-07-21 11:26:11 +00007053template <typename Derived>
7054OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7055 llvm::SmallVector<Expr *, 16> Vars;
7056 Vars.reserve(C->varlist_size());
7057 for (auto *VE : C->varlists()) {
7058 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7059 if (EVar.isInvalid())
7060 return nullptr;
7061 Vars.push_back(EVar.get());
7062 }
7063 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7064 C->getLParenLoc(), C->getLocEnd());
7065}
7066
Douglas Gregorebe10102009-08-20 07:17:43 +00007067//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007068// Expression transformation
7069//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007070template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007071ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007072TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007073 if (!E->isTypeDependent())
7074 return E;
7075
7076 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7077 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007078}
Mike Stump11289f42009-09-09 15:08:12 +00007079
7080template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007081ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007082TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007083 NestedNameSpecifierLoc QualifierLoc;
7084 if (E->getQualifierLoc()) {
7085 QualifierLoc
7086 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7087 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007088 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007089 }
John McCallce546572009-12-08 09:08:17 +00007090
7091 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007092 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7093 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007094 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007095 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007096
John McCall815039a2010-08-17 21:27:17 +00007097 DeclarationNameInfo NameInfo = E->getNameInfo();
7098 if (NameInfo.getName()) {
7099 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7100 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007101 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007102 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007103
7104 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007105 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007106 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007107 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007108 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007109
7110 // Mark it referenced in the new context regardless.
7111 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007112 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007113
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007114 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007115 }
John McCallce546572009-12-08 09:08:17 +00007116
Craig Topperc3ec1492014-05-26 06:22:03 +00007117 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007118 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007119 TemplateArgs = &TransArgs;
7120 TransArgs.setLAngleLoc(E->getLAngleLoc());
7121 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007122 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7123 E->getNumTemplateArgs(),
7124 TransArgs))
7125 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007126 }
7127
Chad Rosier1dcde962012-08-08 18:46:20 +00007128 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007129 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007130}
Mike Stump11289f42009-09-09 15:08:12 +00007131
Douglas Gregora16548e2009-08-11 05:31:07 +00007132template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007133ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007134TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007135 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007136}
Mike Stump11289f42009-09-09 15:08:12 +00007137
Douglas Gregora16548e2009-08-11 05:31:07 +00007138template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007139ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007140TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007141 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007142}
Mike Stump11289f42009-09-09 15:08:12 +00007143
Douglas Gregora16548e2009-08-11 05:31:07 +00007144template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007145ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007146TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007147 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007148}
Mike Stump11289f42009-09-09 15:08:12 +00007149
Douglas Gregora16548e2009-08-11 05:31:07 +00007150template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007151ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007152TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007153 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007154}
Mike Stump11289f42009-09-09 15:08:12 +00007155
Douglas Gregora16548e2009-08-11 05:31:07 +00007156template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007157ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007158TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007159 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007160}
7161
7162template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007163ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007164TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007165 if (FunctionDecl *FD = E->getDirectCallee())
7166 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007167 return SemaRef.MaybeBindToTemporary(E);
7168}
7169
7170template<typename Derived>
7171ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007172TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7173 ExprResult ControllingExpr =
7174 getDerived().TransformExpr(E->getControllingExpr());
7175 if (ControllingExpr.isInvalid())
7176 return ExprError();
7177
Chris Lattner01cf8db2011-07-20 06:58:45 +00007178 SmallVector<Expr *, 4> AssocExprs;
7179 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007180 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7181 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7182 if (TS) {
7183 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7184 if (!AssocType)
7185 return ExprError();
7186 AssocTypes.push_back(AssocType);
7187 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007188 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007189 }
7190
7191 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7192 if (AssocExpr.isInvalid())
7193 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007194 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007195 }
7196
7197 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7198 E->getDefaultLoc(),
7199 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007200 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007201 AssocTypes,
7202 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007203}
7204
7205template<typename Derived>
7206ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007207TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007208 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007209 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007210 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007211
Douglas Gregora16548e2009-08-11 05:31:07 +00007212 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007213 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007214
John McCallb268a282010-08-23 23:25:46 +00007215 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007216 E->getRParen());
7217}
7218
Richard Smithdb2630f2012-10-21 03:28:35 +00007219/// \brief The operand of a unary address-of operator has special rules: it's
7220/// allowed to refer to a non-static member of a class even if there's no 'this'
7221/// object available.
7222template<typename Derived>
7223ExprResult
7224TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7225 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007226 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007227 else
7228 return getDerived().TransformExpr(E);
7229}
7230
Mike Stump11289f42009-09-09 15:08:12 +00007231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007232ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007233TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007234 ExprResult SubExpr;
7235 if (E->getOpcode() == UO_AddrOf)
7236 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7237 else
7238 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007239 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007240 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007241
Douglas Gregora16548e2009-08-11 05:31:07 +00007242 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007243 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007244
Douglas Gregora16548e2009-08-11 05:31:07 +00007245 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7246 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007247 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007248}
Mike Stump11289f42009-09-09 15:08:12 +00007249
Douglas Gregora16548e2009-08-11 05:31:07 +00007250template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007251ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007252TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7253 // Transform the type.
7254 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7255 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007256 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007257
Douglas Gregor882211c2010-04-28 22:16:22 +00007258 // Transform all of the components into components similar to what the
7259 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007260 // FIXME: It would be slightly more efficient in the non-dependent case to
7261 // just map FieldDecls, rather than requiring the rebuilder to look for
7262 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007263 // template code that we don't care.
7264 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007265 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007266 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007267 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007268 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7269 const Node &ON = E->getComponent(I);
7270 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007271 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007272 Comp.LocStart = ON.getSourceRange().getBegin();
7273 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007274 switch (ON.getKind()) {
7275 case Node::Array: {
7276 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007277 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007278 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007279 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007280
Douglas Gregor882211c2010-04-28 22:16:22 +00007281 ExprChanged = ExprChanged || Index.get() != FromIndex;
7282 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007283 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007284 break;
7285 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007286
Douglas Gregor882211c2010-04-28 22:16:22 +00007287 case Node::Field:
7288 case Node::Identifier:
7289 Comp.isBrackets = false;
7290 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007291 if (!Comp.U.IdentInfo)
7292 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007293
Douglas Gregor882211c2010-04-28 22:16:22 +00007294 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007295
Douglas Gregord1702062010-04-29 00:18:15 +00007296 case Node::Base:
7297 // Will be recomputed during the rebuild.
7298 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007299 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007300
Douglas Gregor882211c2010-04-28 22:16:22 +00007301 Components.push_back(Comp);
7302 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007303
Douglas Gregor882211c2010-04-28 22:16:22 +00007304 // If nothing changed, retain the existing expression.
7305 if (!getDerived().AlwaysRebuild() &&
7306 Type == E->getTypeSourceInfo() &&
7307 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007308 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007309
Douglas Gregor882211c2010-04-28 22:16:22 +00007310 // Build a new offsetof expression.
7311 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7312 Components.data(), Components.size(),
7313 E->getRParenLoc());
7314}
7315
7316template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007317ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007318TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7319 assert(getDerived().AlreadyTransformed(E->getType()) &&
7320 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007321 return E;
John McCall8d69a212010-11-15 23:31:06 +00007322}
7323
7324template<typename Derived>
7325ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00007326TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
7327 return E;
7328}
7329
7330template<typename Derived>
7331ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007332TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007333 // Rebuild the syntactic form. The original syntactic form has
7334 // opaque-value expressions in it, so strip those away and rebuild
7335 // the result. This is a really awful way of doing this, but the
7336 // better solution (rebuilding the semantic expressions and
7337 // rebinding OVEs as necessary) doesn't work; we'd need
7338 // TreeTransform to not strip away implicit conversions.
7339 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7340 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007341 if (result.isInvalid()) return ExprError();
7342
7343 // If that gives us a pseudo-object result back, the pseudo-object
7344 // expression must have been an lvalue-to-rvalue conversion which we
7345 // should reapply.
7346 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007347 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007348
7349 return result;
7350}
7351
7352template<typename Derived>
7353ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007354TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7355 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007356 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007357 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007358
John McCallbcd03502009-12-07 02:54:59 +00007359 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007360 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007361 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007362
John McCall4c98fd82009-11-04 07:28:41 +00007363 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007364 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007365
Peter Collingbournee190dee2011-03-11 19:24:49 +00007366 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7367 E->getKind(),
7368 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007369 }
Mike Stump11289f42009-09-09 15:08:12 +00007370
Eli Friedmane4f22df2012-02-29 04:03:55 +00007371 // C++0x [expr.sizeof]p1:
7372 // The operand is either an expression, which is an unevaluated operand
7373 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007374 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7375 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007376
Reid Kleckner32506ed2014-06-12 23:03:48 +00007377 // Try to recover if we have something like sizeof(T::X) where X is a type.
7378 // Notably, there must be *exactly* one set of parens if X is a type.
7379 TypeSourceInfo *RecoveryTSI = nullptr;
7380 ExprResult SubExpr;
7381 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7382 if (auto *DRE =
7383 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7384 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7385 PE, DRE, false, &RecoveryTSI);
7386 else
7387 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7388
7389 if (RecoveryTSI) {
7390 return getDerived().RebuildUnaryExprOrTypeTrait(
7391 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7392 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007393 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007394
Eli Friedmane4f22df2012-02-29 04:03:55 +00007395 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007396 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007397
Peter Collingbournee190dee2011-03-11 19:24:49 +00007398 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7399 E->getOperatorLoc(),
7400 E->getKind(),
7401 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007402}
Mike Stump11289f42009-09-09 15:08:12 +00007403
Douglas Gregora16548e2009-08-11 05:31:07 +00007404template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007405ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007406TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007407 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007408 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007409 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007410
John McCalldadc5752010-08-24 06:29:42 +00007411 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007412 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007413 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007414
7415
Douglas Gregora16548e2009-08-11 05:31:07 +00007416 if (!getDerived().AlwaysRebuild() &&
7417 LHS.get() == E->getLHS() &&
7418 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007419 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007420
John McCallb268a282010-08-23 23:25:46 +00007421 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007422 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007423 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007424 E->getRBracketLoc());
7425}
Mike Stump11289f42009-09-09 15:08:12 +00007426
7427template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007428ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007429TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007430 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007431 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007432 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007433 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007434
7435 // Transform arguments.
7436 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007437 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007438 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007439 &ArgChanged))
7440 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007441
Douglas Gregora16548e2009-08-11 05:31:07 +00007442 if (!getDerived().AlwaysRebuild() &&
7443 Callee.get() == E->getCallee() &&
7444 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007445 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007446
Douglas Gregora16548e2009-08-11 05:31:07 +00007447 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007448 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007449 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007450 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007451 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007452 E->getRParenLoc());
7453}
Mike Stump11289f42009-09-09 15:08:12 +00007454
7455template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007456ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007457TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007458 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007459 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007460 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007461
Douglas Gregorea972d32011-02-28 21:54:11 +00007462 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007463 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007464 QualifierLoc
7465 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007466
Douglas Gregorea972d32011-02-28 21:54:11 +00007467 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007468 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007469 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007470 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007471
Eli Friedman2cfcef62009-12-04 06:40:45 +00007472 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007473 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7474 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007475 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007476 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007477
John McCall16df1e52010-03-30 21:47:33 +00007478 NamedDecl *FoundDecl = E->getFoundDecl();
7479 if (FoundDecl == E->getMemberDecl()) {
7480 FoundDecl = Member;
7481 } else {
7482 FoundDecl = cast_or_null<NamedDecl>(
7483 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7484 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007485 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007486 }
7487
Douglas Gregora16548e2009-08-11 05:31:07 +00007488 if (!getDerived().AlwaysRebuild() &&
7489 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007490 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007491 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007492 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007493 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007494
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007495 // Mark it referenced in the new context regardless.
7496 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007497 SemaRef.MarkMemberReferenced(E);
7498
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007499 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007500 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007501
John McCall6b51f282009-11-23 01:53:49 +00007502 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007503 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007504 TransArgs.setLAngleLoc(E->getLAngleLoc());
7505 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007506 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7507 E->getNumTemplateArgs(),
7508 TransArgs))
7509 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007510 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007511
Douglas Gregora16548e2009-08-11 05:31:07 +00007512 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007513 SourceLocation FakeOperatorLoc =
7514 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007515
John McCall38836f02010-01-15 08:34:02 +00007516 // FIXME: to do this check properly, we will need to preserve the
7517 // first-qualifier-in-scope here, just in case we had a dependent
7518 // base (and therefore couldn't do the check) and a
7519 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007520 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007521
John McCallb268a282010-08-23 23:25:46 +00007522 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007523 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007524 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007525 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007526 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007527 Member,
John McCall16df1e52010-03-30 21:47:33 +00007528 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007529 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007530 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007531 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007532}
Mike Stump11289f42009-09-09 15:08:12 +00007533
Douglas Gregora16548e2009-08-11 05:31:07 +00007534template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007535ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007536TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007537 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007538 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007539 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007540
John McCalldadc5752010-08-24 06:29:42 +00007541 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007542 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007543 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007544
Douglas Gregora16548e2009-08-11 05:31:07 +00007545 if (!getDerived().AlwaysRebuild() &&
7546 LHS.get() == E->getLHS() &&
7547 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007548 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007549
Lang Hames5de91cc2012-10-02 04:45:10 +00007550 Sema::FPContractStateRAII FPContractState(getSema());
7551 getSema().FPFeatures.fp_contract = E->isFPContractable();
7552
Douglas Gregora16548e2009-08-11 05:31:07 +00007553 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007554 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007555}
7556
Mike Stump11289f42009-09-09 15:08:12 +00007557template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007558ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007559TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007560 CompoundAssignOperator *E) {
7561 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007562}
Mike Stump11289f42009-09-09 15:08:12 +00007563
Douglas Gregora16548e2009-08-11 05:31:07 +00007564template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007565ExprResult TreeTransform<Derived>::
7566TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7567 // Just rebuild the common and RHS expressions and see whether we
7568 // get any changes.
7569
7570 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7571 if (commonExpr.isInvalid())
7572 return ExprError();
7573
7574 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7575 if (rhs.isInvalid())
7576 return ExprError();
7577
7578 if (!getDerived().AlwaysRebuild() &&
7579 commonExpr.get() == e->getCommon() &&
7580 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007581 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007582
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007583 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007584 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007585 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007586 e->getColonLoc(),
7587 rhs.get());
7588}
7589
7590template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007591ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007592TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007593 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007594 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007595 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007596
John McCalldadc5752010-08-24 06:29:42 +00007597 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007598 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007599 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007600
John McCalldadc5752010-08-24 06:29:42 +00007601 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007602 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007603 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007604
Douglas Gregora16548e2009-08-11 05:31:07 +00007605 if (!getDerived().AlwaysRebuild() &&
7606 Cond.get() == E->getCond() &&
7607 LHS.get() == E->getLHS() &&
7608 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007609 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007610
John McCallb268a282010-08-23 23:25:46 +00007611 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007612 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007613 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007614 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007615 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007616}
Mike Stump11289f42009-09-09 15:08:12 +00007617
7618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007619ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007620TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007621 // Implicit casts are eliminated during transformation, since they
7622 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007623 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007624}
Mike Stump11289f42009-09-09 15:08:12 +00007625
Douglas Gregora16548e2009-08-11 05:31:07 +00007626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007627ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007628TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007629 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7630 if (!Type)
7631 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007632
John McCalldadc5752010-08-24 06:29:42 +00007633 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007634 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007635 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007636 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007637
Douglas Gregora16548e2009-08-11 05:31:07 +00007638 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007639 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007640 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007641 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007642
John McCall97513962010-01-15 18:39:57 +00007643 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007644 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007645 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007646 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007647}
Mike Stump11289f42009-09-09 15:08:12 +00007648
Douglas Gregora16548e2009-08-11 05:31:07 +00007649template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007650ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007651TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007652 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7653 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7654 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007655 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007656
John McCalldadc5752010-08-24 06:29:42 +00007657 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007658 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007659 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007660
Douglas Gregora16548e2009-08-11 05:31:07 +00007661 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007662 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007663 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007664 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007665
John McCall5d7aa7f2010-01-19 22:33:45 +00007666 // Note: the expression type doesn't necessarily match the
7667 // type-as-written, but that's okay, because it should always be
7668 // derivable from the initializer.
7669
John McCalle15bbff2010-01-18 19:35:47 +00007670 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007671 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007672 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007673}
Mike Stump11289f42009-09-09 15:08:12 +00007674
Douglas Gregora16548e2009-08-11 05:31:07 +00007675template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007676ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007677TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007678 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007679 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007680 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007681
Douglas Gregora16548e2009-08-11 05:31:07 +00007682 if (!getDerived().AlwaysRebuild() &&
7683 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007684 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007685
Douglas Gregora16548e2009-08-11 05:31:07 +00007686 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007687 SourceLocation FakeOperatorLoc =
7688 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007689 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007690 E->getAccessorLoc(),
7691 E->getAccessor());
7692}
Mike Stump11289f42009-09-09 15:08:12 +00007693
Douglas Gregora16548e2009-08-11 05:31:07 +00007694template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007695ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007696TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007697 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007698
Benjamin Kramerf0623432012-08-23 22:51:59 +00007699 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007700 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007701 Inits, &InitChanged))
7702 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007703
Douglas Gregora16548e2009-08-11 05:31:07 +00007704 if (!getDerived().AlwaysRebuild() && !InitChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007705 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007706
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007707 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007708 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007709}
Mike Stump11289f42009-09-09 15:08:12 +00007710
Douglas Gregora16548e2009-08-11 05:31:07 +00007711template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007712ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007713TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007714 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007715
Douglas Gregorebe10102009-08-20 07:17:43 +00007716 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007717 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007718 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007719 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007720
Douglas Gregorebe10102009-08-20 07:17:43 +00007721 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007722 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007723 bool ExprChanged = false;
7724 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7725 DEnd = E->designators_end();
7726 D != DEnd; ++D) {
7727 if (D->isFieldDesignator()) {
7728 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7729 D->getDotLoc(),
7730 D->getFieldLoc()));
7731 continue;
7732 }
Mike Stump11289f42009-09-09 15:08:12 +00007733
Douglas Gregora16548e2009-08-11 05:31:07 +00007734 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007735 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007736 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007737 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007738
7739 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007740 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007741
Douglas Gregora16548e2009-08-11 05:31:07 +00007742 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007743 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007744 continue;
7745 }
Mike Stump11289f42009-09-09 15:08:12 +00007746
Douglas Gregora16548e2009-08-11 05:31:07 +00007747 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007748 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007749 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7750 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007751 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007752
John McCalldadc5752010-08-24 06:29:42 +00007753 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007754 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007755 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007756
7757 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007758 End.get(),
7759 D->getLBracketLoc(),
7760 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007761
Douglas Gregora16548e2009-08-11 05:31:07 +00007762 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7763 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007764
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007765 ArrayExprs.push_back(Start.get());
7766 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007767 }
Mike Stump11289f42009-09-09 15:08:12 +00007768
Douglas Gregora16548e2009-08-11 05:31:07 +00007769 if (!getDerived().AlwaysRebuild() &&
7770 Init.get() == E->getInit() &&
7771 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007772 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007773
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007774 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007775 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007776 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007777}
Mike Stump11289f42009-09-09 15:08:12 +00007778
Douglas Gregora16548e2009-08-11 05:31:07 +00007779template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007780ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007781TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007782 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007783 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007784
Douglas Gregor3da3c062009-10-28 00:29:27 +00007785 // FIXME: Will we ever have proper type location here? Will we actually
7786 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007787 QualType T = getDerived().TransformType(E->getType());
7788 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007789 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007790
Douglas Gregora16548e2009-08-11 05:31:07 +00007791 if (!getDerived().AlwaysRebuild() &&
7792 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007793 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007794
Douglas Gregora16548e2009-08-11 05:31:07 +00007795 return getDerived().RebuildImplicitValueInitExpr(T);
7796}
Mike Stump11289f42009-09-09 15:08:12 +00007797
Douglas Gregora16548e2009-08-11 05:31:07 +00007798template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007799ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007800TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007801 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7802 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007803 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007804
John McCalldadc5752010-08-24 06:29:42 +00007805 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007806 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007807 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007808
Douglas Gregora16548e2009-08-11 05:31:07 +00007809 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007810 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007811 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007812 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007813
John McCallb268a282010-08-23 23:25:46 +00007814 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007815 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007816}
7817
7818template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007819ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007820TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007821 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007822 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007823 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7824 &ArgumentChanged))
7825 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007826
Douglas Gregora16548e2009-08-11 05:31:07 +00007827 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007828 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007829 E->getRParenLoc());
7830}
Mike Stump11289f42009-09-09 15:08:12 +00007831
Douglas Gregora16548e2009-08-11 05:31:07 +00007832/// \brief Transform an address-of-label expression.
7833///
7834/// By default, the transformation of an address-of-label expression always
7835/// rebuilds the expression, so that the label identifier can be resolved to
7836/// the corresponding label statement by semantic analysis.
7837template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007838ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007839TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007840 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7841 E->getLabel());
7842 if (!LD)
7843 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007844
Douglas Gregora16548e2009-08-11 05:31:07 +00007845 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007846 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007847}
Mike Stump11289f42009-09-09 15:08:12 +00007848
7849template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007850ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007851TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007852 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007853 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007854 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007855 if (SubStmt.isInvalid()) {
7856 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007857 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007858 }
Mike Stump11289f42009-09-09 15:08:12 +00007859
Douglas Gregora16548e2009-08-11 05:31:07 +00007860 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007861 SubStmt.get() == E->getSubStmt()) {
7862 // Calling this an 'error' is unintuitive, but it does the right thing.
7863 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007864 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007865 }
Mike Stump11289f42009-09-09 15:08:12 +00007866
7867 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007868 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007869 E->getRParenLoc());
7870}
Mike Stump11289f42009-09-09 15:08:12 +00007871
Douglas Gregora16548e2009-08-11 05:31:07 +00007872template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007873ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007874TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007875 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007876 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007877 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007878
John McCalldadc5752010-08-24 06:29:42 +00007879 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007880 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007881 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007882
John McCalldadc5752010-08-24 06:29:42 +00007883 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007884 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007885 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007886
Douglas Gregora16548e2009-08-11 05:31:07 +00007887 if (!getDerived().AlwaysRebuild() &&
7888 Cond.get() == E->getCond() &&
7889 LHS.get() == E->getLHS() &&
7890 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007891 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007892
Douglas Gregora16548e2009-08-11 05:31:07 +00007893 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007894 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007895 E->getRParenLoc());
7896}
Mike Stump11289f42009-09-09 15:08:12 +00007897
Douglas Gregora16548e2009-08-11 05:31:07 +00007898template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007899ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007900TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007901 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007902}
7903
7904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007905ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007906TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007907 switch (E->getOperator()) {
7908 case OO_New:
7909 case OO_Delete:
7910 case OO_Array_New:
7911 case OO_Array_Delete:
7912 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007913
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007914 case OO_Call: {
7915 // This is a call to an object's operator().
7916 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7917
7918 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007919 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007920 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007921 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007922
7923 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007924 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7925 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007926
7927 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007928 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007929 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007930 Args))
7931 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007932
John McCallb268a282010-08-23 23:25:46 +00007933 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007934 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007935 E->getLocEnd());
7936 }
7937
7938#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7939 case OO_##Name:
7940#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7941#include "clang/Basic/OperatorKinds.def"
7942 case OO_Subscript:
7943 // Handled below.
7944 break;
7945
7946 case OO_Conditional:
7947 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007948
7949 case OO_None:
7950 case NUM_OVERLOADED_OPERATORS:
7951 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007952 }
7953
John McCalldadc5752010-08-24 06:29:42 +00007954 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007955 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007956 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007957
Richard Smithdb2630f2012-10-21 03:28:35 +00007958 ExprResult First;
7959 if (E->getOperator() == OO_Amp)
7960 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7961 else
7962 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007963 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007964 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007965
John McCalldadc5752010-08-24 06:29:42 +00007966 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007967 if (E->getNumArgs() == 2) {
7968 Second = getDerived().TransformExpr(E->getArg(1));
7969 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007970 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007971 }
Mike Stump11289f42009-09-09 15:08:12 +00007972
Douglas Gregora16548e2009-08-11 05:31:07 +00007973 if (!getDerived().AlwaysRebuild() &&
7974 Callee.get() == E->getCallee() &&
7975 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007976 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007977 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007978
Lang Hames5de91cc2012-10-02 04:45:10 +00007979 Sema::FPContractStateRAII FPContractState(getSema());
7980 getSema().FPFeatures.fp_contract = E->isFPContractable();
7981
Douglas Gregora16548e2009-08-11 05:31:07 +00007982 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7983 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007984 Callee.get(),
7985 First.get(),
7986 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007987}
Mike Stump11289f42009-09-09 15:08:12 +00007988
Douglas Gregora16548e2009-08-11 05:31:07 +00007989template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007990ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007991TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7992 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007993}
Mike Stump11289f42009-09-09 15:08:12 +00007994
Douglas Gregora16548e2009-08-11 05:31:07 +00007995template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007996ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007997TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7998 // Transform the callee.
7999 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8000 if (Callee.isInvalid())
8001 return ExprError();
8002
8003 // Transform exec config.
8004 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8005 if (EC.isInvalid())
8006 return ExprError();
8007
8008 // Transform arguments.
8009 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008010 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008011 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008012 &ArgChanged))
8013 return ExprError();
8014
8015 if (!getDerived().AlwaysRebuild() &&
8016 Callee.get() == E->getCallee() &&
8017 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008018 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008019
8020 // FIXME: Wrong source location information for the '('.
8021 SourceLocation FakeLParenLoc
8022 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8023 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008024 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008025 E->getRParenLoc(), EC.get());
8026}
8027
8028template<typename Derived>
8029ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008030TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008031 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8032 if (!Type)
8033 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008034
John McCalldadc5752010-08-24 06:29:42 +00008035 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008036 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008037 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008038 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008039
Douglas Gregora16548e2009-08-11 05:31:07 +00008040 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008041 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008042 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008043 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008044 return getDerived().RebuildCXXNamedCastExpr(
8045 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8046 Type, E->getAngleBrackets().getEnd(),
8047 // FIXME. this should be '(' location
8048 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008049}
Mike Stump11289f42009-09-09 15:08:12 +00008050
Douglas Gregora16548e2009-08-11 05:31:07 +00008051template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008052ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008053TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8054 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008055}
Mike Stump11289f42009-09-09 15:08:12 +00008056
8057template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008058ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008059TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8060 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008061}
8062
Douglas Gregora16548e2009-08-11 05:31:07 +00008063template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008064ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008065TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008066 CXXReinterpretCastExpr *E) {
8067 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008068}
Mike Stump11289f42009-09-09 15:08:12 +00008069
Douglas Gregora16548e2009-08-11 05:31:07 +00008070template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008071ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008072TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8073 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008074}
Mike Stump11289f42009-09-09 15:08:12 +00008075
Douglas Gregora16548e2009-08-11 05:31:07 +00008076template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008077ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008078TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008079 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008080 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8081 if (!Type)
8082 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008083
John McCalldadc5752010-08-24 06:29:42 +00008084 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008085 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008086 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008087 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008088
Douglas Gregora16548e2009-08-11 05:31:07 +00008089 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008090 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008091 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008092 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008093
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008094 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008095 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008096 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008097 E->getRParenLoc());
8098}
Mike Stump11289f42009-09-09 15:08:12 +00008099
Douglas Gregora16548e2009-08-11 05:31:07 +00008100template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008101ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008102TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008103 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008104 TypeSourceInfo *TInfo
8105 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8106 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008107 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008108
Douglas Gregora16548e2009-08-11 05:31:07 +00008109 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008110 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008111 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008112
Douglas Gregor9da64192010-04-26 22:37:10 +00008113 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8114 E->getLocStart(),
8115 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008116 E->getLocEnd());
8117 }
Mike Stump11289f42009-09-09 15:08:12 +00008118
Eli Friedman456f0182012-01-20 01:26:23 +00008119 // We don't know whether the subexpression is potentially evaluated until
8120 // after we perform semantic analysis. We speculatively assume it is
8121 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008122 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008123 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8124 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008125
John McCalldadc5752010-08-24 06:29:42 +00008126 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008127 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008128 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008129
Douglas Gregora16548e2009-08-11 05:31:07 +00008130 if (!getDerived().AlwaysRebuild() &&
8131 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008132 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008133
Douglas Gregor9da64192010-04-26 22:37:10 +00008134 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8135 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008136 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008137 E->getLocEnd());
8138}
8139
8140template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008141ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008142TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8143 if (E->isTypeOperand()) {
8144 TypeSourceInfo *TInfo
8145 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8146 if (!TInfo)
8147 return ExprError();
8148
8149 if (!getDerived().AlwaysRebuild() &&
8150 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008151 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008152
Douglas Gregor69735112011-03-06 17:40:41 +00008153 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008154 E->getLocStart(),
8155 TInfo,
8156 E->getLocEnd());
8157 }
8158
Francois Pichet9f4f2072010-09-08 12:20:18 +00008159 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8160
8161 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8162 if (SubExpr.isInvalid())
8163 return ExprError();
8164
8165 if (!getDerived().AlwaysRebuild() &&
8166 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008167 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008168
8169 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8170 E->getLocStart(),
8171 SubExpr.get(),
8172 E->getLocEnd());
8173}
8174
8175template<typename Derived>
8176ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008177TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008178 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008179}
Mike Stump11289f42009-09-09 15:08:12 +00008180
Douglas Gregora16548e2009-08-11 05:31:07 +00008181template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008182ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008183TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008184 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008185 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008186}
Mike Stump11289f42009-09-09 15:08:12 +00008187
Douglas Gregora16548e2009-08-11 05:31:07 +00008188template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008189ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008190TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008191 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008192
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008193 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8194 // Make sure that we capture 'this'.
8195 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008196 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008197 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008198
Douglas Gregorb15af892010-01-07 23:12:05 +00008199 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008200}
Mike Stump11289f42009-09-09 15:08:12 +00008201
Douglas Gregora16548e2009-08-11 05:31:07 +00008202template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008203ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008204TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008205 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008206 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008207 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008208
Douglas Gregora16548e2009-08-11 05:31:07 +00008209 if (!getDerived().AlwaysRebuild() &&
8210 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008211 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008212
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008213 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8214 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008215}
Mike Stump11289f42009-09-09 15:08:12 +00008216
Douglas Gregora16548e2009-08-11 05:31:07 +00008217template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008218ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008219TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008220 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008221 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8222 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008223 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008224 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008225
Chandler Carruth794da4c2010-02-08 06:42:49 +00008226 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008227 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008228 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008229
Douglas Gregor033f6752009-12-23 23:03:06 +00008230 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008231}
Mike Stump11289f42009-09-09 15:08:12 +00008232
Douglas Gregora16548e2009-08-11 05:31:07 +00008233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008234ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008235TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8236 FieldDecl *Field
8237 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8238 E->getField()));
8239 if (!Field)
8240 return ExprError();
8241
8242 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008243 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008244
8245 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8246}
8247
8248template<typename Derived>
8249ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008250TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8251 CXXScalarValueInitExpr *E) {
8252 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8253 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008254 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008255
Douglas Gregora16548e2009-08-11 05:31:07 +00008256 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008257 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008258 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008259
Chad Rosier1dcde962012-08-08 18:46:20 +00008260 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008261 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008262 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008263}
Mike Stump11289f42009-09-09 15:08:12 +00008264
Douglas Gregora16548e2009-08-11 05:31:07 +00008265template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008266ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008267TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008268 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008269 TypeSourceInfo *AllocTypeInfo
8270 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8271 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008272 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008273
Douglas Gregora16548e2009-08-11 05:31:07 +00008274 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008275 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008276 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008277 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008278
Douglas Gregora16548e2009-08-11 05:31:07 +00008279 // Transform the placement arguments (if any).
8280 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008281 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008282 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008283 E->getNumPlacementArgs(), true,
8284 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008285 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008286
Sebastian Redl6047f072012-02-16 12:22:20 +00008287 // Transform the initializer (if any).
8288 Expr *OldInit = E->getInitializer();
8289 ExprResult NewInit;
8290 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008291 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008292 if (NewInit.isInvalid())
8293 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008294
Sebastian Redl6047f072012-02-16 12:22:20 +00008295 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008296 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008297 if (E->getOperatorNew()) {
8298 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008299 getDerived().TransformDecl(E->getLocStart(),
8300 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008301 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008302 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008303 }
8304
Craig Topperc3ec1492014-05-26 06:22:03 +00008305 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008306 if (E->getOperatorDelete()) {
8307 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008308 getDerived().TransformDecl(E->getLocStart(),
8309 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008310 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008311 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008312 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008313
Douglas Gregora16548e2009-08-11 05:31:07 +00008314 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008315 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008316 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008317 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008318 OperatorNew == E->getOperatorNew() &&
8319 OperatorDelete == E->getOperatorDelete() &&
8320 !ArgumentChanged) {
8321 // Mark any declarations we need as referenced.
8322 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008323 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008324 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008325 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008326 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008327
Sebastian Redl6047f072012-02-16 12:22:20 +00008328 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008329 QualType ElementType
8330 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8331 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8332 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8333 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008334 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008335 }
8336 }
8337 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008338
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008339 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008340 }
Mike Stump11289f42009-09-09 15:08:12 +00008341
Douglas Gregor0744ef62010-09-07 21:49:58 +00008342 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008343 if (!ArraySize.get()) {
8344 // If no array size was specified, but the new expression was
8345 // instantiated with an array type (e.g., "new T" where T is
8346 // instantiated with "int[4]"), extract the outer bound from the
8347 // array type as our array size. We do this with constant and
8348 // dependently-sized array types.
8349 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8350 if (!ArrayT) {
8351 // Do nothing
8352 } else if (const ConstantArrayType *ConsArrayT
8353 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008354 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8355 SemaRef.Context.getSizeType(),
8356 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008357 AllocType = ConsArrayT->getElementType();
8358 } else if (const DependentSizedArrayType *DepArrayT
8359 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8360 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008361 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008362 AllocType = DepArrayT->getElementType();
8363 }
8364 }
8365 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008366
Douglas Gregora16548e2009-08-11 05:31:07 +00008367 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8368 E->isGlobalNew(),
8369 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008370 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008371 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008372 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008373 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008374 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008375 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008376 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008377 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008378}
Mike Stump11289f42009-09-09 15:08:12 +00008379
Douglas Gregora16548e2009-08-11 05:31:07 +00008380template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008381ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008382TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008383 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008384 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008385 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008386
Douglas Gregord2d9da02010-02-26 00:38:10 +00008387 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008388 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008389 if (E->getOperatorDelete()) {
8390 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008391 getDerived().TransformDecl(E->getLocStart(),
8392 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008393 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008394 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008395 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008396
Douglas Gregora16548e2009-08-11 05:31:07 +00008397 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008398 Operand.get() == E->getArgument() &&
8399 OperatorDelete == E->getOperatorDelete()) {
8400 // Mark any declarations we need as referenced.
8401 // FIXME: instantiation-specific.
8402 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008403 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008404
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008405 if (!E->getArgument()->isTypeDependent()) {
8406 QualType Destroyed = SemaRef.Context.getBaseElementType(
8407 E->getDestroyedType());
8408 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8409 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008410 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008411 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008412 }
8413 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008414
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008415 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008416 }
Mike Stump11289f42009-09-09 15:08:12 +00008417
Douglas Gregora16548e2009-08-11 05:31:07 +00008418 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8419 E->isGlobalDelete(),
8420 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008421 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008422}
Mike Stump11289f42009-09-09 15:08:12 +00008423
Douglas Gregora16548e2009-08-11 05:31:07 +00008424template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008425ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008426TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008427 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008428 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008429 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008430 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008431
John McCallba7bf592010-08-24 05:47:05 +00008432 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008433 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008434 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008435 E->getOperatorLoc(),
8436 E->isArrow()? tok::arrow : tok::period,
8437 ObjectTypePtr,
8438 MayBePseudoDestructor);
8439 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008440 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008441
John McCallba7bf592010-08-24 05:47:05 +00008442 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008443 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8444 if (QualifierLoc) {
8445 QualifierLoc
8446 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8447 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008448 return ExprError();
8449 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008450 CXXScopeSpec SS;
8451 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008452
Douglas Gregor678f90d2010-02-25 01:56:36 +00008453 PseudoDestructorTypeStorage Destroyed;
8454 if (E->getDestroyedTypeInfo()) {
8455 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008456 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008457 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008458 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008459 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008460 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008461 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008462 // We aren't likely to be able to resolve the identifier down to a type
8463 // now anyway, so just retain the identifier.
8464 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8465 E->getDestroyedTypeLoc());
8466 } else {
8467 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008468 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008469 *E->getDestroyedTypeIdentifier(),
8470 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008471 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008472 SS, ObjectTypePtr,
8473 false);
8474 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008475 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008476
Douglas Gregor678f90d2010-02-25 01:56:36 +00008477 Destroyed
8478 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8479 E->getDestroyedTypeLoc());
8480 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008481
Craig Topperc3ec1492014-05-26 06:22:03 +00008482 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008483 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008484 CXXScopeSpec EmptySS;
8485 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008486 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008487 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008488 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008489 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008490
John McCallb268a282010-08-23 23:25:46 +00008491 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008492 E->getOperatorLoc(),
8493 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008494 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008495 ScopeTypeInfo,
8496 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008497 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008498 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008499}
Mike Stump11289f42009-09-09 15:08:12 +00008500
Douglas Gregorad8a3362009-09-04 17:36:40 +00008501template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008502ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008503TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008504 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008505 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8506 Sema::LookupOrdinaryName);
8507
8508 // Transform all the decls.
8509 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8510 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008511 NamedDecl *InstD = static_cast<NamedDecl*>(
8512 getDerived().TransformDecl(Old->getNameLoc(),
8513 *I));
John McCall84d87672009-12-10 09:41:52 +00008514 if (!InstD) {
8515 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8516 // This can happen because of dependent hiding.
8517 if (isa<UsingShadowDecl>(*I))
8518 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008519 else {
8520 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008521 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008522 }
John McCall84d87672009-12-10 09:41:52 +00008523 }
John McCalle66edc12009-11-24 19:00:30 +00008524
8525 // Expand using declarations.
8526 if (isa<UsingDecl>(InstD)) {
8527 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008528 for (auto *I : UD->shadows())
8529 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008530 continue;
8531 }
8532
8533 R.addDecl(InstD);
8534 }
8535
8536 // Resolve a kind, but don't do any further analysis. If it's
8537 // ambiguous, the callee needs to deal with it.
8538 R.resolveKind();
8539
8540 // Rebuild the nested-name qualifier, if present.
8541 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008542 if (Old->getQualifierLoc()) {
8543 NestedNameSpecifierLoc QualifierLoc
8544 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8545 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008546 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008547
Douglas Gregor0da1d432011-02-28 20:01:57 +00008548 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008549 }
8550
Douglas Gregor9262f472010-04-27 18:19:34 +00008551 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008552 CXXRecordDecl *NamingClass
8553 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8554 Old->getNameLoc(),
8555 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008556 if (!NamingClass) {
8557 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008558 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008559 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008560
Douglas Gregorda7be082010-04-27 16:10:10 +00008561 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008562 }
8563
Abramo Bagnara7945c982012-01-27 09:46:47 +00008564 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8565
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008566 // If we have neither explicit template arguments, nor the template keyword,
8567 // it's a normal declaration name.
8568 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008569 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8570
8571 // If we have template arguments, rebuild them, then rebuild the
8572 // templateid expression.
8573 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008574 if (Old->hasExplicitTemplateArgs() &&
8575 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008576 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008577 TransArgs)) {
8578 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008579 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008580 }
John McCalle66edc12009-11-24 19:00:30 +00008581
Abramo Bagnara7945c982012-01-27 09:46:47 +00008582 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008583 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008584}
Mike Stump11289f42009-09-09 15:08:12 +00008585
Douglas Gregora16548e2009-08-11 05:31:07 +00008586template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008587ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008588TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8589 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008590 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008591 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8592 TypeSourceInfo *From = E->getArg(I);
8593 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008594 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008595 TypeLocBuilder TLB;
8596 TLB.reserve(FromTL.getFullDataSize());
8597 QualType To = getDerived().TransformType(TLB, FromTL);
8598 if (To.isNull())
8599 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008600
Douglas Gregor29c42f22012-02-24 07:38:34 +00008601 if (To == From->getType())
8602 Args.push_back(From);
8603 else {
8604 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8605 ArgChanged = true;
8606 }
8607 continue;
8608 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008609
Douglas Gregor29c42f22012-02-24 07:38:34 +00008610 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008611
Douglas Gregor29c42f22012-02-24 07:38:34 +00008612 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008613 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008614 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8615 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8616 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008617
Douglas Gregor29c42f22012-02-24 07:38:34 +00008618 // Determine whether the set of unexpanded parameter packs can and should
8619 // be expanded.
8620 bool Expand = true;
8621 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008622 Optional<unsigned> OrigNumExpansions =
8623 ExpansionTL.getTypePtr()->getNumExpansions();
8624 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008625 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8626 PatternTL.getSourceRange(),
8627 Unexpanded,
8628 Expand, RetainExpansion,
8629 NumExpansions))
8630 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008631
Douglas Gregor29c42f22012-02-24 07:38:34 +00008632 if (!Expand) {
8633 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008634 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008635 // expansion.
8636 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008637
Douglas Gregor29c42f22012-02-24 07:38:34 +00008638 TypeLocBuilder TLB;
8639 TLB.reserve(From->getTypeLoc().getFullDataSize());
8640
8641 QualType To = getDerived().TransformType(TLB, PatternTL);
8642 if (To.isNull())
8643 return ExprError();
8644
Chad Rosier1dcde962012-08-08 18:46:20 +00008645 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008646 PatternTL.getSourceRange(),
8647 ExpansionTL.getEllipsisLoc(),
8648 NumExpansions);
8649 if (To.isNull())
8650 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008651
Douglas Gregor29c42f22012-02-24 07:38:34 +00008652 PackExpansionTypeLoc ToExpansionTL
8653 = TLB.push<PackExpansionTypeLoc>(To);
8654 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8655 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8656 continue;
8657 }
8658
8659 // Expand the pack expansion by substituting for each argument in the
8660 // pack(s).
8661 for (unsigned I = 0; I != *NumExpansions; ++I) {
8662 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8663 TypeLocBuilder TLB;
8664 TLB.reserve(PatternTL.getFullDataSize());
8665 QualType To = getDerived().TransformType(TLB, PatternTL);
8666 if (To.isNull())
8667 return ExprError();
8668
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008669 if (To->containsUnexpandedParameterPack()) {
8670 To = getDerived().RebuildPackExpansionType(To,
8671 PatternTL.getSourceRange(),
8672 ExpansionTL.getEllipsisLoc(),
8673 NumExpansions);
8674 if (To.isNull())
8675 return ExprError();
8676
8677 PackExpansionTypeLoc ToExpansionTL
8678 = TLB.push<PackExpansionTypeLoc>(To);
8679 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8680 }
8681
Douglas Gregor29c42f22012-02-24 07:38:34 +00008682 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8683 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008684
Douglas Gregor29c42f22012-02-24 07:38:34 +00008685 if (!RetainExpansion)
8686 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008687
Douglas Gregor29c42f22012-02-24 07:38:34 +00008688 // If we're supposed to retain a pack expansion, do so by temporarily
8689 // forgetting the partially-substituted parameter pack.
8690 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8691
8692 TypeLocBuilder TLB;
8693 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008694
Douglas Gregor29c42f22012-02-24 07:38:34 +00008695 QualType To = getDerived().TransformType(TLB, PatternTL);
8696 if (To.isNull())
8697 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008698
8699 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008700 PatternTL.getSourceRange(),
8701 ExpansionTL.getEllipsisLoc(),
8702 NumExpansions);
8703 if (To.isNull())
8704 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008705
Douglas Gregor29c42f22012-02-24 07:38:34 +00008706 PackExpansionTypeLoc ToExpansionTL
8707 = TLB.push<PackExpansionTypeLoc>(To);
8708 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8709 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8710 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008711
Douglas Gregor29c42f22012-02-24 07:38:34 +00008712 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008713 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008714
8715 return getDerived().RebuildTypeTrait(E->getTrait(),
8716 E->getLocStart(),
8717 Args,
8718 E->getLocEnd());
8719}
8720
8721template<typename Derived>
8722ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008723TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8724 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8725 if (!T)
8726 return ExprError();
8727
8728 if (!getDerived().AlwaysRebuild() &&
8729 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008730 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008731
8732 ExprResult SubExpr;
8733 {
8734 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8735 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8736 if (SubExpr.isInvalid())
8737 return ExprError();
8738
8739 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008740 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008741 }
8742
8743 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8744 E->getLocStart(),
8745 T,
8746 SubExpr.get(),
8747 E->getLocEnd());
8748}
8749
8750template<typename Derived>
8751ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008752TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8753 ExprResult SubExpr;
8754 {
8755 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8756 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8757 if (SubExpr.isInvalid())
8758 return ExprError();
8759
8760 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008761 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008762 }
8763
8764 return getDerived().RebuildExpressionTrait(
8765 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8766}
8767
Reid Kleckner32506ed2014-06-12 23:03:48 +00008768template <typename Derived>
8769ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8770 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8771 TypeSourceInfo **RecoveryTSI) {
8772 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8773 DRE, AddrTaken, RecoveryTSI);
8774
8775 // Propagate both errors and recovered types, which return ExprEmpty.
8776 if (!NewDRE.isUsable())
8777 return NewDRE;
8778
8779 // We got an expr, wrap it up in parens.
8780 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8781 return PE;
8782 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8783 PE->getRParen());
8784}
8785
8786template <typename Derived>
8787ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8788 DependentScopeDeclRefExpr *E) {
8789 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8790 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008791}
8792
8793template<typename Derived>
8794ExprResult
8795TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8796 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00008797 bool IsAddressOfOperand,
8798 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008799 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008800 NestedNameSpecifierLoc QualifierLoc
8801 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8802 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008803 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008804 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008805
John McCall31f82722010-11-12 08:19:04 +00008806 // TODO: If this is a conversion-function-id, verify that the
8807 // destination type name (if present) resolves the same way after
8808 // instantiation as it did in the local scope.
8809
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008810 DeclarationNameInfo NameInfo
8811 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8812 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008813 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008814
John McCalle66edc12009-11-24 19:00:30 +00008815 if (!E->hasExplicitTemplateArgs()) {
8816 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008817 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008818 // Note: it is sufficient to compare the Name component of NameInfo:
8819 // if name has not changed, DNLoc has not changed either.
8820 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008821 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008822
Reid Kleckner32506ed2014-06-12 23:03:48 +00008823 return getDerived().RebuildDependentScopeDeclRefExpr(
8824 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
8825 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00008826 }
John McCall6b51f282009-11-23 01:53:49 +00008827
8828 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008829 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8830 E->getNumTemplateArgs(),
8831 TransArgs))
8832 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008833
Reid Kleckner32506ed2014-06-12 23:03:48 +00008834 return getDerived().RebuildDependentScopeDeclRefExpr(
8835 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
8836 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00008837}
8838
8839template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008840ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008841TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008842 // CXXConstructExprs other than for list-initialization and
8843 // CXXTemporaryObjectExpr are always implicit, so when we have
8844 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008845 if ((E->getNumArgs() == 1 ||
8846 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008847 (!getDerived().DropCallArgument(E->getArg(0))) &&
8848 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008849 return getDerived().TransformExpr(E->getArg(0));
8850
Douglas Gregora16548e2009-08-11 05:31:07 +00008851 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8852
8853 QualType T = getDerived().TransformType(E->getType());
8854 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008855 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008856
8857 CXXConstructorDecl *Constructor
8858 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008859 getDerived().TransformDecl(E->getLocStart(),
8860 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008861 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008862 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008863
Douglas Gregora16548e2009-08-11 05:31:07 +00008864 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008865 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008866 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008867 &ArgumentChanged))
8868 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008869
Douglas Gregora16548e2009-08-11 05:31:07 +00008870 if (!getDerived().AlwaysRebuild() &&
8871 T == E->getType() &&
8872 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008873 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008874 // Mark the constructor as referenced.
8875 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008876 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008877 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00008878 }
Mike Stump11289f42009-09-09 15:08:12 +00008879
Douglas Gregordb121ba2009-12-14 16:27:04 +00008880 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8881 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008882 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008883 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008884 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00008885 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008886 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008887 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008888 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008889}
Mike Stump11289f42009-09-09 15:08:12 +00008890
Douglas Gregora16548e2009-08-11 05:31:07 +00008891/// \brief Transform a C++ temporary-binding expression.
8892///
Douglas Gregor363b1512009-12-24 18:51:59 +00008893/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8894/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008895template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008896ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008897TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008898 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008899}
Mike Stump11289f42009-09-09 15:08:12 +00008900
John McCall5d413782010-12-06 08:20:24 +00008901/// \brief Transform a C++ expression that contains cleanups that should
8902/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008903///
John McCall5d413782010-12-06 08:20:24 +00008904/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008905/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008906template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008907ExprResult
John McCall5d413782010-12-06 08:20:24 +00008908TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008909 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008910}
Mike Stump11289f42009-09-09 15:08:12 +00008911
Douglas Gregora16548e2009-08-11 05:31:07 +00008912template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008913ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008914TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008915 CXXTemporaryObjectExpr *E) {
8916 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8917 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008918 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008919
Douglas Gregora16548e2009-08-11 05:31:07 +00008920 CXXConstructorDecl *Constructor
8921 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008922 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008923 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008924 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008925 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008926
Douglas Gregora16548e2009-08-11 05:31:07 +00008927 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008928 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008929 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008930 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008931 &ArgumentChanged))
8932 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008933
Douglas Gregora16548e2009-08-11 05:31:07 +00008934 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008935 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008936 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008937 !ArgumentChanged) {
8938 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008939 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008940 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008941 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008942
Richard Smithd59b8322012-12-19 01:39:02 +00008943 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008944 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8945 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008946 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008947 E->getLocEnd());
8948}
Mike Stump11289f42009-09-09 15:08:12 +00008949
Douglas Gregora16548e2009-08-11 05:31:07 +00008950template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008951ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008952TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008953
8954 // Transform any init-capture expressions before entering the scope of the
8955 // lambda body, because they are not semantically within that scope.
8956 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8957 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8958 E->explicit_capture_begin());
8959
8960 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8961 CEnd = E->capture_end();
8962 C != CEnd; ++C) {
8963 if (!C->isInitCapture())
8964 continue;
8965 EnterExpressionEvaluationContext EEEC(getSema(),
8966 Sema::PotentiallyEvaluated);
8967 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8968 C->getCapturedVar()->getInit(),
8969 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8970
8971 if (NewExprInitResult.isInvalid())
8972 return ExprError();
8973 Expr *NewExprInit = NewExprInitResult.get();
8974
8975 VarDecl *OldVD = C->getCapturedVar();
8976 QualType NewInitCaptureType =
8977 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8978 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8979 NewExprInit);
8980 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008981 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8982 std::make_pair(NewExprInitResult, NewInitCaptureType);
8983
8984 }
8985
Faisal Vali524ca282013-11-12 01:40:44 +00008986 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008987 // Transform the template parameters, and add them to the current
8988 // instantiation scope. The null case is handled correctly.
8989 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8990 E->getTemplateParameterList());
8991
8992 // Check to see if the TypeSourceInfo of the call operator needs to
8993 // be transformed, and if so do the transformation in the
8994 // CurrentInstantiationScope.
8995
8996 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8997 FunctionProtoTypeLoc OldCallOpFPTL =
8998 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Craig Topperc3ec1492014-05-26 06:22:03 +00008999 TypeSourceInfo *NewCallOpTSI = nullptr;
9000
Faisal Vali2cba1332013-10-23 06:44:28 +00009001 const bool CallOpWasAlreadyTransformed =
9002 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
9003
9004 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
9005 if (CallOpWasAlreadyTransformed)
9006 NewCallOpTSI = OldCallOpTSI;
9007 else {
9008 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
9009 // The transformation MUST be done in the CurrentInstantiationScope since
9010 // it introduces a mapping of the original to the newly created
9011 // transformed parameters.
9012
9013 TypeLocBuilder NewCallOpTLBuilder;
NAKAMURA Takumi23224152014-10-17 12:48:37 +00009014 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
9015 OldCallOpFPTL,
9016 nullptr, 0);
Faisal Vali2cba1332013-10-23 06:44:28 +00009017 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9018 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009019 }
Faisal Vali2cba1332013-10-23 06:44:28 +00009020 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
9021 // the vector below - this will be used to synthesize the
9022 // NewCallOperator. Additionally, add the parameters of the untransformed
9023 // lambda call operator to the CurrentInstantiationScope.
9024 SmallVector<ParmVarDecl *, 4> Params;
9025 {
9026 FunctionProtoTypeLoc NewCallOpFPTL =
9027 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
9028 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00009029 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00009030
9031 for (unsigned I = 0; I < NewNumArgs; ++I) {
9032 // If this call operator's type does not require transformation,
9033 // the parameters do not get added to the current instantiation scope,
9034 // - so ADD them! This allows the following to compile when the enclosing
9035 // template is specialized and the entire lambda expression has to be
9036 // transformed.
9037 // template<class T> void foo(T t) {
9038 // auto L = [](auto a) {
9039 // auto M = [](char b) { <-- note: non-generic lambda
9040 // auto N = [](auto c) {
9041 // int x = sizeof(a);
9042 // x = sizeof(b); <-- specifically this line
9043 // x = sizeof(c);
9044 // };
9045 // };
9046 // };
9047 // }
9048 // foo('a')
9049 if (CallOpWasAlreadyTransformed)
9050 getDerived().transformedLocalDecl(NewParamDeclArray[I],
9051 NewParamDeclArray[I]);
9052 // Add to Params array, so these parameters can be used to create
9053 // the newly transformed call operator.
9054 Params.push_back(NewParamDeclArray[I]);
9055 }
9056 }
9057
9058 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009059 return ExprError();
9060
Eli Friedmand564afb2012-09-19 01:18:11 +00009061 // Create the local class that will describe the lambda.
9062 CXXRecordDecl *Class
9063 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009064 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009065 /*KnownDependent=*/false,
9066 E->getCaptureDefault());
9067
Eli Friedmand564afb2012-09-19 01:18:11 +00009068 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9069
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009070 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00009071 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009072 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009073 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00009074 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00009075 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00009076 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009077
Faisal Vali2cba1332013-10-23 06:44:28 +00009078 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
9079
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009080 return getDerived().TransformLambdaScope(E, NewCallOperator,
9081 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00009082}
9083
9084template<typename Derived>
9085ExprResult
9086TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009087 CXXMethodDecl *CallOperator,
9088 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00009089 bool Invalid = false;
9090
Douglas Gregorb4328232012-02-14 00:00:48 +00009091 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009092 Sema::ContextRAII SavedContext(getSema(), CallOperator,
9093 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009094
Faisal Vali2b391ab2013-09-26 19:54:12 +00009095 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009096 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00009097 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009098 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00009099 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009100 E->hasExplicitParameters(),
9101 E->hasExplicitResultType(),
9102 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00009103
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009104 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009105 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009106 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009107 CEnd = E->capture_end();
9108 C != CEnd; ++C) {
9109 // When we hit the first implicit capture, tell Sema that we've finished
9110 // the list of explicit captures.
9111 if (!FinishedExplicitCaptures && C->isImplicit()) {
9112 getSema().finishLambdaExplicitCaptures(LSI);
9113 FinishedExplicitCaptures = true;
9114 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009115
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009116 // Capturing 'this' is trivial.
9117 if (C->capturesThis()) {
9118 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9119 continue;
9120 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009121 // Captured expression will be recaptured during captured variables
9122 // rebuilding.
9123 if (C->capturesVLAType())
9124 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009125
Richard Smithba71c082013-05-16 06:20:58 +00009126 // Rebuild init-captures, including the implied field declaration.
9127 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009128
9129 InitCaptureInfoTy InitExprTypePair =
9130 InitCaptureExprsAndTypes[C - E->capture_begin()];
9131 ExprResult Init = InitExprTypePair.first;
9132 QualType InitQualType = InitExprTypePair.second;
9133 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009134 Invalid = true;
9135 continue;
9136 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009137 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009138 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9139 OldVD->getLocation(), InitExprTypePair.second,
9140 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009141 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009142 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009143 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009144 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009145 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009146 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009147 continue;
9148 }
9149
9150 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9151
Douglas Gregor3e308b12012-02-14 19:27:52 +00009152 // Determine the capture kind for Sema.
9153 Sema::TryCaptureKind Kind
9154 = C->isImplicit()? Sema::TryCapture_Implicit
9155 : C->getCaptureKind() == LCK_ByCopy
9156 ? Sema::TryCapture_ExplicitByVal
9157 : Sema::TryCapture_ExplicitByRef;
9158 SourceLocation EllipsisLoc;
9159 if (C->isPackExpansion()) {
9160 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9161 bool ShouldExpand = false;
9162 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009163 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009164 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9165 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009166 Unexpanded,
9167 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009168 NumExpansions)) {
9169 Invalid = true;
9170 continue;
9171 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009172
Douglas Gregor3e308b12012-02-14 19:27:52 +00009173 if (ShouldExpand) {
9174 // The transform has determined that we should perform an expansion;
9175 // transform and capture each of the arguments.
9176 // expansion of the pattern. Do so.
9177 VarDecl *Pack = C->getCapturedVar();
9178 for (unsigned I = 0; I != *NumExpansions; ++I) {
9179 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9180 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009181 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009182 Pack));
9183 if (!CapturedVar) {
9184 Invalid = true;
9185 continue;
9186 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009187
Douglas Gregor3e308b12012-02-14 19:27:52 +00009188 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009189 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9190 }
Richard Smith9467be42014-06-06 17:33:35 +00009191
9192 // FIXME: Retain a pack expansion if RetainExpansion is true.
9193
Douglas Gregor3e308b12012-02-14 19:27:52 +00009194 continue;
9195 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009196
Douglas Gregor3e308b12012-02-14 19:27:52 +00009197 EllipsisLoc = C->getEllipsisLoc();
9198 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009199
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009200 // Transform the captured variable.
9201 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009202 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009203 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009204 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009205 Invalid = true;
9206 continue;
9207 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009208
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009209 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00009210 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009211 }
9212 if (!FinishedExplicitCaptures)
9213 getSema().finishLambdaExplicitCaptures(LSI);
9214
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009215
9216 // Enter a new evaluation context to insulate the lambda from any
9217 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009218 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009219
9220 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009221 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009222 /*IsInstantiation=*/true);
9223 return ExprError();
9224 }
9225
9226 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00009227 StmtResult Body = getDerived().TransformStmt(E->getBody());
9228 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009229 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009230 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009231 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009232 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009233
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009234 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009235 /*CurScope=*/nullptr,
9236 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00009237}
9238
9239template<typename Derived>
9240ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009241TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009242 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009243 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9244 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009245 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009246
Douglas Gregora16548e2009-08-11 05:31:07 +00009247 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009248 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009249 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009250 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009251 &ArgumentChanged))
9252 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009253
Douglas Gregora16548e2009-08-11 05:31:07 +00009254 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009255 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009256 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009257 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009258
Douglas Gregora16548e2009-08-11 05:31:07 +00009259 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009260 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009261 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009262 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009263 E->getRParenLoc());
9264}
Mike Stump11289f42009-09-09 15:08:12 +00009265
Douglas Gregora16548e2009-08-11 05:31:07 +00009266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009267ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009268TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009269 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009270 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009271 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009272 Expr *OldBase;
9273 QualType BaseType;
9274 QualType ObjectType;
9275 if (!E->isImplicitAccess()) {
9276 OldBase = E->getBase();
9277 Base = getDerived().TransformExpr(OldBase);
9278 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009279 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009280
John McCall2d74de92009-12-01 22:10:20 +00009281 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009282 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009283 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009284 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009285 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009286 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009287 ObjectTy,
9288 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009289 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009290 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009291
John McCallba7bf592010-08-24 05:47:05 +00009292 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009293 BaseType = ((Expr*) Base.get())->getType();
9294 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009295 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009296 BaseType = getDerived().TransformType(E->getBaseType());
9297 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9298 }
Mike Stump11289f42009-09-09 15:08:12 +00009299
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009300 // Transform the first part of the nested-name-specifier that qualifies
9301 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009302 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009303 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009304 E->getFirstQualifierFoundInScope(),
9305 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009306
Douglas Gregore16af532011-02-28 18:50:33 +00009307 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009308 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009309 QualifierLoc
9310 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9311 ObjectType,
9312 FirstQualifierInScope);
9313 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009314 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009315 }
Mike Stump11289f42009-09-09 15:08:12 +00009316
Abramo Bagnara7945c982012-01-27 09:46:47 +00009317 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9318
John McCall31f82722010-11-12 08:19:04 +00009319 // TODO: If this is a conversion-function-id, verify that the
9320 // destination type name (if present) resolves the same way after
9321 // instantiation as it did in the local scope.
9322
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009323 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009324 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009325 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009326 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009327
John McCall2d74de92009-12-01 22:10:20 +00009328 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009329 // This is a reference to a member without an explicitly-specified
9330 // template argument list. Optimize for this common case.
9331 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009332 Base.get() == OldBase &&
9333 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009334 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009335 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009336 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009337 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009338
John McCallb268a282010-08-23 23:25:46 +00009339 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009340 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009341 E->isArrow(),
9342 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009343 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009344 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009345 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009346 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009347 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009348 }
9349
John McCall6b51f282009-11-23 01:53:49 +00009350 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009351 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9352 E->getNumTemplateArgs(),
9353 TransArgs))
9354 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009355
John McCallb268a282010-08-23 23:25:46 +00009356 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009357 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009358 E->isArrow(),
9359 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009360 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009361 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009362 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009363 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009364 &TransArgs);
9365}
9366
9367template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009368ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009369TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009370 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009371 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009372 QualType BaseType;
9373 if (!Old->isImplicitAccess()) {
9374 Base = getDerived().TransformExpr(Old->getBase());
9375 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009376 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009377 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009378 Old->isArrow());
9379 if (Base.isInvalid())
9380 return ExprError();
9381 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009382 } else {
9383 BaseType = getDerived().TransformType(Old->getBaseType());
9384 }
John McCall10eae182009-11-30 22:42:35 +00009385
Douglas Gregor0da1d432011-02-28 20:01:57 +00009386 NestedNameSpecifierLoc QualifierLoc;
9387 if (Old->getQualifierLoc()) {
9388 QualifierLoc
9389 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9390 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009391 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009392 }
9393
Abramo Bagnara7945c982012-01-27 09:46:47 +00009394 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9395
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009396 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009397 Sema::LookupOrdinaryName);
9398
9399 // Transform all the decls.
9400 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9401 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009402 NamedDecl *InstD = static_cast<NamedDecl*>(
9403 getDerived().TransformDecl(Old->getMemberLoc(),
9404 *I));
John McCall84d87672009-12-10 09:41:52 +00009405 if (!InstD) {
9406 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9407 // This can happen because of dependent hiding.
9408 if (isa<UsingShadowDecl>(*I))
9409 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009410 else {
9411 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009412 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009413 }
John McCall84d87672009-12-10 09:41:52 +00009414 }
John McCall10eae182009-11-30 22:42:35 +00009415
9416 // Expand using declarations.
9417 if (isa<UsingDecl>(InstD)) {
9418 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009419 for (auto *I : UD->shadows())
9420 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009421 continue;
9422 }
9423
9424 R.addDecl(InstD);
9425 }
9426
9427 R.resolveKind();
9428
Douglas Gregor9262f472010-04-27 18:19:34 +00009429 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009430 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009431 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009432 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009433 Old->getMemberLoc(),
9434 Old->getNamingClass()));
9435 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009436 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009437
Douglas Gregorda7be082010-04-27 16:10:10 +00009438 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009439 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009440
John McCall10eae182009-11-30 22:42:35 +00009441 TemplateArgumentListInfo TransArgs;
9442 if (Old->hasExplicitTemplateArgs()) {
9443 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9444 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009445 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9446 Old->getNumTemplateArgs(),
9447 TransArgs))
9448 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009449 }
John McCall38836f02010-01-15 08:34:02 +00009450
9451 // FIXME: to do this check properly, we will need to preserve the
9452 // first-qualifier-in-scope here, just in case we had a dependent
9453 // base (and therefore couldn't do the check) and a
9454 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009455 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009456
John McCallb268a282010-08-23 23:25:46 +00009457 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009458 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009459 Old->getOperatorLoc(),
9460 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009461 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009462 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009463 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009464 R,
9465 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009466 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009467}
9468
9469template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009470ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009471TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009472 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009473 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9474 if (SubExpr.isInvalid())
9475 return ExprError();
9476
9477 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009478 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009479
9480 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9481}
9482
9483template<typename Derived>
9484ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009485TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009486 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9487 if (Pattern.isInvalid())
9488 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009489
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009490 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009491 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009492
Douglas Gregorb8840002011-01-14 21:20:45 +00009493 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9494 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009495}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009496
9497template<typename Derived>
9498ExprResult
9499TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9500 // If E is not value-dependent, then nothing will change when we transform it.
9501 // Note: This is an instantiation-centric view.
9502 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009503 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009504
9505 // Note: None of the implementations of TryExpandParameterPacks can ever
9506 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009507 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009508 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9509 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009510 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009511 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009512 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009513 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009514 ShouldExpand, RetainExpansion,
9515 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009516 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009517
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009518 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009519 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009520
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009521 NamedDecl *Pack = E->getPack();
9522 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009523 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009524 Pack));
9525 if (!Pack)
9526 return ExprError();
9527 }
9528
Chad Rosier1dcde962012-08-08 18:46:20 +00009529
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009530 // We now know the length of the parameter pack, so build a new expression
9531 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009532 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9533 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009534 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009535}
9536
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009537template<typename Derived>
9538ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009539TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9540 SubstNonTypeTemplateParmPackExpr *E) {
9541 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009542 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009543}
9544
9545template<typename Derived>
9546ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009547TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9548 SubstNonTypeTemplateParmExpr *E) {
9549 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009550 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009551}
9552
9553template<typename Derived>
9554ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009555TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9556 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009557 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009558}
9559
9560template<typename Derived>
9561ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009562TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9563 MaterializeTemporaryExpr *E) {
9564 return getDerived().TransformExpr(E->GetTemporaryExpr());
9565}
Chad Rosier1dcde962012-08-08 18:46:20 +00009566
Douglas Gregorfe314812011-06-21 17:03:29 +00009567template<typename Derived>
9568ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009569TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9570 CXXStdInitializerListExpr *E) {
9571 return getDerived().TransformExpr(E->getSubExpr());
9572}
9573
9574template<typename Derived>
9575ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009576TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009577 return SemaRef.MaybeBindToTemporary(E);
9578}
9579
9580template<typename Derived>
9581ExprResult
9582TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009583 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009584}
9585
9586template<typename Derived>
9587ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009588TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9589 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9590 if (SubExpr.isInvalid())
9591 return ExprError();
9592
9593 if (!getDerived().AlwaysRebuild() &&
9594 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009595 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009596
9597 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009598}
9599
9600template<typename Derived>
9601ExprResult
9602TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9603 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009604 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009605 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009606 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009607 /*IsCall=*/false, Elements, &ArgChanged))
9608 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009609
Ted Kremeneke65b0862012-03-06 20:05:56 +00009610 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9611 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009612
Ted Kremeneke65b0862012-03-06 20:05:56 +00009613 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9614 Elements.data(),
9615 Elements.size());
9616}
9617
9618template<typename Derived>
9619ExprResult
9620TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009621 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009622 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009623 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009624 bool ArgChanged = false;
9625 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9626 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009627
Ted Kremeneke65b0862012-03-06 20:05:56 +00009628 if (OrigElement.isPackExpansion()) {
9629 // This key/value element is a pack expansion.
9630 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9631 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9632 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9633 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9634
9635 // Determine whether the set of unexpanded parameter packs can
9636 // and should be expanded.
9637 bool Expand = true;
9638 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009639 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9640 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009641 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9642 OrigElement.Value->getLocEnd());
9643 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9644 PatternRange,
9645 Unexpanded,
9646 Expand, RetainExpansion,
9647 NumExpansions))
9648 return ExprError();
9649
9650 if (!Expand) {
9651 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009652 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009653 // expansion.
9654 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9655 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9656 if (Key.isInvalid())
9657 return ExprError();
9658
9659 if (Key.get() != OrigElement.Key)
9660 ArgChanged = true;
9661
9662 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9663 if (Value.isInvalid())
9664 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009665
Ted Kremeneke65b0862012-03-06 20:05:56 +00009666 if (Value.get() != OrigElement.Value)
9667 ArgChanged = true;
9668
Chad Rosier1dcde962012-08-08 18:46:20 +00009669 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009670 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9671 };
9672 Elements.push_back(Expansion);
9673 continue;
9674 }
9675
9676 // Record right away that the argument was changed. This needs
9677 // to happen even if the array expands to nothing.
9678 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009679
Ted Kremeneke65b0862012-03-06 20:05:56 +00009680 // The transform has determined that we should perform an elementwise
9681 // expansion of the pattern. Do so.
9682 for (unsigned I = 0; I != *NumExpansions; ++I) {
9683 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9684 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9685 if (Key.isInvalid())
9686 return ExprError();
9687
9688 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9689 if (Value.isInvalid())
9690 return ExprError();
9691
Chad Rosier1dcde962012-08-08 18:46:20 +00009692 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009693 Key.get(), Value.get(), SourceLocation(), NumExpansions
9694 };
9695
9696 // If any unexpanded parameter packs remain, we still have a
9697 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +00009698 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +00009699 if (Key.get()->containsUnexpandedParameterPack() ||
9700 Value.get()->containsUnexpandedParameterPack())
9701 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009702
Ted Kremeneke65b0862012-03-06 20:05:56 +00009703 Elements.push_back(Element);
9704 }
9705
Richard Smith9467be42014-06-06 17:33:35 +00009706 // FIXME: Retain a pack expansion if RetainExpansion is true.
9707
Ted Kremeneke65b0862012-03-06 20:05:56 +00009708 // We've finished with this pack expansion.
9709 continue;
9710 }
9711
9712 // Transform and check key.
9713 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9714 if (Key.isInvalid())
9715 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009716
Ted Kremeneke65b0862012-03-06 20:05:56 +00009717 if (Key.get() != OrigElement.Key)
9718 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009719
Ted Kremeneke65b0862012-03-06 20:05:56 +00009720 // Transform and check value.
9721 ExprResult Value
9722 = getDerived().TransformExpr(OrigElement.Value);
9723 if (Value.isInvalid())
9724 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009725
Ted Kremeneke65b0862012-03-06 20:05:56 +00009726 if (Value.get() != OrigElement.Value)
9727 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009728
9729 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009730 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009731 };
9732 Elements.push_back(Element);
9733 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009734
Ted Kremeneke65b0862012-03-06 20:05:56 +00009735 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9736 return SemaRef.MaybeBindToTemporary(E);
9737
9738 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9739 Elements.data(),
9740 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009741}
9742
Mike Stump11289f42009-09-09 15:08:12 +00009743template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009744ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009745TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009746 TypeSourceInfo *EncodedTypeInfo
9747 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9748 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009749 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009750
Douglas Gregora16548e2009-08-11 05:31:07 +00009751 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009752 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009753 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009754
9755 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009756 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009757 E->getRParenLoc());
9758}
Mike Stump11289f42009-09-09 15:08:12 +00009759
Douglas Gregora16548e2009-08-11 05:31:07 +00009760template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009761ExprResult TreeTransform<Derived>::
9762TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009763 // This is a kind of implicit conversion, and it needs to get dropped
9764 // and recomputed for the same general reasons that ImplicitCastExprs
9765 // do, as well a more specific one: this expression is only valid when
9766 // it appears *immediately* as an argument expression.
9767 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009768}
9769
9770template<typename Derived>
9771ExprResult TreeTransform<Derived>::
9772TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009773 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009774 = getDerived().TransformType(E->getTypeInfoAsWritten());
9775 if (!TSInfo)
9776 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009777
John McCall31168b02011-06-15 23:02:42 +00009778 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009779 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009780 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009781
John McCall31168b02011-06-15 23:02:42 +00009782 if (!getDerived().AlwaysRebuild() &&
9783 TSInfo == E->getTypeInfoAsWritten() &&
9784 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009785 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009786
John McCall31168b02011-06-15 23:02:42 +00009787 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009788 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009789 Result.get());
9790}
9791
9792template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009793ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009794TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009795 // Transform arguments.
9796 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009797 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009798 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009799 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009800 &ArgChanged))
9801 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009802
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009803 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9804 // Class message: transform the receiver type.
9805 TypeSourceInfo *ReceiverTypeInfo
9806 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9807 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009808 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009809
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009810 // If nothing changed, just retain the existing message send.
9811 if (!getDerived().AlwaysRebuild() &&
9812 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009813 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009814
9815 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009816 SmallVector<SourceLocation, 16> SelLocs;
9817 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009818 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9819 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009820 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009821 E->getMethodDecl(),
9822 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009823 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009824 E->getRightLoc());
9825 }
9826
9827 // Instance message: transform the receiver
9828 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9829 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009830 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009831 = getDerived().TransformExpr(E->getInstanceReceiver());
9832 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009833 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009834
9835 // If nothing changed, just retain the existing message send.
9836 if (!getDerived().AlwaysRebuild() &&
9837 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009838 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009839
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009840 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009841 SmallVector<SourceLocation, 16> SelLocs;
9842 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009843 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009844 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009845 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009846 E->getMethodDecl(),
9847 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009848 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009849 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009850}
9851
Mike Stump11289f42009-09-09 15:08:12 +00009852template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009853ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009854TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009855 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009856}
9857
Mike Stump11289f42009-09-09 15:08:12 +00009858template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009859ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009860TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009861 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009862}
9863
Mike Stump11289f42009-09-09 15:08:12 +00009864template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009865ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009866TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009867 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009868 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009869 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009870 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009871
9872 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009873
Douglas Gregord51d90d2010-04-26 20:11:03 +00009874 // If nothing changed, just retain the existing expression.
9875 if (!getDerived().AlwaysRebuild() &&
9876 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009877 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009878
John McCallb268a282010-08-23 23:25:46 +00009879 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009880 E->getLocation(),
9881 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009882}
9883
Mike Stump11289f42009-09-09 15:08:12 +00009884template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009885ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009886TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009887 // 'super' and types never change. Property never changes. Just
9888 // retain the existing expression.
9889 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009890 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009891
Douglas Gregor9faee212010-04-26 20:47:02 +00009892 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009893 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009894 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009895 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009896
Douglas Gregor9faee212010-04-26 20:47:02 +00009897 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009898
Douglas Gregor9faee212010-04-26 20:47:02 +00009899 // If nothing changed, just retain the existing expression.
9900 if (!getDerived().AlwaysRebuild() &&
9901 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009902 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009903
John McCallb7bd14f2010-12-02 01:19:52 +00009904 if (E->isExplicitProperty())
9905 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9906 E->getExplicitProperty(),
9907 E->getLocation());
9908
9909 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009910 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009911 E->getImplicitPropertyGetter(),
9912 E->getImplicitPropertySetter(),
9913 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009914}
9915
Mike Stump11289f42009-09-09 15:08:12 +00009916template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009917ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009918TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9919 // Transform the base expression.
9920 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9921 if (Base.isInvalid())
9922 return ExprError();
9923
9924 // Transform the key expression.
9925 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9926 if (Key.isInvalid())
9927 return ExprError();
9928
9929 // If nothing changed, just retain the existing expression.
9930 if (!getDerived().AlwaysRebuild() &&
9931 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009932 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009933
Chad Rosier1dcde962012-08-08 18:46:20 +00009934 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009935 Base.get(), Key.get(),
9936 E->getAtIndexMethodDecl(),
9937 E->setAtIndexMethodDecl());
9938}
9939
9940template<typename Derived>
9941ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009942TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009943 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009944 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009945 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009946 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009947
Douglas Gregord51d90d2010-04-26 20:11:03 +00009948 // If nothing changed, just retain the existing expression.
9949 if (!getDerived().AlwaysRebuild() &&
9950 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009951 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009952
John McCallb268a282010-08-23 23:25:46 +00009953 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009954 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009955 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009956}
9957
Mike Stump11289f42009-09-09 15:08:12 +00009958template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009959ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009960TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009961 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009962 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009963 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009964 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009965 SubExprs, &ArgumentChanged))
9966 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009967
Douglas Gregora16548e2009-08-11 05:31:07 +00009968 if (!getDerived().AlwaysRebuild() &&
9969 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009970 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009971
Douglas Gregora16548e2009-08-11 05:31:07 +00009972 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009973 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009974 E->getRParenLoc());
9975}
9976
Mike Stump11289f42009-09-09 15:08:12 +00009977template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009978ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009979TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9980 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9981 if (SrcExpr.isInvalid())
9982 return ExprError();
9983
9984 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9985 if (!Type)
9986 return ExprError();
9987
9988 if (!getDerived().AlwaysRebuild() &&
9989 Type == E->getTypeSourceInfo() &&
9990 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009991 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +00009992
9993 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9994 SrcExpr.get(), Type,
9995 E->getRParenLoc());
9996}
9997
9998template<typename Derived>
9999ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010000TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010001 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010002
Craig Topperc3ec1492014-05-26 06:22:03 +000010003 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010004 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10005
10006 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010007 blockScope->TheDecl->setBlockMissingReturnType(
10008 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010009
Chris Lattner01cf8db2011-07-20 06:58:45 +000010010 SmallVector<ParmVarDecl*, 4> params;
10011 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010012
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010013 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010014 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
10015 oldBlock->param_begin(),
10016 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010017 nullptr, paramTypes, &params)) {
10018 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010019 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010020 }
John McCall490112f2011-02-04 18:33:18 +000010021
Jordan Rosea0a86be2013-03-08 22:25:36 +000010022 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000010023 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000010024 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000010025
Jordan Rose5c382722013-03-08 21:51:21 +000010026 QualType functionType =
10027 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010028 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000010029 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000010030
10031 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000010032 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000010033 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000010034
10035 if (!oldBlock->blockMissingReturnType()) {
10036 blockScope->HasImplicitReturnType = false;
10037 blockScope->ReturnType = exprResultType;
10038 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010039
John McCall3882ace2011-01-05 12:14:39 +000010040 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000010041 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010042 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010043 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000010044 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010045 }
John McCall3882ace2011-01-05 12:14:39 +000010046
John McCall490112f2011-02-04 18:33:18 +000010047#ifndef NDEBUG
10048 // In builds with assertions, make sure that we captured everything we
10049 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010050 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010051 for (const auto &I : oldBlock->captures()) {
10052 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010053
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010054 // Ignore parameter packs.
10055 if (isa<ParmVarDecl>(oldCapture) &&
10056 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10057 continue;
John McCall490112f2011-02-04 18:33:18 +000010058
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010059 VarDecl *newCapture =
10060 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10061 oldCapture));
10062 assert(blockScope->CaptureMap.count(newCapture));
10063 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010064 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010065 }
10066#endif
10067
10068 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010069 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010070}
10071
Mike Stump11289f42009-09-09 15:08:12 +000010072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010073ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010074TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010075 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010076}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010077
10078template<typename Derived>
10079ExprResult
10080TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010081 QualType RetTy = getDerived().TransformType(E->getType());
10082 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010083 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010084 SubExprs.reserve(E->getNumSubExprs());
10085 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10086 SubExprs, &ArgumentChanged))
10087 return ExprError();
10088
10089 if (!getDerived().AlwaysRebuild() &&
10090 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010091 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010092
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010093 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010094 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010095}
Chad Rosier1dcde962012-08-08 18:46:20 +000010096
Douglas Gregora16548e2009-08-11 05:31:07 +000010097//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010098// Type reconstruction
10099//===----------------------------------------------------------------------===//
10100
Mike Stump11289f42009-09-09 15:08:12 +000010101template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010102QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10103 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010104 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010105 getDerived().getBaseEntity());
10106}
10107
Mike Stump11289f42009-09-09 15:08:12 +000010108template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010109QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10110 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010111 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010112 getDerived().getBaseEntity());
10113}
10114
Mike Stump11289f42009-09-09 15:08:12 +000010115template<typename Derived>
10116QualType
John McCall70dd5f62009-10-30 00:06:24 +000010117TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10118 bool WrittenAsLValue,
10119 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010120 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010121 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010122}
10123
10124template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010125QualType
John McCall70dd5f62009-10-30 00:06:24 +000010126TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10127 QualType ClassType,
10128 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010129 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10130 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010131}
10132
10133template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010134QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010135TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10136 ArrayType::ArraySizeModifier SizeMod,
10137 const llvm::APInt *Size,
10138 Expr *SizeExpr,
10139 unsigned IndexTypeQuals,
10140 SourceRange BracketsRange) {
10141 if (SizeExpr || !Size)
10142 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10143 IndexTypeQuals, BracketsRange,
10144 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010145
10146 QualType Types[] = {
10147 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10148 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10149 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010150 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010151 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010152 QualType SizeType;
10153 for (unsigned I = 0; I != NumTypes; ++I)
10154 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10155 SizeType = Types[I];
10156 break;
10157 }
Mike Stump11289f42009-09-09 15:08:12 +000010158
Eli Friedman9562f392012-01-25 23:20:27 +000010159 // Note that we can return a VariableArrayType here in the case where
10160 // the element type was a dependent VariableArrayType.
10161 IntegerLiteral *ArraySize
10162 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10163 /*FIXME*/BracketsRange.getBegin());
10164 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010165 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010166 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010167}
Mike Stump11289f42009-09-09 15:08:12 +000010168
Douglas Gregord6ff3322009-08-04 16:50:30 +000010169template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010170QualType
10171TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010172 ArrayType::ArraySizeModifier SizeMod,
10173 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010174 unsigned IndexTypeQuals,
10175 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010176 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010177 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010178}
10179
10180template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010181QualType
Mike Stump11289f42009-09-09 15:08:12 +000010182TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010183 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010184 unsigned IndexTypeQuals,
10185 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010186 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010187 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010188}
Mike Stump11289f42009-09-09 15:08:12 +000010189
Douglas Gregord6ff3322009-08-04 16:50:30 +000010190template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010191QualType
10192TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010193 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010194 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010195 unsigned IndexTypeQuals,
10196 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010197 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010198 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010199 IndexTypeQuals, BracketsRange);
10200}
10201
10202template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010203QualType
10204TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010205 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010206 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010207 unsigned IndexTypeQuals,
10208 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010209 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010210 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010211 IndexTypeQuals, BracketsRange);
10212}
10213
10214template<typename Derived>
10215QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010216 unsigned NumElements,
10217 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010218 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010219 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010220}
Mike Stump11289f42009-09-09 15:08:12 +000010221
Douglas Gregord6ff3322009-08-04 16:50:30 +000010222template<typename Derived>
10223QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10224 unsigned NumElements,
10225 SourceLocation AttributeLoc) {
10226 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10227 NumElements, true);
10228 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010229 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10230 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010231 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010232}
Mike Stump11289f42009-09-09 15:08:12 +000010233
Douglas Gregord6ff3322009-08-04 16:50:30 +000010234template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010235QualType
10236TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010237 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010238 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010239 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010240}
Mike Stump11289f42009-09-09 15:08:12 +000010241
Douglas Gregord6ff3322009-08-04 16:50:30 +000010242template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010243QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10244 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010245 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010246 const FunctionProtoType::ExtProtoInfo &EPI) {
10247 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010248 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010249 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010250 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010251}
Mike Stump11289f42009-09-09 15:08:12 +000010252
Douglas Gregord6ff3322009-08-04 16:50:30 +000010253template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010254QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10255 return SemaRef.Context.getFunctionNoProtoType(T);
10256}
10257
10258template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010259QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10260 assert(D && "no decl found");
10261 if (D->isInvalidDecl()) return QualType();
10262
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010263 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010264 TypeDecl *Ty;
10265 if (isa<UsingDecl>(D)) {
10266 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010267 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010268 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10269
10270 // A valid resolved using typename decl points to exactly one type decl.
10271 assert(++Using->shadow_begin() == Using->shadow_end());
10272 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010273
John McCallb96ec562009-12-04 22:46:56 +000010274 } else {
10275 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10276 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10277 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10278 }
10279
10280 return SemaRef.Context.getTypeDeclType(Ty);
10281}
10282
10283template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010284QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10285 SourceLocation Loc) {
10286 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010287}
10288
10289template<typename Derived>
10290QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10291 return SemaRef.Context.getTypeOfType(Underlying);
10292}
10293
10294template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010295QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10296 SourceLocation Loc) {
10297 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010298}
10299
10300template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010301QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10302 UnaryTransformType::UTTKind UKind,
10303 SourceLocation Loc) {
10304 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10305}
10306
10307template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010308QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010309 TemplateName Template,
10310 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010311 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010312 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010313}
Mike Stump11289f42009-09-09 15:08:12 +000010314
Douglas Gregor1135c352009-08-06 05:28:30 +000010315template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010316QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10317 SourceLocation KWLoc) {
10318 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10319}
10320
10321template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010322TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010323TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010324 bool TemplateKW,
10325 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010326 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010327 Template);
10328}
10329
10330template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010331TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010332TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10333 const IdentifierInfo &Name,
10334 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010335 QualType ObjectType,
10336 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010337 UnqualifiedId TemplateName;
10338 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010339 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010340 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010341 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010342 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010343 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010344 /*EnteringContext=*/false,
10345 Template);
John McCall31f82722010-11-12 08:19:04 +000010346 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010347}
Mike Stump11289f42009-09-09 15:08:12 +000010348
Douglas Gregora16548e2009-08-11 05:31:07 +000010349template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010350TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010351TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010352 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010353 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010354 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010355 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010356 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010357 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010358 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010359 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010360 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010361 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010362 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010363 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010364 /*EnteringContext=*/false,
10365 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010366 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010367}
Chad Rosier1dcde962012-08-08 18:46:20 +000010368
Douglas Gregor71395fa2009-11-04 00:56:37 +000010369template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010370ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010371TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10372 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010373 Expr *OrigCallee,
10374 Expr *First,
10375 Expr *Second) {
10376 Expr *Callee = OrigCallee->IgnoreParenCasts();
10377 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010378
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010379 if (First->getObjectKind() == OK_ObjCProperty) {
10380 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10381 if (BinaryOperator::isAssignmentOp(Opc))
10382 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10383 First, Second);
10384 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10385 if (Result.isInvalid())
10386 return ExprError();
10387 First = Result.get();
10388 }
10389
10390 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10391 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10392 if (Result.isInvalid())
10393 return ExprError();
10394 Second = Result.get();
10395 }
10396
Douglas Gregora16548e2009-08-11 05:31:07 +000010397 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010398 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010399 if (!First->getType()->isOverloadableType() &&
10400 !Second->getType()->isOverloadableType())
10401 return getSema().CreateBuiltinArraySubscriptExpr(First,
10402 Callee->getLocStart(),
10403 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010404 } else if (Op == OO_Arrow) {
10405 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010406 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10407 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010408 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010409 // The argument is not of overloadable type, so try to create a
10410 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010411 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010412 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010413
John McCallb268a282010-08-23 23:25:46 +000010414 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010415 }
10416 } else {
John McCallb268a282010-08-23 23:25:46 +000010417 if (!First->getType()->isOverloadableType() &&
10418 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010419 // Neither of the arguments is an overloadable type, so try to
10420 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010421 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010422 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010423 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010424 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010425 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010426
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010427 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010428 }
10429 }
Mike Stump11289f42009-09-09 15:08:12 +000010430
10431 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010432 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010433 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010434
John McCallb268a282010-08-23 23:25:46 +000010435 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010436 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010437 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010438 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010439 // If we've resolved this to a particular non-member function, just call
10440 // that function. If we resolved it to a member function,
10441 // CreateOverloaded* will find that function for us.
10442 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10443 if (!isa<CXXMethodDecl>(ND))
10444 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000010445 }
Mike Stump11289f42009-09-09 15:08:12 +000010446
Douglas Gregora16548e2009-08-11 05:31:07 +000010447 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000010448 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000010449 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000010450
Douglas Gregora16548e2009-08-11 05:31:07 +000010451 // Create the overloaded operator invocation for unary operators.
10452 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000010453 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010454 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000010455 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010456 }
Mike Stump11289f42009-09-09 15:08:12 +000010457
Douglas Gregore9d62932011-07-15 16:25:15 +000010458 if (Op == OO_Subscript) {
10459 SourceLocation LBrace;
10460 SourceLocation RBrace;
10461
10462 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
10463 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
10464 LBrace = SourceLocation::getFromRawEncoding(
10465 NameLoc.CXXOperatorName.BeginOpNameLoc);
10466 RBrace = SourceLocation::getFromRawEncoding(
10467 NameLoc.CXXOperatorName.EndOpNameLoc);
10468 } else {
10469 LBrace = Callee->getLocStart();
10470 RBrace = OpLoc;
10471 }
10472
10473 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10474 First, Second);
10475 }
Sebastian Redladba46e2009-10-29 20:17:01 +000010476
Douglas Gregora16548e2009-08-11 05:31:07 +000010477 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000010478 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010479 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000010480 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10481 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010482 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010483
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010484 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010485}
Mike Stump11289f42009-09-09 15:08:12 +000010486
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010487template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010488ExprResult
John McCallb268a282010-08-23 23:25:46 +000010489TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010490 SourceLocation OperatorLoc,
10491 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010492 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010493 TypeSourceInfo *ScopeType,
10494 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010495 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010496 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010497 QualType BaseType = Base->getType();
10498 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010499 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010500 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010501 !BaseType->getAs<PointerType>()->getPointeeType()
10502 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010503 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +000010504 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010505 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010506 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010507 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010508 /*FIXME?*/true);
10509 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010510
Douglas Gregor678f90d2010-02-25 01:56:36 +000010511 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010512 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10513 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10514 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10515 NameInfo.setNamedTypeInfo(DestroyedType);
10516
Richard Smith8e4a3862012-05-15 06:15:11 +000010517 // The scope type is now known to be a valid nested name specifier
10518 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000010519 if (ScopeType) {
10520 if (!ScopeType->getType()->getAs<TagType>()) {
10521 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
10522 diag::err_expected_class_or_namespace)
10523 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
10524 return ExprError();
10525 }
10526 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
10527 CCLoc);
10528 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010529
Abramo Bagnara7945c982012-01-27 09:46:47 +000010530 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010531 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010532 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010533 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010534 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010535 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010536 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010537}
10538
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010539template<typename Derived>
10540StmtResult
10541TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010542 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010543 CapturedDecl *CD = S->getCapturedDecl();
10544 unsigned NumParams = CD->getNumParams();
10545 unsigned ContextParamPos = CD->getContextParamPosition();
10546 SmallVector<Sema::CapturedParamNameType, 4> Params;
10547 for (unsigned I = 0; I < NumParams; ++I) {
10548 if (I != ContextParamPos) {
10549 Params.push_back(
10550 std::make_pair(
10551 CD->getParam(I)->getName(),
10552 getDerived().TransformType(CD->getParam(I)->getType())));
10553 } else {
10554 Params.push_back(std::make_pair(StringRef(), QualType()));
10555 }
10556 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010557 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010558 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010559 StmtResult Body;
10560 {
10561 Sema::CompoundScopeRAII CompoundScope(getSema());
10562 Body = getDerived().TransformStmt(S->getCapturedStmt());
10563 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010564
10565 if (Body.isInvalid()) {
10566 getSema().ActOnCapturedRegionError();
10567 return StmtError();
10568 }
10569
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010570 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010571}
10572
Douglas Gregord6ff3322009-08-04 16:50:30 +000010573} // end namespace clang
10574
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000010575#endif