blob: 29c9163a5e485a4381e4f92a38b2b7e5617e31f2 [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
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
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
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000330 /// \brief Transform the given expression.
331 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000332 /// By default, this routine transforms an expression by delegating to the
333 /// appropriate TransformXXXExpr function to build a new expression.
334 /// Subclasses may override this function to transform expressions using some
335 /// other mechanism.
336 ///
337 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000338 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000339
Richard Smithd59b8322012-12-19 01:39:02 +0000340 /// \brief Transform the given initializer.
341 ///
342 /// By default, this routine transforms an initializer by stripping off the
343 /// semantic nodes added by initialization, then passing the result to
344 /// TransformExpr or TransformExprs.
345 ///
346 /// \returns the transformed initializer.
347 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
348
Douglas Gregora3efea12011-01-03 19:04:46 +0000349 /// \brief Transform the given list of expressions.
350 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000351 /// This routine transforms a list of expressions by invoking
352 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000353 /// support for variadic templates by expanding any pack expansions (if the
354 /// derived class permits such expansion) along the way. When pack expansions
355 /// are present, the number of outputs may not equal the number of inputs.
356 ///
357 /// \param Inputs The set of expressions to be transformed.
358 ///
359 /// \param NumInputs The number of expressions in \c Inputs.
360 ///
361 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000362 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000363 /// be.
364 ///
365 /// \param Outputs The transformed input expressions will be added to this
366 /// vector.
367 ///
368 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
369 /// due to transformation.
370 ///
371 /// \returns true if an error occurred, false otherwise.
372 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000373 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000374 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000375
Douglas Gregord6ff3322009-08-04 16:50:30 +0000376 /// \brief Transform the given declaration, which is referenced from a type
377 /// or expression.
378 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000379 /// By default, acts as the identity function on declarations, unless the
380 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000381 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000382 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000383 llvm::DenseMap<Decl *, Decl *>::iterator Known
384 = TransformedLocalDecls.find(D);
385 if (Known != TransformedLocalDecls.end())
386 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000387
388 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000389 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000390
Chad Rosier1dcde962012-08-08 18:46:20 +0000391 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000392 /// place them on the new declaration.
393 ///
394 /// By default, this operation does nothing. Subclasses may override this
395 /// behavior to transform attributes.
396 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000398 /// \brief Note that a local declaration has been transformed by this
399 /// transformer.
400 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000401 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000402 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
403 /// the transformer itself has to transform the declarations. This routine
404 /// can be overridden by a subclass that keeps track of such mappings.
405 void transformedLocalDecl(Decl *Old, Decl *New) {
406 TransformedLocalDecls[Old] = New;
407 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
Douglas Gregorebe10102009-08-20 07:17:43 +0000409 /// \brief Transform the definition of the given declaration.
410 ///
Mike Stump11289f42009-09-09 15:08:12 +0000411 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000412 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000413 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
414 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000415 }
Mike Stump11289f42009-09-09 15:08:12 +0000416
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000417 /// \brief Transform the given declaration, which was the first part of a
418 /// nested-name-specifier in a member access expression.
419 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000420 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000421 /// identifier in a nested-name-specifier of a member access expression, e.g.,
422 /// the \c T in \c x->T::member
423 ///
424 /// By default, invokes TransformDecl() to transform the declaration.
425 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000426 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
427 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000428 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000429
Douglas Gregor14454802011-02-25 02:25:35 +0000430 /// \brief Transform the given nested-name-specifier with source-location
431 /// information.
432 ///
433 /// By default, transforms all of the types and declarations within the
434 /// nested-name-specifier. Subclasses may override this function to provide
435 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000436 NestedNameSpecifierLoc
437 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
438 QualType ObjectType = QualType(),
439 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000440
Douglas Gregorf816bd72009-09-03 22:13:48 +0000441 /// \brief Transform the given declaration name.
442 ///
443 /// By default, transforms the types of conversion function, constructor,
444 /// and destructor names and then (if needed) rebuilds the declaration name.
445 /// Identifiers and selectors are returned unmodified. Sublcasses may
446 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000447 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000448 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000449
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000451 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000452 /// \param SS The nested-name-specifier that qualifies the template
453 /// name. This nested-name-specifier must already have been transformed.
454 ///
455 /// \param Name The template name to transform.
456 ///
457 /// \param NameLoc The source location of the template name.
458 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000459 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000460 /// access expression, this is the type of the object whose member template
461 /// is being referenced.
462 ///
463 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
464 /// also refers to a name within the current (lexical) scope, this is the
465 /// declaration it refers to.
466 ///
467 /// By default, transforms the template name by transforming the declarations
468 /// and nested-name-specifiers that occur within the template name.
469 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000470 TemplateName
471 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
472 SourceLocation NameLoc,
473 QualType ObjectType = QualType(),
474 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000475
Douglas Gregord6ff3322009-08-04 16:50:30 +0000476 /// \brief Transform the given template argument.
477 ///
Mike Stump11289f42009-09-09 15:08:12 +0000478 /// By default, this operation transforms the type, expression, or
479 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000480 /// new template argument from the transformed result. Subclasses may
481 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000482 ///
483 /// Returns true if there was an error.
484 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
485 TemplateArgumentLoc &Output);
486
Douglas Gregor62e06f22010-12-20 17:31:10 +0000487 /// \brief Transform the given set of template arguments.
488 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000489 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000490 /// in the input set using \c TransformTemplateArgument(), and appends
491 /// the transformed arguments to the output list.
492 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000493 /// Note that this overload of \c TransformTemplateArguments() is merely
494 /// a convenience function. Subclasses that wish to override this behavior
495 /// should override the iterator-based member template version.
496 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000497 /// \param Inputs The set of template arguments to be transformed.
498 ///
499 /// \param NumInputs The number of template arguments in \p Inputs.
500 ///
501 /// \param Outputs The set of transformed template arguments output by this
502 /// routine.
503 ///
504 /// Returns true if an error occurred.
505 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
506 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000507 TemplateArgumentListInfo &Outputs) {
508 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
509 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000510
511 /// \brief Transform the given set of template arguments.
512 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000513 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000514 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000515 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000516 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000517 /// \param First An iterator to the first template argument.
518 ///
519 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000520 ///
521 /// \param Outputs The set of transformed template arguments output by this
522 /// routine.
523 ///
524 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000525 template<typename InputIterator>
526 bool TransformTemplateArguments(InputIterator First,
527 InputIterator Last,
528 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000529
John McCall0ad16662009-10-29 08:12:44 +0000530 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
531 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
532 TemplateArgumentLoc &ArgLoc);
533
John McCallbcd03502009-12-07 02:54:59 +0000534 /// \brief Fakes up a TypeSourceInfo for a type.
535 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
536 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000537 getDerived().getBaseLocation());
538 }
Mike Stump11289f42009-09-09 15:08:12 +0000539
John McCall550e0c22009-10-21 00:40:46 +0000540#define ABSTRACT_TYPELOC(CLASS, PARENT)
541#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000542 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000543#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544
Douglas Gregor3024f072012-04-16 07:05:22 +0000545 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
546 FunctionProtoTypeLoc TL,
547 CXXRecordDecl *ThisContext,
548 unsigned ThisTypeQuals);
549
David Majnemerfad8f482013-10-15 09:33:02 +0000550 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000551
Chad Rosier1dcde962012-08-08 18:46:20 +0000552 QualType
John McCall31f82722010-11-12 08:19:04 +0000553 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
554 TemplateSpecializationTypeLoc TL,
555 TemplateName Template);
556
Chad Rosier1dcde962012-08-08 18:46:20 +0000557 QualType
John McCall31f82722010-11-12 08:19:04 +0000558 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
559 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000560 TemplateName Template,
561 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000562
Chad Rosier1dcde962012-08-08 18:46:20 +0000563 QualType
Douglas Gregor5a064722011-02-28 17:23:35 +0000564 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000565 DependentTemplateSpecializationTypeLoc TL,
566 NestedNameSpecifierLoc QualifierLoc);
567
John McCall58f10c32010-03-11 09:03:00 +0000568 /// \brief Transforms the parameters of a function type into the
569 /// given vectors.
570 ///
571 /// The result vectors should be kept in sync; null entries in the
572 /// variables vector are acceptable.
573 ///
574 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000575 bool TransformFunctionTypeParams(SourceLocation Loc,
576 ParmVarDecl **Params, unsigned NumParams,
577 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000578 SmallVectorImpl<QualType> &PTypes,
579 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000580
581 /// \brief Transforms a single function-type parameter. Return null
582 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000583 ///
584 /// \param indexAdjustment - A number to add to the parameter's
585 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000586 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000587 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000588 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000589 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000590
John McCall31f82722010-11-12 08:19:04 +0000591 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000592
John McCalldadc5752010-08-24 06:29:42 +0000593 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
594 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000595
596 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000597 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000598 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
599 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000600
Faisal Vali2cba1332013-10-23 06:44:28 +0000601 TemplateParameterList *TransformTemplateParameterList(
602 TemplateParameterList *TPL) {
603 return TPL;
604 }
605
Richard Smithdb2630f2012-10-21 03:28:35 +0000606 ExprResult TransformAddressOfOperand(Expr *E);
607 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
608 bool IsAddressOfOperand);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000609 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000610
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000611// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
612// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000613#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000614 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000615 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000616#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000617 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000618 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000619#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000620#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000621
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000622#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000623 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000624 OMPClause *Transform ## Class(Class *S);
625#include "clang/Basic/OpenMPKinds.def"
626
Douglas Gregord6ff3322009-08-04 16:50:30 +0000627 /// \brief Build a new pointer type given its pointee type.
628 ///
629 /// By default, performs semantic analysis when building the pointer type.
630 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000631 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000632
633 /// \brief Build a new block pointer type given its pointee type.
634 ///
Mike Stump11289f42009-09-09 15:08:12 +0000635 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000636 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000637 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000638
John McCall70dd5f62009-10-30 00:06:24 +0000639 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000640 ///
John McCall70dd5f62009-10-30 00:06:24 +0000641 /// By default, performs semantic analysis when building the
642 /// reference type. Subclasses may override this routine to provide
643 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000644 ///
John McCall70dd5f62009-10-30 00:06:24 +0000645 /// \param LValue whether the type was written with an lvalue sigil
646 /// or an rvalue sigil.
647 QualType RebuildReferenceType(QualType ReferentType,
648 bool LValue,
649 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000650
Douglas Gregord6ff3322009-08-04 16:50:30 +0000651 /// \brief Build a new member pointer type given the pointee type and the
652 /// class type it refers into.
653 ///
654 /// By default, performs semantic analysis when building the member pointer
655 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000656 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
657 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000658
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659 /// \brief Build a new array type given the element type, size
660 /// modifier, size of the array (if known), size expression, and index type
661 /// qualifiers.
662 ///
663 /// By default, performs semantic analysis when building the array type.
664 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000665 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666 QualType RebuildArrayType(QualType ElementType,
667 ArrayType::ArraySizeModifier SizeMod,
668 const llvm::APInt *Size,
669 Expr *SizeExpr,
670 unsigned IndexTypeQuals,
671 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000672
Douglas Gregord6ff3322009-08-04 16:50:30 +0000673 /// \brief Build a new constant array type given the element type, size
674 /// modifier, (known) size of the array, and index type qualifiers.
675 ///
676 /// By default, performs semantic analysis when building the array type.
677 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000678 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 ArrayType::ArraySizeModifier SizeMod,
680 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000681 unsigned IndexTypeQuals,
682 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000683
Douglas Gregord6ff3322009-08-04 16:50:30 +0000684 /// \brief Build a new incomplete array type given the element type, size
685 /// modifier, and index type qualifiers.
686 ///
687 /// By default, performs semantic analysis when building the array type.
688 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000689 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000690 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000691 unsigned IndexTypeQuals,
692 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000693
Mike Stump11289f42009-09-09 15:08:12 +0000694 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 /// size modifier, size expression, and index type qualifiers.
696 ///
697 /// By default, performs semantic analysis when building the array type.
698 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000699 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000700 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000701 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702 unsigned IndexTypeQuals,
703 SourceRange BracketsRange);
704
Mike Stump11289f42009-09-09 15:08:12 +0000705 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000706 /// size modifier, size expression, and index type qualifiers.
707 ///
708 /// By default, performs semantic analysis when building the array type.
709 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000710 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000711 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000712 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000713 unsigned IndexTypeQuals,
714 SourceRange BracketsRange);
715
716 /// \brief Build a new vector type given the element type and
717 /// number of elements.
718 ///
719 /// By default, performs semantic analysis when building the vector type.
720 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000721 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000722 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000723
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724 /// \brief Build a new extended vector type given the element type and
725 /// number of elements.
726 ///
727 /// By default, performs semantic analysis when building the vector type.
728 /// Subclasses may override this routine to provide different behavior.
729 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
730 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000731
732 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000733 /// given the element type and number of elements.
734 ///
735 /// By default, performs semantic analysis when building the vector type.
736 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000737 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000738 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000739 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000740
Douglas Gregord6ff3322009-08-04 16:50:30 +0000741 /// \brief Build a new function type.
742 ///
743 /// By default, performs semantic analysis when building the function type.
744 /// Subclasses may override this routine to provide different behavior.
745 QualType RebuildFunctionProtoType(QualType T,
Jordan Rose5c382722013-03-08 21:51:21 +0000746 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000747 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000748
John McCall550e0c22009-10-21 00:40:46 +0000749 /// \brief Build a new unprototyped function type.
750 QualType RebuildFunctionNoProtoType(QualType ResultType);
751
John McCallb96ec562009-12-04 22:46:56 +0000752 /// \brief Rebuild an unresolved typename type, given the decl that
753 /// the UnresolvedUsingTypenameDecl was transformed to.
754 QualType RebuildUnresolvedUsingType(Decl *D);
755
Douglas Gregord6ff3322009-08-04 16:50:30 +0000756 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000757 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000758 return SemaRef.Context.getTypeDeclType(Typedef);
759 }
760
761 /// \brief Build a new class/struct/union type.
762 QualType RebuildRecordType(RecordDecl *Record) {
763 return SemaRef.Context.getTypeDeclType(Record);
764 }
765
766 /// \brief Build a new Enum type.
767 QualType RebuildEnumType(EnumDecl *Enum) {
768 return SemaRef.Context.getTypeDeclType(Enum);
769 }
John McCallfcc33b02009-09-05 00:15:47 +0000770
Mike Stump11289f42009-09-09 15:08:12 +0000771 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000772 ///
773 /// By default, performs semantic analysis when building the typeof type.
774 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000775 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000776
Mike Stump11289f42009-09-09 15:08:12 +0000777 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000778 ///
779 /// By default, builds a new TypeOfType with the given underlying type.
780 QualType RebuildTypeOfType(QualType Underlying);
781
Alexis Hunte852b102011-05-24 22:41:36 +0000782 /// \brief Build a new unary transform type.
783 QualType RebuildUnaryTransformType(QualType BaseType,
784 UnaryTransformType::UTTKind UKind,
785 SourceLocation Loc);
786
Richard Smith74aeef52013-04-26 16:15:35 +0000787 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000788 ///
789 /// By default, performs semantic analysis when building the decltype type.
790 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000791 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000792
Richard Smith74aeef52013-04-26 16:15:35 +0000793 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000794 ///
795 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000796 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000797 // Note, IsDependent is always false here: we implicitly convert an 'auto'
798 // which has been deduced to a dependent type into an undeduced 'auto', so
799 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000800 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
801 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000802 }
803
Douglas Gregord6ff3322009-08-04 16:50:30 +0000804 /// \brief Build a new template specialization type.
805 ///
806 /// By default, performs semantic analysis when building the template
807 /// specialization type. Subclasses may override this routine to provide
808 /// different behavior.
809 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000810 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000811 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000812
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000813 /// \brief Build a new parenthesized type.
814 ///
815 /// By default, builds a new ParenType type from the inner type.
816 /// Subclasses may override this routine to provide different behavior.
817 QualType RebuildParenType(QualType InnerType) {
818 return SemaRef.Context.getParenType(InnerType);
819 }
820
Douglas Gregord6ff3322009-08-04 16:50:30 +0000821 /// \brief Build a new qualified name type.
822 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000823 /// By default, builds a new ElaboratedType type from the keyword,
824 /// the nested-name-specifier and the named type.
825 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000826 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
827 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000828 NestedNameSpecifierLoc QualifierLoc,
829 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000830 return SemaRef.Context.getElaboratedType(Keyword,
831 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000832 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000833 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000834
835 /// \brief Build a new typename type that refers to a template-id.
836 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000837 /// By default, builds a new DependentNameType type from the
838 /// nested-name-specifier and the given type. Subclasses may override
839 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000840 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000841 ElaboratedTypeKeyword Keyword,
842 NestedNameSpecifierLoc QualifierLoc,
843 const IdentifierInfo *Name,
844 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000845 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000846 // Rebuild the template name.
847 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000848 CXXScopeSpec SS;
849 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000850 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000851 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
852 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000853
Douglas Gregora7a795b2011-03-01 20:11:18 +0000854 if (InstName.isNull())
855 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000856
Douglas Gregora7a795b2011-03-01 20:11:18 +0000857 // If it's still dependent, make a dependent specialization.
858 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000859 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
860 QualifierLoc.getNestedNameSpecifier(),
861 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000862 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000863
Douglas Gregora7a795b2011-03-01 20:11:18 +0000864 // Otherwise, make an elaborated type wrapping a non-dependent
865 // specialization.
866 QualType T =
867 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
868 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000869
Craig Topperc3ec1492014-05-26 06:22:03 +0000870 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000871 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000872
873 return SemaRef.Context.getElaboratedType(Keyword,
874 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000875 T);
876 }
877
Douglas Gregord6ff3322009-08-04 16:50:30 +0000878 /// \brief Build a new typename type that refers to an identifier.
879 ///
880 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000881 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000882 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000883 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000884 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000885 NestedNameSpecifierLoc QualifierLoc,
886 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000887 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000888 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000889 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000890
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000891 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000892 // If the name is still dependent, just build a new dependent name type.
893 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000894 return SemaRef.Context.getDependentNameType(Keyword,
895 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000896 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000897 }
898
Abramo Bagnara6150c882010-05-11 21:36:43 +0000899 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000900 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000901 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000902
903 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
904
Abramo Bagnarad7548482010-05-19 21:37:53 +0000905 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000906 // into a non-dependent elaborated-type-specifier. Find the tag we're
907 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000908 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000909 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
910 if (!DC)
911 return QualType();
912
John McCallbf8c5192010-05-27 06:40:31 +0000913 if (SemaRef.RequireCompleteDeclContext(SS, DC))
914 return QualType();
915
Craig Topperc3ec1492014-05-26 06:22:03 +0000916 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000917 SemaRef.LookupQualifiedName(Result, DC);
918 switch (Result.getResultKind()) {
919 case LookupResult::NotFound:
920 case LookupResult::NotFoundInCurrentInstantiation:
921 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000922
Douglas Gregore677daf2010-03-31 22:19:08 +0000923 case LookupResult::Found:
924 Tag = Result.getAsSingle<TagDecl>();
925 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000926
Douglas Gregore677daf2010-03-31 22:19:08 +0000927 case LookupResult::FoundOverloaded:
928 case LookupResult::FoundUnresolvedValue:
929 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000930
Douglas Gregore677daf2010-03-31 22:19:08 +0000931 case LookupResult::Ambiguous:
932 // Let the LookupResult structure handle ambiguities.
933 return QualType();
934 }
935
936 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000937 // Check where the name exists but isn't a tag type and use that to emit
938 // better diagnostics.
939 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
940 SemaRef.LookupQualifiedName(Result, DC);
941 switch (Result.getResultKind()) {
942 case LookupResult::Found:
943 case LookupResult::FoundOverloaded:
944 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000945 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000946 unsigned Kind = 0;
947 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000948 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
949 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000950 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
951 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
952 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000953 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000954 default:
Nick Lewycky0c438082011-01-24 19:01:04 +0000955 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000956 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000957 break;
958 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000959 return QualType();
960 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000961
Richard Trieucaa33d32011-06-10 03:11:26 +0000962 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
963 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000964 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000965 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
966 return QualType();
967 }
968
969 // Build the elaborated-type-specifier type.
970 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000971 return SemaRef.Context.getElaboratedType(Keyword,
972 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000973 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000974 }
Mike Stump11289f42009-09-09 15:08:12 +0000975
Douglas Gregor822d0302011-01-12 17:07:58 +0000976 /// \brief Build a new pack expansion type.
977 ///
978 /// By default, builds a new PackExpansionType type from the given pattern.
979 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000980 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +0000981 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000982 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +0000983 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000984 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
985 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000986 }
987
Eli Friedman0dfb8892011-10-06 23:00:33 +0000988 /// \brief Build a new atomic type given its value type.
989 ///
990 /// By default, performs semantic analysis when building the atomic type.
991 /// Subclasses may override this routine to provide different behavior.
992 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
993
Douglas Gregor71dc5092009-08-06 06:41:21 +0000994 /// \brief Build a new template name given a nested name specifier, a flag
995 /// indicating whether the "template" keyword was provided, and the template
996 /// that the template name refers to.
997 ///
998 /// By default, builds the new template name directly. Subclasses may override
999 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001000 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001001 bool TemplateKW,
1002 TemplateDecl *Template);
1003
Douglas Gregor71dc5092009-08-06 06:41:21 +00001004 /// \brief Build a new template name given a nested name specifier and the
1005 /// name that is referred to as a template.
1006 ///
1007 /// By default, performs semantic analysis to determine whether the name can
1008 /// be resolved to a specific template, then builds the appropriate kind of
1009 /// template name. Subclasses may override this routine to provide different
1010 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001011 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1012 const IdentifierInfo &Name,
1013 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001014 QualType ObjectType,
1015 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001016
Douglas Gregor71395fa2009-11-04 00:56:37 +00001017 /// \brief Build a new template name given a nested name specifier and the
1018 /// overloaded operator name that is referred to as a template.
1019 ///
1020 /// By default, performs semantic analysis to determine whether the name can
1021 /// be resolved to a specific template, then builds the appropriate kind of
1022 /// template name. Subclasses may override this routine to provide different
1023 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001024 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001025 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001026 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001027 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001028
1029 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001030 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001031 ///
1032 /// By default, performs semantic analysis to determine whether the name can
1033 /// be resolved to a specific template, then builds the appropriate kind of
1034 /// template name. Subclasses may override this routine to provide different
1035 /// behavior.
1036 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1037 const TemplateArgument &ArgPack) {
1038 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1039 }
1040
Douglas Gregorebe10102009-08-20 07:17:43 +00001041 /// \brief Build a new compound statement.
1042 ///
1043 /// By default, performs semantic analysis to build the new statement.
1044 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001045 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001046 MultiStmtArg Statements,
1047 SourceLocation RBraceLoc,
1048 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001049 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001050 IsStmtExpr);
1051 }
1052
1053 /// \brief Build a new case statement.
1054 ///
1055 /// By default, performs semantic analysis to build the new statement.
1056 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001057 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001058 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001059 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001060 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001061 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001062 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001063 ColonLoc);
1064 }
Mike Stump11289f42009-09-09 15:08:12 +00001065
Douglas Gregorebe10102009-08-20 07:17:43 +00001066 /// \brief Attach the body to a new case statement.
1067 ///
1068 /// By default, performs semantic analysis to build the new statement.
1069 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001070 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001071 getSema().ActOnCaseStmtBody(S, Body);
1072 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001073 }
Mike Stump11289f42009-09-09 15:08:12 +00001074
Douglas Gregorebe10102009-08-20 07:17:43 +00001075 /// \brief Build a new default statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001079 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001080 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001081 Stmt *SubStmt) {
1082 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001083 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001084 }
Mike Stump11289f42009-09-09 15:08:12 +00001085
Douglas Gregorebe10102009-08-20 07:17:43 +00001086 /// \brief Build a new label statement.
1087 ///
1088 /// By default, performs semantic analysis to build the new statement.
1089 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001090 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1091 SourceLocation ColonLoc, Stmt *SubStmt) {
1092 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001093 }
Mike Stump11289f42009-09-09 15:08:12 +00001094
Richard Smithc202b282012-04-14 00:33:13 +00001095 /// \brief Build a new label statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001099 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1100 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001101 Stmt *SubStmt) {
1102 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1103 }
1104
Douglas Gregorebe10102009-08-20 07:17:43 +00001105 /// \brief Build a new "if" statement.
1106 ///
1107 /// By default, performs semantic analysis to build the new statement.
1108 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001109 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001110 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001111 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001112 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 }
Mike Stump11289f42009-09-09 15:08:12 +00001114
Douglas Gregorebe10102009-08-20 07:17:43 +00001115 /// \brief Start building a new switch statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001119 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001120 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001121 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001122 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001123 }
Mike Stump11289f42009-09-09 15:08:12 +00001124
Douglas Gregorebe10102009-08-20 07:17:43 +00001125 /// \brief Attach the body to the switch statement.
1126 ///
1127 /// By default, performs semantic analysis to build the new statement.
1128 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001129 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001130 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001131 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001132 }
1133
1134 /// \brief Build a new while statement.
1135 ///
1136 /// By default, performs semantic analysis to build the new statement.
1137 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001138 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1139 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001140 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001141 }
Mike Stump11289f42009-09-09 15:08:12 +00001142
Douglas Gregorebe10102009-08-20 07:17:43 +00001143 /// \brief Build a new do-while statement.
1144 ///
1145 /// By default, performs semantic analysis to build the new statement.
1146 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001147 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001148 SourceLocation WhileLoc, SourceLocation LParenLoc,
1149 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001150 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1151 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001152 }
1153
1154 /// \brief Build a new for statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001158 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001159 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001160 VarDecl *CondVar, Sema::FullExprArg Inc,
1161 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001162 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001163 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001164 }
Mike Stump11289f42009-09-09 15:08:12 +00001165
Douglas Gregorebe10102009-08-20 07:17:43 +00001166 /// \brief Build a new goto statement.
1167 ///
1168 /// By default, performs semantic analysis to build the new statement.
1169 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001170 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1171 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001172 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001173 }
1174
1175 /// \brief Build a new indirect goto statement.
1176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001179 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001180 SourceLocation StarLoc,
1181 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001182 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001183 }
Mike Stump11289f42009-09-09 15:08:12 +00001184
Douglas Gregorebe10102009-08-20 07:17:43 +00001185 /// \brief Build a new return statement.
1186 ///
1187 /// By default, performs semantic analysis to build the new statement.
1188 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001189 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001190 return getSema().BuildReturnStmt(ReturnLoc, Result);
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 declaration statement.
1194 ///
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
Rafael Espindolaab417692013-07-09 12:05:01 +00001197 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1198 SourceLocation StartLoc, SourceLocation EndLoc) {
1199 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001200 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001201 }
Mike Stump11289f42009-09-09 15:08:12 +00001202
Anders Carlssonaaeef072010-01-24 05:50:09 +00001203 /// \brief Build a new inline asm statement.
1204 ///
1205 /// By default, performs semantic analysis to build the new statement.
1206 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001207 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1208 bool IsVolatile, unsigned NumOutputs,
1209 unsigned NumInputs, IdentifierInfo **Names,
1210 MultiExprArg Constraints, MultiExprArg Exprs,
1211 Expr *AsmString, MultiExprArg Clobbers,
1212 SourceLocation RParenLoc) {
1213 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1214 NumInputs, Names, Constraints, Exprs,
1215 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001216 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001217
Chad Rosier32503022012-06-11 20:47:18 +00001218 /// \brief Build a new MS style inline asm statement.
1219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001222 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001223 ArrayRef<Token> AsmToks,
1224 StringRef AsmString,
1225 unsigned NumOutputs, unsigned NumInputs,
1226 ArrayRef<StringRef> Constraints,
1227 ArrayRef<StringRef> Clobbers,
1228 ArrayRef<Expr*> Exprs,
1229 SourceLocation EndLoc) {
1230 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1231 NumOutputs, NumInputs,
1232 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001233 }
1234
James Dennett2a4d13c2012-06-15 07:13:21 +00001235 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001236 ///
1237 /// By default, performs semantic analysis to build the new statement.
1238 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001239 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001240 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001241 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001242 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001243 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001244 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001245 }
1246
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001247 /// \brief Rebuild an Objective-C exception declaration.
1248 ///
1249 /// By default, performs semantic analysis to build the new declaration.
1250 /// Subclasses may override this routine to provide different behavior.
1251 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1252 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001253 return getSema().BuildObjCExceptionDecl(TInfo, T,
1254 ExceptionDecl->getInnerLocStart(),
1255 ExceptionDecl->getLocation(),
1256 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001257 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001258
James Dennett2a4d13c2012-06-15 07:13:21 +00001259 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001260 ///
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001263 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001264 SourceLocation RParenLoc,
1265 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001266 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001267 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001268 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001269 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001270
James Dennett2a4d13c2012-06-15 07:13:21 +00001271 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001272 ///
1273 /// By default, performs semantic analysis to build the new statement.
1274 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001275 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001276 Stmt *Body) {
1277 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001278 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001279
James Dennett2a4d13c2012-06-15 07:13:21 +00001280 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001281 ///
1282 /// By default, performs semantic analysis to build the new statement.
1283 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001284 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001285 Expr *Operand) {
1286 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001287 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001288
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001289 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001290 ///
1291 /// By default, performs semantic analysis to build the new statement.
1292 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001293 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1294 ArrayRef<OMPClause *> Clauses,
1295 Stmt *AStmt,
1296 SourceLocation StartLoc,
1297 SourceLocation EndLoc) {
1298 return getSema().ActOnOpenMPExecutableDirective(Kind, Clauses, AStmt,
1299 StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001300 }
1301
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001302 /// \brief Build a new OpenMP 'if' clause.
1303 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001304 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001305 /// Subclasses may override this routine to provide different behavior.
1306 OMPClause *RebuildOMPIfClause(Expr *Condition,
1307 SourceLocation StartLoc,
1308 SourceLocation LParenLoc,
1309 SourceLocation EndLoc) {
1310 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1311 LParenLoc, EndLoc);
1312 }
1313
Alexey Bataev568a8332014-03-06 06:15:19 +00001314 /// \brief Build a new OpenMP 'num_threads' clause.
1315 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001316 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001317 /// Subclasses may override this routine to provide different behavior.
1318 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1319 SourceLocation StartLoc,
1320 SourceLocation LParenLoc,
1321 SourceLocation EndLoc) {
1322 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1323 LParenLoc, EndLoc);
1324 }
1325
Alexey Bataev62c87d22014-03-21 04:51:18 +00001326 /// \brief Build a new OpenMP 'safelen' clause.
1327 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001328 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001329 /// Subclasses may override this routine to provide different behavior.
1330 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1331 SourceLocation LParenLoc,
1332 SourceLocation EndLoc) {
1333 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1334 }
1335
Alexander Musman8bd31e62014-05-27 15:12:19 +00001336 /// \brief Build a new OpenMP 'collapse' clause.
1337 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001338 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001339 /// Subclasses may override this routine to provide different behavior.
1340 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1341 SourceLocation LParenLoc,
1342 SourceLocation EndLoc) {
1343 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1344 EndLoc);
1345 }
1346
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001347 /// \brief Build a new OpenMP 'default' clause.
1348 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001349 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001350 /// Subclasses may override this routine to provide different behavior.
1351 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1352 SourceLocation KindKwLoc,
1353 SourceLocation StartLoc,
1354 SourceLocation LParenLoc,
1355 SourceLocation EndLoc) {
1356 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1357 StartLoc, LParenLoc, EndLoc);
1358 }
1359
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001360 /// \brief Build a new OpenMP 'proc_bind' clause.
1361 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001362 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001363 /// Subclasses may override this routine to provide different behavior.
1364 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1365 SourceLocation KindKwLoc,
1366 SourceLocation StartLoc,
1367 SourceLocation LParenLoc,
1368 SourceLocation EndLoc) {
1369 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1370 StartLoc, LParenLoc, EndLoc);
1371 }
1372
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001373 /// \brief Build a new OpenMP 'private' clause.
1374 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001375 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001376 /// Subclasses may override this routine to provide different behavior.
1377 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1378 SourceLocation StartLoc,
1379 SourceLocation LParenLoc,
1380 SourceLocation EndLoc) {
1381 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1382 EndLoc);
1383 }
1384
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001385 /// \brief Build a new OpenMP 'firstprivate' clause.
1386 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001387 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001388 /// Subclasses may override this routine to provide different behavior.
1389 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1390 SourceLocation StartLoc,
1391 SourceLocation LParenLoc,
1392 SourceLocation EndLoc) {
1393 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1394 EndLoc);
1395 }
1396
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001397 /// \brief Build a new OpenMP 'shared' clause.
1398 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001399 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001400 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001401 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1402 SourceLocation StartLoc,
1403 SourceLocation LParenLoc,
1404 SourceLocation EndLoc) {
1405 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1406 EndLoc);
1407 }
1408
Alexander Musman8dba6642014-04-22 13:09:42 +00001409 /// \brief Build a new OpenMP 'linear' clause.
1410 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001411 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001412 /// Subclasses may override this routine to provide different behavior.
1413 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1414 SourceLocation StartLoc,
1415 SourceLocation LParenLoc,
1416 SourceLocation ColonLoc,
1417 SourceLocation EndLoc) {
1418 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1419 ColonLoc, EndLoc);
1420 }
1421
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001422 /// \brief Build a new OpenMP 'aligned' clause.
1423 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001424 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001425 /// Subclasses may override this routine to provide different behavior.
1426 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1427 SourceLocation StartLoc,
1428 SourceLocation LParenLoc,
1429 SourceLocation ColonLoc,
1430 SourceLocation EndLoc) {
1431 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1432 LParenLoc, ColonLoc, EndLoc);
1433 }
1434
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001435 /// \brief Build a new OpenMP 'copyin' clause.
1436 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001437 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001438 /// Subclasses may override this routine to provide different behavior.
1439 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1440 SourceLocation StartLoc,
1441 SourceLocation LParenLoc,
1442 SourceLocation EndLoc) {
1443 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1444 EndLoc);
1445 }
1446
James Dennett2a4d13c2012-06-15 07:13:21 +00001447 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001448 ///
1449 /// By default, performs semantic analysis to build the new statement.
1450 /// Subclasses may override this routine to provide different behavior.
1451 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1452 Expr *object) {
1453 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1454 }
1455
James Dennett2a4d13c2012-06-15 07:13:21 +00001456 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001457 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001458 /// By default, performs semantic analysis to build the new statement.
1459 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001460 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001461 Expr *Object, Stmt *Body) {
1462 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001463 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001464
James Dennett2a4d13c2012-06-15 07:13:21 +00001465 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001466 ///
1467 /// By default, performs semantic analysis to build the new statement.
1468 /// Subclasses may override this routine to provide different behavior.
1469 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1470 Stmt *Body) {
1471 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1472 }
John McCall53848232011-07-27 01:07:15 +00001473
Douglas Gregorf68a5082010-04-22 23:10:45 +00001474 /// \brief Build a new Objective-C fast enumeration statement.
1475 ///
1476 /// By default, performs semantic analysis to build the new statement.
1477 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001478 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001479 Stmt *Element,
1480 Expr *Collection,
1481 SourceLocation RParenLoc,
1482 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001483 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001484 Element,
John McCallb268a282010-08-23 23:25:46 +00001485 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001486 RParenLoc);
1487 if (ForEachStmt.isInvalid())
1488 return StmtError();
1489
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001490 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001491 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001492
Douglas Gregorebe10102009-08-20 07:17:43 +00001493 /// \brief Build a new C++ exception declaration.
1494 ///
1495 /// By default, performs semantic analysis to build the new decaration.
1496 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001497 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001498 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001499 SourceLocation StartLoc,
1500 SourceLocation IdLoc,
1501 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001502 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001503 StartLoc, IdLoc, Id);
1504 if (Var)
1505 getSema().CurContext->addDecl(Var);
1506 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001507 }
1508
1509 /// \brief Build a new C++ catch statement.
1510 ///
1511 /// By default, performs semantic analysis to build the new statement.
1512 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001513 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001514 VarDecl *ExceptionDecl,
1515 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001516 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1517 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001518 }
Mike Stump11289f42009-09-09 15:08:12 +00001519
Douglas Gregorebe10102009-08-20 07:17:43 +00001520 /// \brief Build a new C++ try statement.
1521 ///
1522 /// By default, performs semantic analysis to build the new statement.
1523 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001524 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1525 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001526 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001527 }
Mike Stump11289f42009-09-09 15:08:12 +00001528
Richard Smith02e85f32011-04-14 22:09:26 +00001529 /// \brief Build a new C++0x range-based for statement.
1530 ///
1531 /// By default, performs semantic analysis to build the new statement.
1532 /// Subclasses may override this routine to provide different behavior.
1533 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1534 SourceLocation ColonLoc,
1535 Stmt *Range, Stmt *BeginEnd,
1536 Expr *Cond, Expr *Inc,
1537 Stmt *LoopVar,
1538 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001539 // If we've just learned that the range is actually an Objective-C
1540 // collection, treat this as an Objective-C fast enumeration loop.
1541 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1542 if (RangeStmt->isSingleDecl()) {
1543 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001544 if (RangeVar->isInvalidDecl())
1545 return StmtError();
1546
Douglas Gregorf7106af2013-04-08 18:40:13 +00001547 Expr *RangeExpr = RangeVar->getInit();
1548 if (!RangeExpr->isTypeDependent() &&
1549 RangeExpr->getType()->isObjCObjectPointerType())
1550 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1551 RParenLoc);
1552 }
1553 }
1554 }
1555
Richard Smith02e85f32011-04-14 22:09:26 +00001556 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001557 Cond, Inc, LoopVar, RParenLoc,
1558 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001559 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001560
1561 /// \brief Build a new C++0x range-based for statement.
1562 ///
1563 /// By default, performs semantic analysis to build the new statement.
1564 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001565 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001566 bool IsIfExists,
1567 NestedNameSpecifierLoc QualifierLoc,
1568 DeclarationNameInfo NameInfo,
1569 Stmt *Nested) {
1570 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1571 QualifierLoc, NameInfo, Nested);
1572 }
1573
Richard Smith02e85f32011-04-14 22:09:26 +00001574 /// \brief Attach body to a C++0x range-based for statement.
1575 ///
1576 /// By default, performs semantic analysis to finish the new statement.
1577 /// Subclasses may override this routine to provide different behavior.
1578 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1579 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1580 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001581
David Majnemerfad8f482013-10-15 09:33:02 +00001582 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1583 Stmt *TryBlock, Stmt *Handler) {
1584 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001585 }
1586
David Majnemerfad8f482013-10-15 09:33:02 +00001587 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001588 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001589 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001590 }
1591
David Majnemerfad8f482013-10-15 09:33:02 +00001592 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1593 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001594 }
1595
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 /// \brief Build a new expression that references a declaration.
1597 ///
1598 /// By default, performs semantic analysis to build the new expression.
1599 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001600 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001601 LookupResult &R,
1602 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001603 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1604 }
1605
1606
1607 /// \brief Build a new expression that references a declaration.
1608 ///
1609 /// By default, performs semantic analysis to build the new expression.
1610 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001611 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001612 ValueDecl *VD,
1613 const DeclarationNameInfo &NameInfo,
1614 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001615 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001616 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001617
1618 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001619
1620 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001621 }
Mike Stump11289f42009-09-09 15:08:12 +00001622
Douglas Gregora16548e2009-08-11 05:31:07 +00001623 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001624 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 /// By default, performs semantic analysis to build the new expression.
1626 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001627 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001629 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001630 }
1631
Douglas Gregorad8a3362009-09-04 17:36:40 +00001632 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001633 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001634 /// By default, performs semantic analysis to build the new expression.
1635 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001636 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001637 SourceLocation OperatorLoc,
1638 bool isArrow,
1639 CXXScopeSpec &SS,
1640 TypeSourceInfo *ScopeType,
1641 SourceLocation CCLoc,
1642 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001643 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001644
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001646 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 /// By default, performs semantic analysis to build the new expression.
1648 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001649 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001650 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001651 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001652 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001653 }
Mike Stump11289f42009-09-09 15:08:12 +00001654
Douglas Gregor882211c2010-04-28 22:16:22 +00001655 /// \brief Build a new builtin offsetof expression.
1656 ///
1657 /// By default, performs semantic analysis to build the new expression.
1658 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001659 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001660 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001661 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001662 unsigned NumComponents,
1663 SourceLocation RParenLoc) {
1664 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1665 NumComponents, RParenLoc);
1666 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001667
1668 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001669 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001670 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001671 /// By default, performs semantic analysis to build the new expression.
1672 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001673 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1674 SourceLocation OpLoc,
1675 UnaryExprOrTypeTrait ExprKind,
1676 SourceRange R) {
1677 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001678 }
1679
Peter Collingbournee190dee2011-03-11 19:24:49 +00001680 /// \brief Build a new sizeof, alignof or vec step expression with an
1681 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001682 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001683 /// By default, performs semantic analysis to build the new expression.
1684 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001685 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1686 UnaryExprOrTypeTrait ExprKind,
1687 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001688 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001689 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001690 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001691 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001692
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001693 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001694 }
Mike Stump11289f42009-09-09 15:08:12 +00001695
Douglas Gregora16548e2009-08-11 05:31:07 +00001696 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001697 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 /// By default, performs semantic analysis to build the new expression.
1699 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001700 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001701 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001702 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001703 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001704 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001705 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001706 RBracketLoc);
1707 }
1708
1709 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001710 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001711 /// By default, performs semantic analysis to build the new expression.
1712 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001713 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001715 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001716 Expr *ExecConfig = nullptr) {
1717 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001718 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001719 }
1720
1721 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001722 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001723 /// By default, performs semantic analysis to build the new expression.
1724 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001725 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001726 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001727 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001728 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001729 const DeclarationNameInfo &MemberNameInfo,
1730 ValueDecl *Member,
1731 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001732 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001733 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001734 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1735 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001736 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001737 // We have a reference to an unnamed field. This is always the
1738 // base of an anonymous struct/union member access, i.e. the
1739 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001740 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001741 assert(Member->getType()->isRecordType() &&
1742 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001743
Richard Smithcab9a7d2011-10-26 19:06:56 +00001744 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001745 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001746 QualifierLoc.getNestedNameSpecifier(),
1747 FoundDecl, Member);
1748 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001749 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001750 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001751 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001752 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001753 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001754 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001755 cast<FieldDecl>(Member)->getType(),
1756 VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001757 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001758 }
Mike Stump11289f42009-09-09 15:08:12 +00001759
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001760 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001761 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001762
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001763 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001764 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001765
John McCall16df1e52010-03-30 21:47:33 +00001766 // FIXME: this involves duplicating earlier analysis in a lot of
1767 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001768 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001769 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001770 R.resolveKind();
1771
John McCallb268a282010-08-23 23:25:46 +00001772 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001773 SS, TemplateKWLoc,
1774 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001775 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001776 }
Mike Stump11289f42009-09-09 15:08:12 +00001777
Douglas Gregora16548e2009-08-11 05:31:07 +00001778 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001779 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001780 /// By default, performs semantic analysis to build the new expression.
1781 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001782 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001783 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001784 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001785 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001786 }
1787
1788 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001789 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 /// By default, performs semantic analysis to build the new expression.
1791 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001792 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001793 SourceLocation QuestionLoc,
1794 Expr *LHS,
1795 SourceLocation ColonLoc,
1796 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001797 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1798 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001799 }
1800
Douglas Gregora16548e2009-08-11 05:31:07 +00001801 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001802 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001803 /// By default, performs semantic analysis to build the new expression.
1804 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001805 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001806 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001807 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001808 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001809 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001810 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001811 }
Mike Stump11289f42009-09-09 15:08:12 +00001812
Douglas Gregora16548e2009-08-11 05:31:07 +00001813 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001814 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001815 /// By default, performs semantic analysis to build the new expression.
1816 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001817 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001818 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001819 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001820 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001821 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001822 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001823 }
Mike Stump11289f42009-09-09 15:08:12 +00001824
Douglas Gregora16548e2009-08-11 05:31:07 +00001825 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001826 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001827 /// By default, performs semantic analysis to build the new expression.
1828 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001829 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001830 SourceLocation OpLoc,
1831 SourceLocation AccessorLoc,
1832 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001833
John McCall10eae182009-11-30 22:42:35 +00001834 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001835 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001836 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001837 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001838 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001839 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001840 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001841 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 }
Mike Stump11289f42009-09-09 15:08:12 +00001843
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001845 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001846 /// By default, performs semantic analysis to build the new expression.
1847 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001848 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001849 MultiExprArg Inits,
1850 SourceLocation RBraceLoc,
1851 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001852 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001853 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001854 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001855 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001856
Douglas Gregord3d93062009-11-09 17:16:50 +00001857 // Patch in the result type we were given, which may have been computed
1858 // when the initial InitListExpr was built.
1859 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1860 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001861 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001862 }
Mike Stump11289f42009-09-09 15:08:12 +00001863
Douglas Gregora16548e2009-08-11 05:31:07 +00001864 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001865 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001866 /// By default, performs semantic analysis to build the new expression.
1867 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001868 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001869 MultiExprArg ArrayExprs,
1870 SourceLocation EqualOrColonLoc,
1871 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001872 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001873 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001874 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001875 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001876 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001877 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001878
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001879 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001880 }
Mike Stump11289f42009-09-09 15:08:12 +00001881
Douglas Gregora16548e2009-08-11 05:31:07 +00001882 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001883 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001884 /// By default, builds the implicit value initialization without performing
1885 /// any semantic analysis. Subclasses may override this routine to provide
1886 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001887 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001888 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00001889 }
Mike Stump11289f42009-09-09 15:08:12 +00001890
Douglas Gregora16548e2009-08-11 05:31:07 +00001891 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001892 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001893 /// By default, performs semantic analysis to build the new expression.
1894 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001895 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001896 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001897 SourceLocation RParenLoc) {
1898 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001899 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001900 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001901 }
1902
1903 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001904 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001905 /// By default, performs semantic analysis to build the new expression.
1906 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001907 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001908 MultiExprArg SubExprs,
1909 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001910 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001911 }
Mike Stump11289f42009-09-09 15:08:12 +00001912
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001914 ///
1915 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001916 /// rather than attempting to map the label statement itself.
1917 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001918 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001919 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001920 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 }
Mike Stump11289f42009-09-09 15:08:12 +00001922
Douglas Gregora16548e2009-08-11 05:31:07 +00001923 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001924 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001925 /// By default, performs semantic analysis to build the new expression.
1926 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001927 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001928 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001930 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001931 }
Mike Stump11289f42009-09-09 15:08:12 +00001932
Douglas Gregora16548e2009-08-11 05:31:07 +00001933 /// \brief Build a new __builtin_choose_expr expression.
1934 ///
1935 /// By default, performs semantic analysis to build the new expression.
1936 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001937 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001938 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 SourceLocation RParenLoc) {
1940 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001941 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 RParenLoc);
1943 }
Mike Stump11289f42009-09-09 15:08:12 +00001944
Peter Collingbourne91147592011-04-15 00:35:48 +00001945 /// \brief Build a new generic selection expression.
1946 ///
1947 /// By default, performs semantic analysis to build the new expression.
1948 /// Subclasses may override this routine to provide different behavior.
1949 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1950 SourceLocation DefaultLoc,
1951 SourceLocation RParenLoc,
1952 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001953 ArrayRef<TypeSourceInfo *> Types,
1954 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001955 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001956 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00001957 }
1958
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 /// \brief Build a new overloaded operator call expression.
1960 ///
1961 /// By default, performs semantic analysis to build the new expression.
1962 /// The semantic analysis provides the behavior of template instantiation,
1963 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001964 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001965 /// argument-dependent lookup, etc. Subclasses may override this routine to
1966 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001967 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001969 Expr *Callee,
1970 Expr *First,
1971 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001972
1973 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 /// reinterpret_cast.
1975 ///
1976 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001977 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001979 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001980 Stmt::StmtClass Class,
1981 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001982 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 SourceLocation RAngleLoc,
1984 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001985 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001986 SourceLocation RParenLoc) {
1987 switch (Class) {
1988 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001989 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001990 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001991 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001992
1993 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001994 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001995 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001996 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001997
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001999 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002000 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002001 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002002 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002003
Douglas Gregora16548e2009-08-11 05:31:07 +00002004 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002005 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002006 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002007 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002008
Douglas Gregora16548e2009-08-11 05:31:07 +00002009 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002010 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002011 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002012 }
Mike Stump11289f42009-09-09 15:08:12 +00002013
Douglas Gregora16548e2009-08-11 05:31:07 +00002014 /// \brief Build a new C++ static_cast expression.
2015 ///
2016 /// By default, performs semantic analysis to build the new expression.
2017 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002018 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002020 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002021 SourceLocation RAngleLoc,
2022 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002023 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002024 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002025 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002026 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002027 SourceRange(LAngleLoc, RAngleLoc),
2028 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002029 }
2030
2031 /// \brief Build a new C++ dynamic_cast expression.
2032 ///
2033 /// By default, performs semantic analysis to build the new expression.
2034 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002035 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002036 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002037 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002038 SourceLocation RAngleLoc,
2039 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002040 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002041 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002042 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002043 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002044 SourceRange(LAngleLoc, RAngleLoc),
2045 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002046 }
2047
2048 /// \brief Build a new C++ reinterpret_cast expression.
2049 ///
2050 /// By default, performs semantic analysis to build the new expression.
2051 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002052 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002054 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002055 SourceLocation RAngleLoc,
2056 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002057 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002058 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002059 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002060 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002061 SourceRange(LAngleLoc, RAngleLoc),
2062 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002063 }
2064
2065 /// \brief Build a new C++ const_cast expression.
2066 ///
2067 /// By default, performs semantic analysis to build the new expression.
2068 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002069 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002070 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002071 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002072 SourceLocation RAngleLoc,
2073 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002074 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002075 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002076 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002077 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002078 SourceRange(LAngleLoc, RAngleLoc),
2079 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002080 }
Mike Stump11289f42009-09-09 15:08:12 +00002081
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 /// \brief Build a new C++ functional-style cast expression.
2083 ///
2084 /// By default, performs semantic analysis to build the new expression.
2085 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002086 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2087 SourceLocation LParenLoc,
2088 Expr *Sub,
2089 SourceLocation RParenLoc) {
2090 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002091 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002092 RParenLoc);
2093 }
Mike Stump11289f42009-09-09 15:08:12 +00002094
Douglas Gregora16548e2009-08-11 05:31:07 +00002095 /// \brief Build a new C++ typeid(type) expression.
2096 ///
2097 /// By default, performs semantic analysis to build the new expression.
2098 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002099 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002100 SourceLocation TypeidLoc,
2101 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002102 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002103 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002104 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002105 }
Mike Stump11289f42009-09-09 15:08:12 +00002106
Francois Pichet9f4f2072010-09-08 12:20:18 +00002107
Douglas Gregora16548e2009-08-11 05:31:07 +00002108 /// \brief Build a new C++ typeid(expr) expression.
2109 ///
2110 /// By default, performs semantic analysis to build the new expression.
2111 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002112 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002113 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002114 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002115 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002116 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002117 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002118 }
2119
Francois Pichet9f4f2072010-09-08 12:20:18 +00002120 /// \brief Build a new C++ __uuidof(type) expression.
2121 ///
2122 /// By default, performs semantic analysis to build the new expression.
2123 /// Subclasses may override this routine to provide different behavior.
2124 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2125 SourceLocation TypeidLoc,
2126 TypeSourceInfo *Operand,
2127 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002128 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002129 RParenLoc);
2130 }
2131
2132 /// \brief Build a new C++ __uuidof(expr) expression.
2133 ///
2134 /// By default, performs semantic analysis to build the new expression.
2135 /// Subclasses may override this routine to provide different behavior.
2136 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2137 SourceLocation TypeidLoc,
2138 Expr *Operand,
2139 SourceLocation RParenLoc) {
2140 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2141 RParenLoc);
2142 }
2143
Douglas Gregora16548e2009-08-11 05:31:07 +00002144 /// \brief Build a new C++ "this" expression.
2145 ///
2146 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002147 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002148 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002149 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002150 QualType ThisType,
2151 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002152 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002153 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002154 }
2155
2156 /// \brief Build a new C++ throw expression.
2157 ///
2158 /// By default, performs semantic analysis to build the new expression.
2159 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002160 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2161 bool IsThrownVariableInScope) {
2162 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002163 }
2164
2165 /// \brief Build a new C++ default-argument expression.
2166 ///
2167 /// By default, builds a new default-argument expression, which does not
2168 /// require any semantic analysis. Subclasses may override this routine to
2169 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002170 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002171 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002172 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 }
2174
Richard Smith852c9db2013-04-20 22:23:05 +00002175 /// \brief Build a new C++11 default-initialization expression.
2176 ///
2177 /// By default, builds a new default field initialization expression, which
2178 /// does not require any semantic analysis. Subclasses may override this
2179 /// routine to provide different behavior.
2180 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2181 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002182 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002183 }
2184
Douglas Gregora16548e2009-08-11 05:31:07 +00002185 /// \brief Build a new C++ zero-initialization expression.
2186 ///
2187 /// By default, performs semantic analysis to build the new expression.
2188 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002189 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2190 SourceLocation LParenLoc,
2191 SourceLocation RParenLoc) {
2192 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002193 None, 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++ "new" expression.
2197 ///
2198 /// By default, performs semantic analysis to build the new expression.
2199 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002200 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002201 bool UseGlobal,
2202 SourceLocation PlacementLParen,
2203 MultiExprArg PlacementArgs,
2204 SourceLocation PlacementRParen,
2205 SourceRange TypeIdParens,
2206 QualType AllocatedType,
2207 TypeSourceInfo *AllocatedTypeInfo,
2208 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002209 SourceRange DirectInitRange,
2210 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002211 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002212 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002213 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002214 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002215 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002216 AllocatedType,
2217 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002218 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002219 DirectInitRange,
2220 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002221 }
Mike Stump11289f42009-09-09 15:08:12 +00002222
Douglas Gregora16548e2009-08-11 05:31:07 +00002223 /// \brief Build a new C++ "delete" expression.
2224 ///
2225 /// By default, performs semantic analysis to build the new expression.
2226 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002227 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002228 bool IsGlobalDelete,
2229 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002230 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002231 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002232 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 }
Mike Stump11289f42009-09-09 15:08:12 +00002234
Douglas Gregor29c42f22012-02-24 07:38:34 +00002235 /// \brief Build a new type trait expression.
2236 ///
2237 /// By default, performs semantic analysis to build the new expression.
2238 /// Subclasses may override this routine to provide different behavior.
2239 ExprResult RebuildTypeTrait(TypeTrait Trait,
2240 SourceLocation StartLoc,
2241 ArrayRef<TypeSourceInfo *> Args,
2242 SourceLocation RParenLoc) {
2243 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2244 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002245
John Wiegley6242b6a2011-04-28 00:16:57 +00002246 /// \brief Build a new array type trait 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 RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2251 SourceLocation StartLoc,
2252 TypeSourceInfo *TSInfo,
2253 Expr *DimExpr,
2254 SourceLocation RParenLoc) {
2255 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2256 }
2257
John Wiegleyf9f65842011-04-25 06:54:41 +00002258 /// \brief Build a new expression trait expression.
2259 ///
2260 /// By default, performs semantic analysis to build the new expression.
2261 /// Subclasses may override this routine to provide different behavior.
2262 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2263 SourceLocation StartLoc,
2264 Expr *Queried,
2265 SourceLocation RParenLoc) {
2266 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2267 }
2268
Mike Stump11289f42009-09-09 15:08:12 +00002269 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002270 /// expression.
2271 ///
2272 /// By default, performs semantic analysis to build the new expression.
2273 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002274 ExprResult RebuildDependentScopeDeclRefExpr(
2275 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002276 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002277 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002278 const TemplateArgumentListInfo *TemplateArgs,
2279 bool IsAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002280 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002281 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002282
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002283 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnara7945c982012-01-27 09:46:47 +00002284 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002285 NameInfo, TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002286
Richard Smithdb2630f2012-10-21 03:28:35 +00002287 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2288 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002289 }
2290
2291 /// \brief Build a new template-id expression.
2292 ///
2293 /// By default, performs semantic analysis to build the new expression.
2294 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002295 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002296 SourceLocation TemplateKWLoc,
2297 LookupResult &R,
2298 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002299 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002300 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2301 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002302 }
2303
2304 /// \brief Build a new object-construction expression.
2305 ///
2306 /// By default, performs semantic analysis to build the new expression.
2307 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002308 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002309 SourceLocation Loc,
2310 CXXConstructorDecl *Constructor,
2311 bool IsElidable,
2312 MultiExprArg Args,
2313 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002314 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002315 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002316 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002317 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002318 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002319 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002320 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002321 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002322
Douglas Gregordb121ba2009-12-14 16:27:04 +00002323 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002324 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002325 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002326 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002327 RequiresZeroInit, ConstructKind,
2328 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002329 }
2330
2331 /// \brief Build a new object-construction expression.
2332 ///
2333 /// By default, performs semantic analysis to build the new expression.
2334 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002335 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2336 SourceLocation LParenLoc,
2337 MultiExprArg Args,
2338 SourceLocation RParenLoc) {
2339 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002340 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002341 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002342 RParenLoc);
2343 }
2344
2345 /// \brief Build a new object-construction expression.
2346 ///
2347 /// By default, performs semantic analysis to build the new expression.
2348 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002349 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2350 SourceLocation LParenLoc,
2351 MultiExprArg Args,
2352 SourceLocation RParenLoc) {
2353 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002354 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002355 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002356 RParenLoc);
2357 }
Mike Stump11289f42009-09-09 15:08:12 +00002358
Douglas Gregora16548e2009-08-11 05:31:07 +00002359 /// \brief Build a new member reference expression.
2360 ///
2361 /// By default, performs semantic analysis to build the new expression.
2362 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002363 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002364 QualType BaseType,
2365 bool IsArrow,
2366 SourceLocation OperatorLoc,
2367 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002368 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002369 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002370 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002371 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002372 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002373 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002374
John McCallb268a282010-08-23 23:25:46 +00002375 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002376 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002377 SS, TemplateKWLoc,
2378 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002379 MemberNameInfo,
2380 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002381 }
2382
John McCall10eae182009-11-30 22:42:35 +00002383 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002384 ///
2385 /// By default, performs semantic analysis to build the new expression.
2386 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002387 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2388 SourceLocation OperatorLoc,
2389 bool IsArrow,
2390 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002391 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002392 NamedDecl *FirstQualifierInScope,
2393 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002394 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002395 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002396 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002397
John McCallb268a282010-08-23 23:25:46 +00002398 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002399 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002400 SS, TemplateKWLoc,
2401 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002402 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002403 }
Mike Stump11289f42009-09-09 15:08:12 +00002404
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002405 /// \brief Build a new noexcept expression.
2406 ///
2407 /// By default, performs semantic analysis to build the new expression.
2408 /// Subclasses may override this routine to provide different behavior.
2409 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2410 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2411 }
2412
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002413 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002414 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2415 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002416 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002417 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002418 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002419 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2420 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002421 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002422
2423 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2424 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002425 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002426 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002427
Patrick Beard0caa3942012-04-19 00:25:12 +00002428 /// \brief Build a new Objective-C boxed expression.
2429 ///
2430 /// By default, performs semantic analysis to build the new expression.
2431 /// Subclasses may override this routine to provide different behavior.
2432 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2433 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2434 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002435
Ted Kremeneke65b0862012-03-06 20:05:56 +00002436 /// \brief Build a new Objective-C array literal.
2437 ///
2438 /// By default, performs semantic analysis to build the new expression.
2439 /// Subclasses may override this routine to provide different behavior.
2440 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2441 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002442 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002443 MultiExprArg(Elements, NumElements));
2444 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002445
2446 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002447 Expr *Base, Expr *Key,
2448 ObjCMethodDecl *getterMethod,
2449 ObjCMethodDecl *setterMethod) {
2450 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2451 getterMethod, setterMethod);
2452 }
2453
2454 /// \brief Build a new Objective-C dictionary literal.
2455 ///
2456 /// By default, performs semantic analysis to build the new expression.
2457 /// Subclasses may override this routine to provide different behavior.
2458 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2459 ObjCDictionaryElement *Elements,
2460 unsigned NumElements) {
2461 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2462 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002463
James Dennett2a4d13c2012-06-15 07:13:21 +00002464 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002465 ///
2466 /// By default, performs semantic analysis to build the new expression.
2467 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002468 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002469 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002470 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002471 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002472 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002473
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002474 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002475 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002476 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002477 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002478 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002479 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002480 MultiExprArg Args,
2481 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002482 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2483 ReceiverTypeInfo->getType(),
2484 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002485 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002486 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002487 }
2488
2489 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002490 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002491 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002492 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002493 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002494 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002495 MultiExprArg Args,
2496 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002497 return SemaRef.BuildInstanceMessage(Receiver,
2498 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002499 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002500 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002501 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002502 }
2503
Douglas Gregord51d90d2010-04-26 20:11:03 +00002504 /// \brief Build a new Objective-C ivar reference expression.
2505 ///
2506 /// By default, performs semantic analysis to build the new expression.
2507 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002508 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002509 SourceLocation IvarLoc,
2510 bool IsArrow, bool IsFreeIvar) {
2511 // FIXME: We lose track of the IsFreeIvar bit.
2512 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002513 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2514 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002515 /*FIXME:*/IvarLoc, IsArrow,
2516 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002517 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002518 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002519 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002520 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002521
2522 /// \brief Build a new Objective-C property reference expression.
2523 ///
2524 /// By default, performs semantic analysis to build the new expression.
2525 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002526 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002527 ObjCPropertyDecl *Property,
2528 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002529 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002530 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2531 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2532 /*FIXME:*/PropertyLoc,
2533 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002534 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002535 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002536 NameInfo,
2537 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002538 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002539
John McCallb7bd14f2010-12-02 01:19:52 +00002540 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002541 ///
2542 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002543 /// Subclasses may override this routine to provide different behavior.
2544 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2545 ObjCMethodDecl *Getter,
2546 ObjCMethodDecl *Setter,
2547 SourceLocation PropertyLoc) {
2548 // Since these expressions can only be value-dependent, we do not
2549 // need to perform semantic analysis again.
2550 return Owned(
2551 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2552 VK_LValue, OK_ObjCProperty,
2553 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002554 }
2555
Douglas Gregord51d90d2010-04-26 20:11:03 +00002556 /// \brief Build a new Objective-C "isa" expression.
2557 ///
2558 /// By default, performs semantic analysis to build the new expression.
2559 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002560 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002561 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002562 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002563 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2564 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002565 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002566 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002567 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002568 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002569 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002570 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002571
Douglas Gregora16548e2009-08-11 05:31:07 +00002572 /// \brief Build a new shuffle vector expression.
2573 ///
2574 /// By default, performs semantic analysis to build the new expression.
2575 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002576 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002577 MultiExprArg SubExprs,
2578 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002579 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002580 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002581 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2582 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2583 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002584 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002585
Douglas Gregora16548e2009-08-11 05:31:07 +00002586 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002587 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002588 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2589 SemaRef.Context.BuiltinFnTy,
2590 VK_RValue, BuiltinLoc);
2591 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2592 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002593 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002594
2595 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002596 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002597 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002598 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002599
Douglas Gregora16548e2009-08-11 05:31:07 +00002600 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002601 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002602 }
John McCall31f82722010-11-12 08:19:04 +00002603
Hal Finkelc4d7c822013-09-18 03:29:45 +00002604 /// \brief Build a new convert vector expression.
2605 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2606 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2607 SourceLocation RParenLoc) {
2608 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2609 BuiltinLoc, RParenLoc);
2610 }
2611
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002612 /// \brief Build a new template argument pack expansion.
2613 ///
2614 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002615 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002616 /// different behavior.
2617 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002618 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002619 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002620 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002621 case TemplateArgument::Expression: {
2622 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002623 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2624 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002625 if (Result.isInvalid())
2626 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002627
Douglas Gregor98318c22011-01-03 21:37:45 +00002628 return TemplateArgumentLoc(Result.get(), Result.get());
2629 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002630
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002631 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002632 return TemplateArgumentLoc(TemplateArgument(
2633 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002634 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002635 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002636 Pattern.getTemplateNameLoc(),
2637 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002638
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002639 case TemplateArgument::Null:
2640 case TemplateArgument::Integral:
2641 case TemplateArgument::Declaration:
2642 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002643 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002644 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002645 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002646
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002647 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002648 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002649 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002650 EllipsisLoc,
2651 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002652 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2653 Expansion);
2654 break;
2655 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002656
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002657 return TemplateArgumentLoc();
2658 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002659
Douglas Gregor968f23a2011-01-03 19:31:53 +00002660 /// \brief Build a new expression pack expansion.
2661 ///
2662 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002663 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002664 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002665 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002666 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002667 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002668 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002669
2670 /// \brief Build a new atomic operation expression.
2671 ///
2672 /// By default, performs semantic analysis to build the new expression.
2673 /// Subclasses may override this routine to provide different behavior.
2674 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2675 MultiExprArg SubExprs,
2676 QualType RetTy,
2677 AtomicExpr::AtomicOp Op,
2678 SourceLocation RParenLoc) {
2679 // Just create the expression; there is not any interesting semantic
2680 // analysis here because we can't actually build an AtomicExpr until
2681 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002682 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002683 RParenLoc);
2684 }
2685
John McCall31f82722010-11-12 08:19:04 +00002686private:
Douglas Gregor14454802011-02-25 02:25:35 +00002687 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2688 QualType ObjectType,
2689 NamedDecl *FirstQualifierInScope,
2690 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002691
2692 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2693 QualType ObjectType,
2694 NamedDecl *FirstQualifierInScope,
2695 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002696
2697 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2698 NamedDecl *FirstQualifierInScope,
2699 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002700};
Douglas Gregora16548e2009-08-11 05:31:07 +00002701
Douglas Gregorebe10102009-08-20 07:17:43 +00002702template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002703StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002704 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002705 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002706
Douglas Gregorebe10102009-08-20 07:17:43 +00002707 switch (S->getStmtClass()) {
2708 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002709
Douglas Gregorebe10102009-08-20 07:17:43 +00002710 // Transform individual statement nodes
2711#define STMT(Node, Parent) \
2712 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002713#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002714#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002715#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002716
Douglas Gregorebe10102009-08-20 07:17:43 +00002717 // Transform expressions by calling TransformExpr.
2718#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002719#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002720#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002721#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002722 {
John McCalldadc5752010-08-24 06:29:42 +00002723 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002724 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002725 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002726
Richard Smith945f8d32013-01-14 22:39:08 +00002727 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002728 }
Mike Stump11289f42009-09-09 15:08:12 +00002729 }
2730
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002731 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002732}
Mike Stump11289f42009-09-09 15:08:12 +00002733
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002734template<typename Derived>
2735OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2736 if (!S)
2737 return S;
2738
2739 switch (S->getClauseKind()) {
2740 default: break;
2741 // Transform individual clause nodes
2742#define OPENMP_CLAUSE(Name, Class) \
2743 case OMPC_ ## Name : \
2744 return getDerived().Transform ## Class(cast<Class>(S));
2745#include "clang/Basic/OpenMPKinds.def"
2746 }
2747
2748 return S;
2749}
2750
Mike Stump11289f42009-09-09 15:08:12 +00002751
Douglas Gregore922c772009-08-04 22:27:00 +00002752template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002753ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002754 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002755 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002756
2757 switch (E->getStmtClass()) {
2758 case Stmt::NoStmtClass: break;
2759#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002760#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002761#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002762 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002763#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002764 }
2765
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002766 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002767}
2768
2769template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002770ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2771 bool CXXDirectInit) {
2772 // Initializers are instantiated like expressions, except that various outer
2773 // layers are stripped.
2774 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002775 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002776
2777 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2778 Init = ExprTemp->getSubExpr();
2779
Richard Smithe6ca4752013-05-30 22:40:16 +00002780 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2781 Init = MTE->GetTemporaryExpr();
2782
Richard Smithd59b8322012-12-19 01:39:02 +00002783 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2784 Init = Binder->getSubExpr();
2785
2786 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2787 Init = ICE->getSubExprAsWritten();
2788
Richard Smithcc1b96d2013-06-12 22:31:48 +00002789 if (CXXStdInitializerListExpr *ILE =
2790 dyn_cast<CXXStdInitializerListExpr>(Init))
2791 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2792
Richard Smith38a549b2012-12-21 08:13:35 +00002793 // If this is not a direct-initializer, we only need to reconstruct
2794 // InitListExprs. Other forms of copy-initialization will be a no-op if
2795 // the initializer is already the right type.
2796 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2797 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2798 return getDerived().TransformExpr(Init);
2799
2800 // Revert value-initialization back to empty parens.
2801 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2802 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002803 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002804 Parens.getEnd());
2805 }
2806
2807 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2808 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002809 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002810 SourceLocation());
2811
2812 // Revert initialization by constructor back to a parenthesized or braced list
2813 // of expressions. Any other form of initializer can just be reused directly.
2814 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002815 return getDerived().TransformExpr(Init);
2816
2817 SmallVector<Expr*, 8> NewArgs;
2818 bool ArgChanged = false;
2819 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2820 /*IsCall*/true, NewArgs, &ArgChanged))
2821 return ExprError();
2822
2823 // If this was list initialization, revert to list form.
2824 if (Construct->isListInitialization())
2825 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2826 Construct->getLocEnd(),
2827 Construct->getType());
2828
Richard Smithd59b8322012-12-19 01:39:02 +00002829 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002830 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithd59b8322012-12-19 01:39:02 +00002831 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2832 Parens.getEnd());
2833}
2834
2835template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002836bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2837 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002838 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002839 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002840 bool *ArgChanged) {
2841 for (unsigned I = 0; I != NumInputs; ++I) {
2842 // If requested, drop call arguments that need to be dropped.
2843 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2844 if (ArgChanged)
2845 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002846
Douglas Gregora3efea12011-01-03 19:04:46 +00002847 break;
2848 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002849
Douglas Gregor968f23a2011-01-03 19:31:53 +00002850 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2851 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002852
Chris Lattner01cf8db2011-07-20 06:58:45 +00002853 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002854 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2855 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002856
Douglas Gregor968f23a2011-01-03 19:31:53 +00002857 // Determine whether the set of unexpanded parameter packs can and should
2858 // be expanded.
2859 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002860 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002861 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2862 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002863 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2864 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002865 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002866 Expand, RetainExpansion,
2867 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002868 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002869
Douglas Gregor968f23a2011-01-03 19:31:53 +00002870 if (!Expand) {
2871 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002872 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002873 // expansion.
2874 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2875 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2876 if (OutPattern.isInvalid())
2877 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002878
2879 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002880 Expansion->getEllipsisLoc(),
2881 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002882 if (Out.isInvalid())
2883 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002884
Douglas Gregor968f23a2011-01-03 19:31:53 +00002885 if (ArgChanged)
2886 *ArgChanged = true;
2887 Outputs.push_back(Out.get());
2888 continue;
2889 }
John McCall542e7c62011-07-06 07:30:07 +00002890
2891 // Record right away that the argument was changed. This needs
2892 // to happen even if the array expands to nothing.
2893 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002894
Douglas Gregor968f23a2011-01-03 19:31:53 +00002895 // The transform has determined that we should perform an elementwise
2896 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002897 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002898 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2899 ExprResult Out = getDerived().TransformExpr(Pattern);
2900 if (Out.isInvalid())
2901 return true;
2902
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002903 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002904 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2905 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002906 if (Out.isInvalid())
2907 return true;
2908 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002909
Douglas Gregor968f23a2011-01-03 19:31:53 +00002910 Outputs.push_back(Out.get());
2911 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002912
Douglas Gregor968f23a2011-01-03 19:31:53 +00002913 continue;
2914 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002915
Richard Smithd59b8322012-12-19 01:39:02 +00002916 ExprResult Result =
2917 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2918 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00002919 if (Result.isInvalid())
2920 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002921
Douglas Gregora3efea12011-01-03 19:04:46 +00002922 if (Result.get() != Inputs[I] && ArgChanged)
2923 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002924
2925 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00002926 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002927
Douglas Gregora3efea12011-01-03 19:04:46 +00002928 return false;
2929}
2930
2931template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002932NestedNameSpecifierLoc
2933TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2934 NestedNameSpecifierLoc NNS,
2935 QualType ObjectType,
2936 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002937 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00002938 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00002939 Qualifier = Qualifier.getPrefix())
2940 Qualifiers.push_back(Qualifier);
2941
2942 CXXScopeSpec SS;
2943 while (!Qualifiers.empty()) {
2944 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2945 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00002946
Douglas Gregor14454802011-02-25 02:25:35 +00002947 switch (QNNS->getKind()) {
2948 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00002949 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00002950 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002951 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002952 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002953 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00002954 FirstQualifierInScope, false))
2955 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002956
Douglas Gregor14454802011-02-25 02:25:35 +00002957 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002958
Douglas Gregor14454802011-02-25 02:25:35 +00002959 case NestedNameSpecifier::Namespace: {
2960 NamespaceDecl *NS
2961 = cast_or_null<NamespaceDecl>(
2962 getDerived().TransformDecl(
2963 Q.getLocalBeginLoc(),
2964 QNNS->getAsNamespace()));
2965 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2966 break;
2967 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002968
Douglas Gregor14454802011-02-25 02:25:35 +00002969 case NestedNameSpecifier::NamespaceAlias: {
2970 NamespaceAliasDecl *Alias
2971 = cast_or_null<NamespaceAliasDecl>(
2972 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2973 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00002974 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002975 Q.getLocalEndLoc());
2976 break;
2977 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002978
Douglas Gregor14454802011-02-25 02:25:35 +00002979 case NestedNameSpecifier::Global:
2980 // There is no meaningful transformation that one could perform on the
2981 // global scope.
2982 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2983 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002984
Douglas Gregor14454802011-02-25 02:25:35 +00002985 case NestedNameSpecifier::TypeSpecWithTemplate:
2986 case NestedNameSpecifier::TypeSpec: {
2987 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2988 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00002989
Douglas Gregor14454802011-02-25 02:25:35 +00002990 if (!TL)
2991 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002992
Douglas Gregor14454802011-02-25 02:25:35 +00002993 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00002994 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00002995 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002996 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00002997 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00002998 if (TL.getType()->isEnumeralType())
2999 SemaRef.Diag(TL.getBeginLoc(),
3000 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003001 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3002 Q.getLocalEndLoc());
3003 break;
3004 }
Richard Trieude756fb2011-05-07 01:36:37 +00003005 // If the nested-name-specifier is an invalid type def, don't emit an
3006 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003007 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3008 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003009 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003010 << TL.getType() << SS.getRange();
3011 }
Douglas Gregor14454802011-02-25 02:25:35 +00003012 return NestedNameSpecifierLoc();
3013 }
Douglas Gregore16af532011-02-28 18:50:33 +00003014 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003015
Douglas Gregore16af532011-02-28 18:50:33 +00003016 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003017 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003018 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003019 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003020
Douglas Gregor14454802011-02-25 02:25:35 +00003021 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003022 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003023 !getDerived().AlwaysRebuild())
3024 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003025
3026 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003027 // nested-name-specifier, do so.
3028 if (SS.location_size() == NNS.getDataLength() &&
3029 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3030 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3031
3032 // Allocate new nested-name-specifier location information.
3033 return SS.getWithLocInContext(SemaRef.Context);
3034}
3035
3036template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003037DeclarationNameInfo
3038TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003039::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003040 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003041 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003042 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003043
3044 switch (Name.getNameKind()) {
3045 case DeclarationName::Identifier:
3046 case DeclarationName::ObjCZeroArgSelector:
3047 case DeclarationName::ObjCOneArgSelector:
3048 case DeclarationName::ObjCMultiArgSelector:
3049 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003050 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003051 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003052 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003053
Douglas Gregorf816bd72009-09-03 22:13:48 +00003054 case DeclarationName::CXXConstructorName:
3055 case DeclarationName::CXXDestructorName:
3056 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003057 TypeSourceInfo *NewTInfo;
3058 CanQualType NewCanTy;
3059 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003060 NewTInfo = getDerived().TransformType(OldTInfo);
3061 if (!NewTInfo)
3062 return DeclarationNameInfo();
3063 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003064 }
3065 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003066 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003067 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003068 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003069 if (NewT.isNull())
3070 return DeclarationNameInfo();
3071 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3072 }
Mike Stump11289f42009-09-09 15:08:12 +00003073
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003074 DeclarationName NewName
3075 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3076 NewCanTy);
3077 DeclarationNameInfo NewNameInfo(NameInfo);
3078 NewNameInfo.setName(NewName);
3079 NewNameInfo.setNamedTypeInfo(NewTInfo);
3080 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003081 }
Mike Stump11289f42009-09-09 15:08:12 +00003082 }
3083
David Blaikie83d382b2011-09-23 05:06:16 +00003084 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003085}
3086
3087template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003088TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003089TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3090 TemplateName Name,
3091 SourceLocation NameLoc,
3092 QualType ObjectType,
3093 NamedDecl *FirstQualifierInScope) {
3094 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3095 TemplateDecl *Template = QTN->getTemplateDecl();
3096 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003097
Douglas Gregor9db53502011-03-02 18:07:45 +00003098 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003099 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003100 Template));
3101 if (!TransTemplate)
3102 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003103
Douglas Gregor9db53502011-03-02 18:07:45 +00003104 if (!getDerived().AlwaysRebuild() &&
3105 SS.getScopeRep() == QTN->getQualifier() &&
3106 TransTemplate == Template)
3107 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003108
Douglas Gregor9db53502011-03-02 18:07:45 +00003109 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3110 TransTemplate);
3111 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003112
Douglas Gregor9db53502011-03-02 18:07:45 +00003113 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3114 if (SS.getScopeRep()) {
3115 // These apply to the scope specifier, not the template.
3116 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003117 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003118 }
3119
Douglas Gregor9db53502011-03-02 18:07:45 +00003120 if (!getDerived().AlwaysRebuild() &&
3121 SS.getScopeRep() == DTN->getQualifier() &&
3122 ObjectType.isNull())
3123 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003124
Douglas Gregor9db53502011-03-02 18:07:45 +00003125 if (DTN->isIdentifier()) {
3126 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003127 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003128 NameLoc,
3129 ObjectType,
3130 FirstQualifierInScope);
3131 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003132
Douglas Gregor9db53502011-03-02 18:07:45 +00003133 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3134 ObjectType);
3135 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003136
Douglas Gregor9db53502011-03-02 18:07:45 +00003137 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3138 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003139 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003140 Template));
3141 if (!TransTemplate)
3142 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003143
Douglas Gregor9db53502011-03-02 18:07:45 +00003144 if (!getDerived().AlwaysRebuild() &&
3145 TransTemplate == Template)
3146 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003147
Douglas Gregor9db53502011-03-02 18:07:45 +00003148 return TemplateName(TransTemplate);
3149 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003150
Douglas Gregor9db53502011-03-02 18:07:45 +00003151 if (SubstTemplateTemplateParmPackStorage *SubstPack
3152 = Name.getAsSubstTemplateTemplateParmPack()) {
3153 TemplateTemplateParmDecl *TransParam
3154 = cast_or_null<TemplateTemplateParmDecl>(
3155 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3156 if (!TransParam)
3157 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003158
Douglas Gregor9db53502011-03-02 18:07:45 +00003159 if (!getDerived().AlwaysRebuild() &&
3160 TransParam == SubstPack->getParameterPack())
3161 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003162
3163 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003164 SubstPack->getArgumentPack());
3165 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003166
Douglas Gregor9db53502011-03-02 18:07:45 +00003167 // These should be getting filtered out before they reach the AST.
3168 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003169}
3170
3171template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003172void TreeTransform<Derived>::InventTemplateArgumentLoc(
3173 const TemplateArgument &Arg,
3174 TemplateArgumentLoc &Output) {
3175 SourceLocation Loc = getDerived().getBaseLocation();
3176 switch (Arg.getKind()) {
3177 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003178 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003179 break;
3180
3181 case TemplateArgument::Type:
3182 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003183 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003184
John McCall0ad16662009-10-29 08:12:44 +00003185 break;
3186
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003187 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003188 case TemplateArgument::TemplateExpansion: {
3189 NestedNameSpecifierLocBuilder Builder;
3190 TemplateName Template = Arg.getAsTemplate();
3191 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3192 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3193 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3194 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003195
Douglas Gregor9d802122011-03-02 17:09:35 +00003196 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003197 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003198 Builder.getWithLocInContext(SemaRef.Context),
3199 Loc);
3200 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003201 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003202 Builder.getWithLocInContext(SemaRef.Context),
3203 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003204
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003205 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003206 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003207
John McCall0ad16662009-10-29 08:12:44 +00003208 case TemplateArgument::Expression:
3209 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3210 break;
3211
3212 case TemplateArgument::Declaration:
3213 case TemplateArgument::Integral:
3214 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003215 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003216 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003217 break;
3218 }
3219}
3220
3221template<typename Derived>
3222bool TreeTransform<Derived>::TransformTemplateArgument(
3223 const TemplateArgumentLoc &Input,
3224 TemplateArgumentLoc &Output) {
3225 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003226 switch (Arg.getKind()) {
3227 case TemplateArgument::Null:
3228 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003229 case TemplateArgument::Pack:
3230 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003231 case TemplateArgument::NullPtr:
3232 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003233
Douglas Gregore922c772009-08-04 22:27:00 +00003234 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003235 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003236 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003237 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003238
3239 DI = getDerived().TransformType(DI);
3240 if (!DI) return true;
3241
3242 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3243 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003244 }
Mike Stump11289f42009-09-09 15:08:12 +00003245
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003246 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003247 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3248 if (QualifierLoc) {
3249 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3250 if (!QualifierLoc)
3251 return true;
3252 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003253
Douglas Gregordf846d12011-03-02 18:46:51 +00003254 CXXScopeSpec SS;
3255 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003256 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003257 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3258 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003259 if (Template.isNull())
3260 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003261
Douglas Gregor9d802122011-03-02 17:09:35 +00003262 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003263 Input.getTemplateNameLoc());
3264 return false;
3265 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003266
3267 case TemplateArgument::TemplateExpansion:
3268 llvm_unreachable("Caller should expand pack expansions");
3269
Douglas Gregore922c772009-08-04 22:27:00 +00003270 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003271 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003272 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003273 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003274
John McCall0ad16662009-10-29 08:12:44 +00003275 Expr *InputExpr = Input.getSourceExpression();
3276 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3277
Chris Lattnercdb591a2011-04-25 20:37:58 +00003278 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003279 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003280 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003281 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003282 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003283 }
Douglas Gregore922c772009-08-04 22:27:00 +00003284 }
Mike Stump11289f42009-09-09 15:08:12 +00003285
Douglas Gregore922c772009-08-04 22:27:00 +00003286 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003287 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003288}
3289
Douglas Gregorfe921a72010-12-20 23:36:19 +00003290/// \brief Iterator adaptor that invents template argument location information
3291/// for each of the template arguments in its underlying iterator.
3292template<typename Derived, typename InputIterator>
3293class TemplateArgumentLocInventIterator {
3294 TreeTransform<Derived> &Self;
3295 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003296
Douglas Gregorfe921a72010-12-20 23:36:19 +00003297public:
3298 typedef TemplateArgumentLoc value_type;
3299 typedef TemplateArgumentLoc reference;
3300 typedef typename std::iterator_traits<InputIterator>::difference_type
3301 difference_type;
3302 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003303
Douglas Gregorfe921a72010-12-20 23:36:19 +00003304 class pointer {
3305 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003306
Douglas Gregorfe921a72010-12-20 23:36:19 +00003307 public:
3308 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003309
Douglas Gregorfe921a72010-12-20 23:36:19 +00003310 const TemplateArgumentLoc *operator->() const { return &Arg; }
3311 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003312
Douglas Gregorfe921a72010-12-20 23:36:19 +00003313 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003314
Douglas Gregorfe921a72010-12-20 23:36:19 +00003315 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3316 InputIterator Iter)
3317 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003318
Douglas Gregorfe921a72010-12-20 23:36:19 +00003319 TemplateArgumentLocInventIterator &operator++() {
3320 ++Iter;
3321 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003322 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003323
Douglas Gregorfe921a72010-12-20 23:36:19 +00003324 TemplateArgumentLocInventIterator operator++(int) {
3325 TemplateArgumentLocInventIterator Old(*this);
3326 ++(*this);
3327 return Old;
3328 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003329
Douglas Gregorfe921a72010-12-20 23:36:19 +00003330 reference operator*() const {
3331 TemplateArgumentLoc Result;
3332 Self.InventTemplateArgumentLoc(*Iter, Result);
3333 return Result;
3334 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003335
Douglas Gregorfe921a72010-12-20 23:36:19 +00003336 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003337
Douglas Gregorfe921a72010-12-20 23:36:19 +00003338 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3339 const TemplateArgumentLocInventIterator &Y) {
3340 return X.Iter == Y.Iter;
3341 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003342
Douglas Gregorfe921a72010-12-20 23:36:19 +00003343 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3344 const TemplateArgumentLocInventIterator &Y) {
3345 return X.Iter != Y.Iter;
3346 }
3347};
Chad Rosier1dcde962012-08-08 18:46:20 +00003348
Douglas Gregor42cafa82010-12-20 17:42:22 +00003349template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003350template<typename InputIterator>
3351bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3352 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003353 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003354 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003355 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003356 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003357
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003358 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3359 // Unpack argument packs, which we translate them into separate
3360 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003361 // FIXME: We could do much better if we could guarantee that the
3362 // TemplateArgumentLocInfo for the pack expansion would be usable for
3363 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003364 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003365 TemplateArgument::pack_iterator>
3366 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003367 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003368 In.getArgument().pack_begin()),
3369 PackLocIterator(*this,
3370 In.getArgument().pack_end()),
3371 Outputs))
3372 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003373
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003374 continue;
3375 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003376
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003377 if (In.getArgument().isPackExpansion()) {
3378 // We have a pack expansion, for which we will be substituting into
3379 // the pattern.
3380 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003381 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003382 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003383 = getSema().getTemplateArgumentPackExpansionPattern(
3384 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003385
Chris Lattner01cf8db2011-07-20 06:58:45 +00003386 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003387 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3388 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003389
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003390 // Determine whether the set of unexpanded parameter packs can and should
3391 // be expanded.
3392 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003393 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003394 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003395 if (getDerived().TryExpandParameterPacks(Ellipsis,
3396 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003397 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003398 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003399 RetainExpansion,
3400 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003401 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003402
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003403 if (!Expand) {
3404 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003405 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003406 // expansion.
3407 TemplateArgumentLoc OutPattern;
3408 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3409 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3410 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003411
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003412 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3413 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003414 if (Out.getArgument().isNull())
3415 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003416
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003417 Outputs.addArgument(Out);
3418 continue;
3419 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003420
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003421 // The transform has determined that we should perform an elementwise
3422 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003423 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003424 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3425
3426 if (getDerived().TransformTemplateArgument(Pattern, Out))
3427 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003428
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003429 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003430 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3431 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003432 if (Out.getArgument().isNull())
3433 return true;
3434 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003435
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003436 Outputs.addArgument(Out);
3437 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003438
Douglas Gregor48d24112011-01-10 20:53:55 +00003439 // If we're supposed to retain a pack expansion, do so by temporarily
3440 // forgetting the partially-substituted parameter pack.
3441 if (RetainExpansion) {
3442 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003443
Douglas Gregor48d24112011-01-10 20:53:55 +00003444 if (getDerived().TransformTemplateArgument(Pattern, Out))
3445 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003446
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003447 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3448 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003449 if (Out.getArgument().isNull())
3450 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003451
Douglas Gregor48d24112011-01-10 20:53:55 +00003452 Outputs.addArgument(Out);
3453 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003454
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003455 continue;
3456 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003457
3458 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003459 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003460 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003461
Douglas Gregor42cafa82010-12-20 17:42:22 +00003462 Outputs.addArgument(Out);
3463 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003464
Douglas Gregor42cafa82010-12-20 17:42:22 +00003465 return false;
3466
3467}
3468
Douglas Gregord6ff3322009-08-04 16:50:30 +00003469//===----------------------------------------------------------------------===//
3470// Type transformation
3471//===----------------------------------------------------------------------===//
3472
3473template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003474QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003475 if (getDerived().AlreadyTransformed(T))
3476 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003477
John McCall550e0c22009-10-21 00:40:46 +00003478 // Temporary workaround. All of these transformations should
3479 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003480 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3481 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003482
John McCall31f82722010-11-12 08:19:04 +00003483 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003484
John McCall550e0c22009-10-21 00:40:46 +00003485 if (!NewDI)
3486 return QualType();
3487
3488 return NewDI->getType();
3489}
3490
3491template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003492TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003493 // Refine the base location to the type's location.
3494 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3495 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003496 if (getDerived().AlreadyTransformed(DI->getType()))
3497 return DI;
3498
3499 TypeLocBuilder TLB;
3500
3501 TypeLoc TL = DI->getTypeLoc();
3502 TLB.reserve(TL.getFullDataSize());
3503
John McCall31f82722010-11-12 08:19:04 +00003504 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003505 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003506 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003507
John McCallbcd03502009-12-07 02:54:59 +00003508 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003509}
3510
3511template<typename Derived>
3512QualType
John McCall31f82722010-11-12 08:19:04 +00003513TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003514 switch (T.getTypeLocClass()) {
3515#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003516#define TYPELOC(CLASS, PARENT) \
3517 case TypeLoc::CLASS: \
3518 return getDerived().Transform##CLASS##Type(TLB, \
3519 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003520#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003521 }
Mike Stump11289f42009-09-09 15:08:12 +00003522
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003523 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003524}
3525
3526/// FIXME: By default, this routine adds type qualifiers only to types
3527/// that can have qualifiers, and silently suppresses those qualifiers
3528/// that are not permitted (e.g., qualifiers on reference or function
3529/// types). This is the right thing for template instantiation, but
3530/// probably not for other clients.
3531template<typename Derived>
3532QualType
3533TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003534 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003535 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003536
John McCall31f82722010-11-12 08:19:04 +00003537 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003538 if (Result.isNull())
3539 return QualType();
3540
3541 // Silently suppress qualifiers if the result type can't be qualified.
3542 // FIXME: this is the right thing for template instantiation, but
3543 // probably not for other clients.
3544 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003545 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003546
John McCall31168b02011-06-15 23:02:42 +00003547 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003548 // resulting type.
3549 if (Quals.hasObjCLifetime()) {
3550 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3551 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003552 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003553 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003554 // A lifetime qualifier applied to a substituted template parameter
3555 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003556 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003557 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003558 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3559 QualType Replacement = SubstTypeParam->getReplacementType();
3560 Qualifiers Qs = Replacement.getQualifiers();
3561 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003562 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003563 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3564 Qs);
3565 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003566 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003567 Replacement);
3568 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003569 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3570 // 'auto' types behave the same way as template parameters.
3571 QualType Deduced = AutoTy->getDeducedType();
3572 Qualifiers Qs = Deduced.getQualifiers();
3573 Qs.removeObjCLifetime();
3574 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3575 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003576 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3577 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003578 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003579 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003580 // Otherwise, complain about the addition of a qualifier to an
3581 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003582 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003583 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003584 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003585
Douglas Gregore46db902011-06-17 22:11:49 +00003586 Quals.removeObjCLifetime();
3587 }
3588 }
3589 }
John McCallcb0f89a2010-06-05 06:41:15 +00003590 if (!Quals.empty()) {
3591 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003592 // BuildQualifiedType might not add qualifiers if they are invalid.
3593 if (Result.hasLocalQualifiers())
3594 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003595 // No location information to preserve.
3596 }
John McCall550e0c22009-10-21 00:40:46 +00003597
3598 return Result;
3599}
3600
Douglas Gregor14454802011-02-25 02:25:35 +00003601template<typename Derived>
3602TypeLoc
3603TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3604 QualType ObjectType,
3605 NamedDecl *UnqualLookup,
3606 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003607 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003608 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003609
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003610 TypeSourceInfo *TSI =
3611 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3612 if (TSI)
3613 return TSI->getTypeLoc();
3614 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003615}
3616
Douglas Gregor579c15f2011-03-02 18:32:08 +00003617template<typename Derived>
3618TypeSourceInfo *
3619TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3620 QualType ObjectType,
3621 NamedDecl *UnqualLookup,
3622 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003623 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003624 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003625
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003626 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3627 UnqualLookup, SS);
3628}
3629
3630template <typename Derived>
3631TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3632 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3633 CXXScopeSpec &SS) {
3634 QualType T = TL.getType();
3635 assert(!getDerived().AlreadyTransformed(T));
3636
Douglas Gregor579c15f2011-03-02 18:32:08 +00003637 TypeLocBuilder TLB;
3638 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003639
Douglas Gregor579c15f2011-03-02 18:32:08 +00003640 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003641 TemplateSpecializationTypeLoc SpecTL =
3642 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003643
Douglas Gregor579c15f2011-03-02 18:32:08 +00003644 TemplateName Template
3645 = getDerived().TransformTemplateName(SS,
3646 SpecTL.getTypePtr()->getTemplateName(),
3647 SpecTL.getTemplateNameLoc(),
3648 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003649 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003650 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003651
3652 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003653 Template);
3654 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003655 DependentTemplateSpecializationTypeLoc SpecTL =
3656 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003657
Douglas Gregor579c15f2011-03-02 18:32:08 +00003658 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003659 = getDerived().RebuildTemplateName(SS,
3660 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003661 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003662 ObjectType, UnqualLookup);
3663 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003664 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003665
3666 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003667 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003668 Template,
3669 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003670 } else {
3671 // Nothing special needs to be done for these.
3672 Result = getDerived().TransformType(TLB, TL);
3673 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003674
3675 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003676 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003677
Douglas Gregor579c15f2011-03-02 18:32:08 +00003678 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3679}
3680
John McCall550e0c22009-10-21 00:40:46 +00003681template <class TyLoc> static inline
3682QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3683 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3684 NewT.setNameLoc(T.getNameLoc());
3685 return T.getType();
3686}
3687
John McCall550e0c22009-10-21 00:40:46 +00003688template<typename Derived>
3689QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003690 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003691 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3692 NewT.setBuiltinLoc(T.getBuiltinLoc());
3693 if (T.needsExtraLocalData())
3694 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3695 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003696}
Mike Stump11289f42009-09-09 15:08:12 +00003697
Douglas Gregord6ff3322009-08-04 16:50:30 +00003698template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003699QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003700 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003701 // FIXME: recurse?
3702 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003703}
Mike Stump11289f42009-09-09 15:08:12 +00003704
Reid Kleckner0503a872013-12-05 01:23:43 +00003705template <typename Derived>
3706QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3707 AdjustedTypeLoc TL) {
3708 // Adjustments applied during transformation are handled elsewhere.
3709 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3710}
3711
Douglas Gregord6ff3322009-08-04 16:50:30 +00003712template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003713QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3714 DecayedTypeLoc TL) {
3715 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3716 if (OriginalType.isNull())
3717 return QualType();
3718
3719 QualType Result = TL.getType();
3720 if (getDerived().AlwaysRebuild() ||
3721 OriginalType != TL.getOriginalLoc().getType())
3722 Result = SemaRef.Context.getDecayedType(OriginalType);
3723 TLB.push<DecayedTypeLoc>(Result);
3724 // Nothing to set for DecayedTypeLoc.
3725 return Result;
3726}
3727
3728template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003729QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003730 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003731 QualType PointeeType
3732 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003733 if (PointeeType.isNull())
3734 return QualType();
3735
3736 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003737 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003738 // A dependent pointer type 'T *' has is being transformed such
3739 // that an Objective-C class type is being replaced for 'T'. The
3740 // resulting pointer type is an ObjCObjectPointerType, not a
3741 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003742 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003743
John McCall8b07ec22010-05-15 11:32:37 +00003744 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3745 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003746 return Result;
3747 }
John McCall31f82722010-11-12 08:19:04 +00003748
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003749 if (getDerived().AlwaysRebuild() ||
3750 PointeeType != TL.getPointeeLoc().getType()) {
3751 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3752 if (Result.isNull())
3753 return QualType();
3754 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003755
John McCall31168b02011-06-15 23:02:42 +00003756 // Objective-C ARC can add lifetime qualifiers to the type that we're
3757 // pointing to.
3758 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003759
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003760 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3761 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003762 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003763}
Mike Stump11289f42009-09-09 15:08:12 +00003764
3765template<typename Derived>
3766QualType
John McCall550e0c22009-10-21 00:40:46 +00003767TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003768 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003769 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003770 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3771 if (PointeeType.isNull())
3772 return QualType();
3773
3774 QualType Result = TL.getType();
3775 if (getDerived().AlwaysRebuild() ||
3776 PointeeType != TL.getPointeeLoc().getType()) {
3777 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003778 TL.getSigilLoc());
3779 if (Result.isNull())
3780 return QualType();
3781 }
3782
Douglas Gregor049211a2010-04-22 16:50:51 +00003783 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003784 NewT.setSigilLoc(TL.getSigilLoc());
3785 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003786}
3787
John McCall70dd5f62009-10-30 00:06:24 +00003788/// Transforms a reference type. Note that somewhat paradoxically we
3789/// don't care whether the type itself is an l-value type or an r-value
3790/// type; we only care if the type was *written* as an l-value type
3791/// or an r-value type.
3792template<typename Derived>
3793QualType
3794TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003795 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003796 const ReferenceType *T = TL.getTypePtr();
3797
3798 // Note that this works with the pointee-as-written.
3799 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3800 if (PointeeType.isNull())
3801 return QualType();
3802
3803 QualType Result = TL.getType();
3804 if (getDerived().AlwaysRebuild() ||
3805 PointeeType != T->getPointeeTypeAsWritten()) {
3806 Result = getDerived().RebuildReferenceType(PointeeType,
3807 T->isSpelledAsLValue(),
3808 TL.getSigilLoc());
3809 if (Result.isNull())
3810 return QualType();
3811 }
3812
John McCall31168b02011-06-15 23:02:42 +00003813 // Objective-C ARC can add lifetime qualifiers to the type that we're
3814 // referring to.
3815 TLB.TypeWasModifiedSafely(
3816 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3817
John McCall70dd5f62009-10-30 00:06:24 +00003818 // r-value references can be rebuilt as l-value references.
3819 ReferenceTypeLoc NewTL;
3820 if (isa<LValueReferenceType>(Result))
3821 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3822 else
3823 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3824 NewTL.setSigilLoc(TL.getSigilLoc());
3825
3826 return Result;
3827}
3828
Mike Stump11289f42009-09-09 15:08:12 +00003829template<typename Derived>
3830QualType
John McCall550e0c22009-10-21 00:40:46 +00003831TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003832 LValueReferenceTypeLoc TL) {
3833 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003834}
3835
Mike Stump11289f42009-09-09 15:08:12 +00003836template<typename Derived>
3837QualType
John McCall550e0c22009-10-21 00:40:46 +00003838TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003839 RValueReferenceTypeLoc TL) {
3840 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003841}
Mike Stump11289f42009-09-09 15:08:12 +00003842
Douglas Gregord6ff3322009-08-04 16:50:30 +00003843template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003844QualType
John McCall550e0c22009-10-21 00:40:46 +00003845TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003846 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003847 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003848 if (PointeeType.isNull())
3849 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003850
Abramo Bagnara509357842011-03-05 14:42:21 +00003851 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003852 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00003853 if (OldClsTInfo) {
3854 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3855 if (!NewClsTInfo)
3856 return QualType();
3857 }
3858
3859 const MemberPointerType *T = TL.getTypePtr();
3860 QualType OldClsType = QualType(T->getClass(), 0);
3861 QualType NewClsType;
3862 if (NewClsTInfo)
3863 NewClsType = NewClsTInfo->getType();
3864 else {
3865 NewClsType = getDerived().TransformType(OldClsType);
3866 if (NewClsType.isNull())
3867 return QualType();
3868 }
Mike Stump11289f42009-09-09 15:08:12 +00003869
John McCall550e0c22009-10-21 00:40:46 +00003870 QualType Result = TL.getType();
3871 if (getDerived().AlwaysRebuild() ||
3872 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003873 NewClsType != OldClsType) {
3874 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003875 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003876 if (Result.isNull())
3877 return QualType();
3878 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003879
Reid Kleckner0503a872013-12-05 01:23:43 +00003880 // If we had to adjust the pointee type when building a member pointer, make
3881 // sure to push TypeLoc info for it.
3882 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3883 if (MPT && PointeeType != MPT->getPointeeType()) {
3884 assert(isa<AdjustedType>(MPT->getPointeeType()));
3885 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3886 }
3887
John McCall550e0c22009-10-21 00:40:46 +00003888 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3889 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003890 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003891
3892 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003893}
3894
Mike Stump11289f42009-09-09 15:08:12 +00003895template<typename Derived>
3896QualType
John McCall550e0c22009-10-21 00:40:46 +00003897TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003898 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003899 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003900 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003901 if (ElementType.isNull())
3902 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003903
John McCall550e0c22009-10-21 00:40:46 +00003904 QualType Result = TL.getType();
3905 if (getDerived().AlwaysRebuild() ||
3906 ElementType != T->getElementType()) {
3907 Result = getDerived().RebuildConstantArrayType(ElementType,
3908 T->getSizeModifier(),
3909 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003910 T->getIndexTypeCVRQualifiers(),
3911 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003912 if (Result.isNull())
3913 return QualType();
3914 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00003915
3916 // We might have either a ConstantArrayType or a VariableArrayType now:
3917 // a ConstantArrayType is allowed to have an element type which is a
3918 // VariableArrayType if the type is dependent. Fortunately, all array
3919 // types have the same location layout.
3920 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003921 NewTL.setLBracketLoc(TL.getLBracketLoc());
3922 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003923
John McCall550e0c22009-10-21 00:40:46 +00003924 Expr *Size = TL.getSizeExpr();
3925 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003926 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3927 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003928 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
3929 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00003930 }
3931 NewTL.setSizeExpr(Size);
3932
3933 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003934}
Mike Stump11289f42009-09-09 15:08:12 +00003935
Douglas Gregord6ff3322009-08-04 16:50:30 +00003936template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003937QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003938 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003939 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003940 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003941 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003942 if (ElementType.isNull())
3943 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003944
John McCall550e0c22009-10-21 00:40:46 +00003945 QualType Result = TL.getType();
3946 if (getDerived().AlwaysRebuild() ||
3947 ElementType != T->getElementType()) {
3948 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003949 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003950 T->getIndexTypeCVRQualifiers(),
3951 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003952 if (Result.isNull())
3953 return QualType();
3954 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003955
John McCall550e0c22009-10-21 00:40:46 +00003956 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3957 NewTL.setLBracketLoc(TL.getLBracketLoc());
3958 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00003959 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00003960
3961 return Result;
3962}
3963
3964template<typename Derived>
3965QualType
3966TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003967 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003968 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003969 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3970 if (ElementType.isNull())
3971 return QualType();
3972
John McCalldadc5752010-08-24 06:29:42 +00003973 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003974 = getDerived().TransformExpr(T->getSizeExpr());
3975 if (SizeResult.isInvalid())
3976 return QualType();
3977
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003978 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003979
3980 QualType Result = TL.getType();
3981 if (getDerived().AlwaysRebuild() ||
3982 ElementType != T->getElementType() ||
3983 Size != T->getSizeExpr()) {
3984 Result = getDerived().RebuildVariableArrayType(ElementType,
3985 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003986 Size,
John McCall550e0c22009-10-21 00:40:46 +00003987 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003988 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003989 if (Result.isNull())
3990 return QualType();
3991 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003992
Serge Pavlov774c6d02014-02-06 03:49:11 +00003993 // We might have constant size array now, but fortunately it has the same
3994 // location layout.
3995 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003996 NewTL.setLBracketLoc(TL.getLBracketLoc());
3997 NewTL.setRBracketLoc(TL.getRBracketLoc());
3998 NewTL.setSizeExpr(Size);
3999
4000 return Result;
4001}
4002
4003template<typename Derived>
4004QualType
4005TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004006 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004007 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004008 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4009 if (ElementType.isNull())
4010 return QualType();
4011
Richard Smith764d2fe2011-12-20 02:08:33 +00004012 // Array bounds are constant expressions.
4013 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4014 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004015
John McCall33ddac02011-01-19 10:06:00 +00004016 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4017 Expr *origSize = TL.getSizeExpr();
4018 if (!origSize) origSize = T->getSizeExpr();
4019
4020 ExprResult sizeResult
4021 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004022 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004023 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004024 return QualType();
4025
John McCall33ddac02011-01-19 10:06:00 +00004026 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004027
4028 QualType Result = TL.getType();
4029 if (getDerived().AlwaysRebuild() ||
4030 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004031 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004032 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4033 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004034 size,
John McCall550e0c22009-10-21 00:40:46 +00004035 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004036 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004037 if (Result.isNull())
4038 return QualType();
4039 }
John McCall550e0c22009-10-21 00:40:46 +00004040
4041 // We might have any sort of array type now, but fortunately they
4042 // all have the same location layout.
4043 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4044 NewTL.setLBracketLoc(TL.getLBracketLoc());
4045 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004046 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004047
4048 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004049}
Mike Stump11289f42009-09-09 15:08:12 +00004050
4051template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004052QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004053 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004054 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004055 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004056
4057 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004058 QualType ElementType = getDerived().TransformType(T->getElementType());
4059 if (ElementType.isNull())
4060 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004061
Richard Smith764d2fe2011-12-20 02:08:33 +00004062 // Vector sizes are constant expressions.
4063 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4064 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004065
John McCalldadc5752010-08-24 06:29:42 +00004066 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004067 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004068 if (Size.isInvalid())
4069 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004070
John McCall550e0c22009-10-21 00:40:46 +00004071 QualType Result = TL.getType();
4072 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004073 ElementType != T->getElementType() ||
4074 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004075 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004076 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004077 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004078 if (Result.isNull())
4079 return QualType();
4080 }
John McCall550e0c22009-10-21 00:40:46 +00004081
4082 // Result might be dependent or not.
4083 if (isa<DependentSizedExtVectorType>(Result)) {
4084 DependentSizedExtVectorTypeLoc NewTL
4085 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4086 NewTL.setNameLoc(TL.getNameLoc());
4087 } else {
4088 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4089 NewTL.setNameLoc(TL.getNameLoc());
4090 }
4091
4092 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004093}
Mike Stump11289f42009-09-09 15:08:12 +00004094
4095template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004096QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004097 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004098 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004099 QualType ElementType = getDerived().TransformType(T->getElementType());
4100 if (ElementType.isNull())
4101 return QualType();
4102
John McCall550e0c22009-10-21 00:40:46 +00004103 QualType Result = TL.getType();
4104 if (getDerived().AlwaysRebuild() ||
4105 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004106 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004107 T->getVectorKind());
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 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4113 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004114
John McCall550e0c22009-10-21 00:40:46 +00004115 return Result;
4116}
4117
4118template<typename Derived>
4119QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004120 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004121 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004122 QualType ElementType = getDerived().TransformType(T->getElementType());
4123 if (ElementType.isNull())
4124 return QualType();
4125
4126 QualType Result = TL.getType();
4127 if (getDerived().AlwaysRebuild() ||
4128 ElementType != T->getElementType()) {
4129 Result = getDerived().RebuildExtVectorType(ElementType,
4130 T->getNumElements(),
4131 /*FIXME*/ SourceLocation());
4132 if (Result.isNull())
4133 return QualType();
4134 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004135
John McCall550e0c22009-10-21 00:40:46 +00004136 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4137 NewTL.setNameLoc(TL.getNameLoc());
4138
4139 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004140}
Mike Stump11289f42009-09-09 15:08:12 +00004141
David Blaikie05785d12013-02-20 22:23:23 +00004142template <typename Derived>
4143ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4144 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4145 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004146 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004147 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004148
Douglas Gregor715e4612011-01-14 22:40:04 +00004149 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004150 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004151 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004152 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004153 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004154
Douglas Gregor715e4612011-01-14 22:40:04 +00004155 TypeLocBuilder TLB;
4156 TypeLoc NewTL = OldDI->getTypeLoc();
4157 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004158
4159 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004160 OldExpansionTL.getPatternLoc());
4161 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004162 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004163
4164 Result = RebuildPackExpansionType(Result,
4165 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004166 OldExpansionTL.getEllipsisLoc(),
4167 NumExpansions);
4168 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004169 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004170
Douglas Gregor715e4612011-01-14 22:40:04 +00004171 PackExpansionTypeLoc NewExpansionTL
4172 = TLB.push<PackExpansionTypeLoc>(Result);
4173 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4174 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4175 } else
4176 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004177 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004178 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004179
John McCall8fb0d9d2011-05-01 22:35:37 +00004180 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004181 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004182
4183 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4184 OldParm->getDeclContext(),
4185 OldParm->getInnerLocStart(),
4186 OldParm->getLocation(),
4187 OldParm->getIdentifier(),
4188 NewDI->getType(),
4189 NewDI,
4190 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004191 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004192 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4193 OldParm->getFunctionScopeIndex() + indexAdjustment);
4194 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004195}
4196
4197template<typename Derived>
4198bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004199 TransformFunctionTypeParams(SourceLocation Loc,
4200 ParmVarDecl **Params, unsigned NumParams,
4201 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004202 SmallVectorImpl<QualType> &OutParamTypes,
4203 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004204 int indexAdjustment = 0;
4205
Douglas Gregordd472162011-01-07 00:20:55 +00004206 for (unsigned i = 0; i != NumParams; ++i) {
4207 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004208 assert(OldParm->getFunctionScopeIndex() == i);
4209
David Blaikie05785d12013-02-20 22:23:23 +00004210 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004211 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004212 if (OldParm->isParameterPack()) {
4213 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004214 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004215
Douglas Gregor5499af42011-01-05 23:12:31 +00004216 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004217 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004218 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004219 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4220 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004221 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4222
Douglas Gregor5499af42011-01-05 23:12:31 +00004223 // Determine whether we should expand the parameter packs.
4224 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004225 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004226 Optional<unsigned> OrigNumExpansions =
4227 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004228 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004229 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4230 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004231 Unexpanded,
4232 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004233 RetainExpansion,
4234 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004235 return true;
4236 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004237
Douglas Gregor5499af42011-01-05 23:12:31 +00004238 if (ShouldExpand) {
4239 // Expand the function parameter pack into multiple, separate
4240 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004241 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004242 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004243 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004244 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004245 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004246 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004247 OrigNumExpansions,
4248 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004249 if (!NewParm)
4250 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004251
Douglas Gregordd472162011-01-07 00:20:55 +00004252 OutParamTypes.push_back(NewParm->getType());
4253 if (PVars)
4254 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004255 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004256
4257 // If we're supposed to retain a pack expansion, do so by temporarily
4258 // forgetting the partially-substituted parameter pack.
4259 if (RetainExpansion) {
4260 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004261 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004262 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004263 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004264 OrigNumExpansions,
4265 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004266 if (!NewParm)
4267 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004268
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004269 OutParamTypes.push_back(NewParm->getType());
4270 if (PVars)
4271 PVars->push_back(NewParm);
4272 }
4273
John McCall8fb0d9d2011-05-01 22:35:37 +00004274 // The next parameter should have the same adjustment as the
4275 // last thing we pushed, but we post-incremented indexAdjustment
4276 // on every push. Also, if we push nothing, the adjustment should
4277 // go down by one.
4278 indexAdjustment--;
4279
Douglas Gregor5499af42011-01-05 23:12:31 +00004280 // We're done with the pack expansion.
4281 continue;
4282 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004283
4284 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004285 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004286 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4287 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004288 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004289 NumExpansions,
4290 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004291 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004292 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004293 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004294 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004295
John McCall58f10c32010-03-11 09:03:00 +00004296 if (!NewParm)
4297 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004298
Douglas Gregordd472162011-01-07 00:20:55 +00004299 OutParamTypes.push_back(NewParm->getType());
4300 if (PVars)
4301 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004302 continue;
4303 }
John McCall58f10c32010-03-11 09:03:00 +00004304
4305 // Deal with the possibility that we don't have a parameter
4306 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004307 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004308 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004309 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004310 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004311 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004312 = dyn_cast<PackExpansionType>(OldType)) {
4313 // We have a function parameter pack that may need to be expanded.
4314 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004315 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004316 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004317
Douglas Gregor5499af42011-01-05 23:12:31 +00004318 // Determine whether we should expand the parameter packs.
4319 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004320 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004321 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004322 Unexpanded,
4323 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004324 RetainExpansion,
4325 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004326 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004327 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004328
Douglas Gregor5499af42011-01-05 23:12:31 +00004329 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004330 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004331 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004332 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004333 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4334 QualType NewType = getDerived().TransformType(Pattern);
4335 if (NewType.isNull())
4336 return true;
John McCall58f10c32010-03-11 09:03:00 +00004337
Douglas Gregordd472162011-01-07 00:20:55 +00004338 OutParamTypes.push_back(NewType);
4339 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004340 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004341 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004342
Douglas Gregor5499af42011-01-05 23:12:31 +00004343 // We're done with the pack expansion.
4344 continue;
4345 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004346
Douglas Gregor48d24112011-01-10 20:53:55 +00004347 // If we're supposed to retain a pack expansion, do so by temporarily
4348 // forgetting the partially-substituted parameter pack.
4349 if (RetainExpansion) {
4350 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4351 QualType NewType = getDerived().TransformType(Pattern);
4352 if (NewType.isNull())
4353 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004354
Douglas Gregor48d24112011-01-10 20:53:55 +00004355 OutParamTypes.push_back(NewType);
4356 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004357 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004358 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004359
Chad Rosier1dcde962012-08-08 18:46:20 +00004360 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004361 // expansion.
4362 OldType = Expansion->getPattern();
4363 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004364 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4365 NewType = getDerived().TransformType(OldType);
4366 } else {
4367 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004368 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004369
Douglas Gregor5499af42011-01-05 23:12:31 +00004370 if (NewType.isNull())
4371 return true;
4372
4373 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004374 NewType = getSema().Context.getPackExpansionType(NewType,
4375 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004376
Douglas Gregordd472162011-01-07 00:20:55 +00004377 OutParamTypes.push_back(NewType);
4378 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004379 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004380 }
4381
John McCall8fb0d9d2011-05-01 22:35:37 +00004382#ifndef NDEBUG
4383 if (PVars) {
4384 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4385 if (ParmVarDecl *parm = (*PVars)[i])
4386 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004387 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004388#endif
4389
4390 return false;
4391}
John McCall58f10c32010-03-11 09:03:00 +00004392
4393template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004394QualType
John McCall550e0c22009-10-21 00:40:46 +00004395TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004396 FunctionProtoTypeLoc TL) {
Craig Topperc3ec1492014-05-26 06:22:03 +00004397 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
Douglas Gregor3024f072012-04-16 07:05:22 +00004398}
4399
4400template<typename Derived>
4401QualType
4402TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4403 FunctionProtoTypeLoc TL,
4404 CXXRecordDecl *ThisContext,
4405 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004406 // Transform the parameters and return type.
4407 //
Richard Smithf623c962012-04-17 00:58:00 +00004408 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004409 // When the function has a trailing return type, we instantiate the
4410 // parameters before the return type, since the return type can then refer
4411 // to the parameters themselves (via decltype, sizeof, etc.).
4412 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004413 SmallVector<QualType, 4> ParamTypes;
4414 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004415 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004416
Douglas Gregor7fb25412010-10-01 18:44:50 +00004417 QualType ResultType;
4418
Richard Smith1226c602012-08-14 22:51:13 +00004419 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004420 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004421 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004422 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004423 return QualType();
4424
Douglas Gregor3024f072012-04-16 07:05:22 +00004425 {
4426 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004427 // If a declaration declares a member function or member function
4428 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004429 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004430 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004431 // declarator.
4432 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004433
Alp Toker42a16a62014-01-25 23:51:36 +00004434 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004435 if (ResultType.isNull())
4436 return QualType();
4437 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004438 }
4439 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004440 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004441 if (ResultType.isNull())
4442 return QualType();
4443
Alp Toker9cacbab2014-01-20 20:26:09 +00004444 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004445 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004446 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004447 return QualType();
4448 }
4449
Richard Smithf623c962012-04-17 00:58:00 +00004450 // FIXME: Need to transform the exception-specification too.
4451
John McCall550e0c22009-10-21 00:40:46 +00004452 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004453 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004454 T->getNumParams() != ParamTypes.size() ||
4455 !std::equal(T->param_type_begin(), T->param_type_end(),
4456 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004457 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004458 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004459 if (Result.isNull())
4460 return QualType();
4461 }
Mike Stump11289f42009-09-09 15:08:12 +00004462
John McCall550e0c22009-10-21 00:40:46 +00004463 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004464 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004465 NewTL.setLParenLoc(TL.getLParenLoc());
4466 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004467 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004468 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4469 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004470
4471 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004472}
Mike Stump11289f42009-09-09 15:08:12 +00004473
Douglas Gregord6ff3322009-08-04 16:50:30 +00004474template<typename Derived>
4475QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004476 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004477 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004478 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004479 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004480 if (ResultType.isNull())
4481 return QualType();
4482
4483 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004484 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004485 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4486
4487 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004488 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004489 NewTL.setLParenLoc(TL.getLParenLoc());
4490 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004491 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004492
4493 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004494}
Mike Stump11289f42009-09-09 15:08:12 +00004495
John McCallb96ec562009-12-04 22:46:56 +00004496template<typename Derived> QualType
4497TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004498 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004499 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004500 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004501 if (!D)
4502 return QualType();
4503
4504 QualType Result = TL.getType();
4505 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4506 Result = getDerived().RebuildUnresolvedUsingType(D);
4507 if (Result.isNull())
4508 return QualType();
4509 }
4510
4511 // We might get an arbitrary type spec type back. We should at
4512 // least always get a type spec type, though.
4513 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4514 NewTL.setNameLoc(TL.getNameLoc());
4515
4516 return Result;
4517}
4518
Douglas Gregord6ff3322009-08-04 16:50:30 +00004519template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004520QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004521 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004522 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004523 TypedefNameDecl *Typedef
4524 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4525 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004526 if (!Typedef)
4527 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004528
John McCall550e0c22009-10-21 00:40:46 +00004529 QualType Result = TL.getType();
4530 if (getDerived().AlwaysRebuild() ||
4531 Typedef != T->getDecl()) {
4532 Result = getDerived().RebuildTypedefType(Typedef);
4533 if (Result.isNull())
4534 return QualType();
4535 }
Mike Stump11289f42009-09-09 15:08:12 +00004536
John McCall550e0c22009-10-21 00:40:46 +00004537 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4538 NewTL.setNameLoc(TL.getNameLoc());
4539
4540 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004541}
Mike Stump11289f42009-09-09 15:08:12 +00004542
Douglas Gregord6ff3322009-08-04 16:50:30 +00004543template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004544QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004545 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004546 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004547 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4548 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004549
John McCalldadc5752010-08-24 06:29:42 +00004550 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004551 if (E.isInvalid())
4552 return QualType();
4553
Eli Friedmane4f22df2012-02-29 04:03:55 +00004554 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4555 if (E.isInvalid())
4556 return QualType();
4557
John McCall550e0c22009-10-21 00:40:46 +00004558 QualType Result = TL.getType();
4559 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004560 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004561 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004562 if (Result.isNull())
4563 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004564 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004565 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004566
John McCall550e0c22009-10-21 00:40:46 +00004567 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004568 NewTL.setTypeofLoc(TL.getTypeofLoc());
4569 NewTL.setLParenLoc(TL.getLParenLoc());
4570 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004571
4572 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004573}
Mike Stump11289f42009-09-09 15:08:12 +00004574
4575template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004576QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004577 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004578 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4579 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4580 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004581 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004582
John McCall550e0c22009-10-21 00:40:46 +00004583 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004584 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4585 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004586 if (Result.isNull())
4587 return QualType();
4588 }
Mike Stump11289f42009-09-09 15:08:12 +00004589
John McCall550e0c22009-10-21 00:40:46 +00004590 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004591 NewTL.setTypeofLoc(TL.getTypeofLoc());
4592 NewTL.setLParenLoc(TL.getLParenLoc());
4593 NewTL.setRParenLoc(TL.getRParenLoc());
4594 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004595
4596 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004597}
Mike Stump11289f42009-09-09 15:08:12 +00004598
4599template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004600QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004601 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004602 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004603
Douglas Gregore922c772009-08-04 22:27:00 +00004604 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004605 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4606 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004607
John McCalldadc5752010-08-24 06:29:42 +00004608 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004609 if (E.isInvalid())
4610 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004611
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004612 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004613 if (E.isInvalid())
4614 return QualType();
4615
John McCall550e0c22009-10-21 00:40:46 +00004616 QualType Result = TL.getType();
4617 if (getDerived().AlwaysRebuild() ||
4618 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004619 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004620 if (Result.isNull())
4621 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004622 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004623 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004624
John McCall550e0c22009-10-21 00:40:46 +00004625 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4626 NewTL.setNameLoc(TL.getNameLoc());
4627
4628 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004629}
4630
4631template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004632QualType TreeTransform<Derived>::TransformUnaryTransformType(
4633 TypeLocBuilder &TLB,
4634 UnaryTransformTypeLoc TL) {
4635 QualType Result = TL.getType();
4636 if (Result->isDependentType()) {
4637 const UnaryTransformType *T = TL.getTypePtr();
4638 QualType NewBase =
4639 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4640 Result = getDerived().RebuildUnaryTransformType(NewBase,
4641 T->getUTTKind(),
4642 TL.getKWLoc());
4643 if (Result.isNull())
4644 return QualType();
4645 }
4646
4647 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4648 NewTL.setKWLoc(TL.getKWLoc());
4649 NewTL.setParensRange(TL.getParensRange());
4650 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4651 return Result;
4652}
4653
4654template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004655QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4656 AutoTypeLoc TL) {
4657 const AutoType *T = TL.getTypePtr();
4658 QualType OldDeduced = T->getDeducedType();
4659 QualType NewDeduced;
4660 if (!OldDeduced.isNull()) {
4661 NewDeduced = getDerived().TransformType(OldDeduced);
4662 if (NewDeduced.isNull())
4663 return QualType();
4664 }
4665
4666 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004667 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4668 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004669 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004670 if (Result.isNull())
4671 return QualType();
4672 }
4673
4674 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4675 NewTL.setNameLoc(TL.getNameLoc());
4676
4677 return Result;
4678}
4679
4680template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004681QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004682 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004683 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004684 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004685 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4686 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004687 if (!Record)
4688 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004689
John McCall550e0c22009-10-21 00:40:46 +00004690 QualType Result = TL.getType();
4691 if (getDerived().AlwaysRebuild() ||
4692 Record != T->getDecl()) {
4693 Result = getDerived().RebuildRecordType(Record);
4694 if (Result.isNull())
4695 return QualType();
4696 }
Mike Stump11289f42009-09-09 15:08:12 +00004697
John McCall550e0c22009-10-21 00:40:46 +00004698 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4699 NewTL.setNameLoc(TL.getNameLoc());
4700
4701 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004702}
Mike Stump11289f42009-09-09 15:08:12 +00004703
4704template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004705QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004706 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004707 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004708 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004709 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4710 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004711 if (!Enum)
4712 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004713
John McCall550e0c22009-10-21 00:40:46 +00004714 QualType Result = TL.getType();
4715 if (getDerived().AlwaysRebuild() ||
4716 Enum != T->getDecl()) {
4717 Result = getDerived().RebuildEnumType(Enum);
4718 if (Result.isNull())
4719 return QualType();
4720 }
Mike Stump11289f42009-09-09 15:08:12 +00004721
John McCall550e0c22009-10-21 00:40:46 +00004722 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4723 NewTL.setNameLoc(TL.getNameLoc());
4724
4725 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004726}
John McCallfcc33b02009-09-05 00:15:47 +00004727
John McCalle78aac42010-03-10 03:28:59 +00004728template<typename Derived>
4729QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4730 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004731 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004732 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4733 TL.getTypePtr()->getDecl());
4734 if (!D) return QualType();
4735
4736 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4737 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4738 return T;
4739}
4740
Douglas Gregord6ff3322009-08-04 16:50:30 +00004741template<typename Derived>
4742QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004743 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004744 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004745 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004746}
4747
Mike Stump11289f42009-09-09 15:08:12 +00004748template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004749QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004750 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004751 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004752 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004753
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004754 // Substitute into the replacement type, which itself might involve something
4755 // that needs to be transformed. This only tends to occur with default
4756 // template arguments of template template parameters.
4757 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4758 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4759 if (Replacement.isNull())
4760 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004761
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004762 // Always canonicalize the replacement type.
4763 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4764 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004765 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004766 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004767
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004768 // Propagate type-source information.
4769 SubstTemplateTypeParmTypeLoc NewTL
4770 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4771 NewTL.setNameLoc(TL.getNameLoc());
4772 return Result;
4773
John McCallcebee162009-10-18 09:09:24 +00004774}
4775
4776template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004777QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4778 TypeLocBuilder &TLB,
4779 SubstTemplateTypeParmPackTypeLoc TL) {
4780 return TransformTypeSpecType(TLB, TL);
4781}
4782
4783template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004784QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004785 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004786 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004787 const TemplateSpecializationType *T = TL.getTypePtr();
4788
Douglas Gregordf846d12011-03-02 18:46:51 +00004789 // The nested-name-specifier never matters in a TemplateSpecializationType,
4790 // because we can't have a dependent nested-name-specifier anyway.
4791 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004792 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004793 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4794 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004795 if (Template.isNull())
4796 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004797
John McCall31f82722010-11-12 08:19:04 +00004798 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4799}
4800
Eli Friedman0dfb8892011-10-06 23:00:33 +00004801template<typename Derived>
4802QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4803 AtomicTypeLoc TL) {
4804 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4805 if (ValueType.isNull())
4806 return QualType();
4807
4808 QualType Result = TL.getType();
4809 if (getDerived().AlwaysRebuild() ||
4810 ValueType != TL.getValueLoc().getType()) {
4811 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4812 if (Result.isNull())
4813 return QualType();
4814 }
4815
4816 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4817 NewTL.setKWLoc(TL.getKWLoc());
4818 NewTL.setLParenLoc(TL.getLParenLoc());
4819 NewTL.setRParenLoc(TL.getRParenLoc());
4820
4821 return Result;
4822}
4823
Chad Rosier1dcde962012-08-08 18:46:20 +00004824 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004825 /// container that provides a \c getArgLoc() member function.
4826 ///
4827 /// This iterator is intended to be used with the iterator form of
4828 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4829 template<typename ArgLocContainer>
4830 class TemplateArgumentLocContainerIterator {
4831 ArgLocContainer *Container;
4832 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004833
Douglas Gregorfe921a72010-12-20 23:36:19 +00004834 public:
4835 typedef TemplateArgumentLoc value_type;
4836 typedef TemplateArgumentLoc reference;
4837 typedef int difference_type;
4838 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004839
Douglas Gregorfe921a72010-12-20 23:36:19 +00004840 class pointer {
4841 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004842
Douglas Gregorfe921a72010-12-20 23:36:19 +00004843 public:
4844 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004845
Douglas Gregorfe921a72010-12-20 23:36:19 +00004846 const TemplateArgumentLoc *operator->() const {
4847 return &Arg;
4848 }
4849 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004850
4851
Douglas Gregorfe921a72010-12-20 23:36:19 +00004852 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004853
Douglas Gregorfe921a72010-12-20 23:36:19 +00004854 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4855 unsigned Index)
4856 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004857
Douglas Gregorfe921a72010-12-20 23:36:19 +00004858 TemplateArgumentLocContainerIterator &operator++() {
4859 ++Index;
4860 return *this;
4861 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004862
Douglas Gregorfe921a72010-12-20 23:36:19 +00004863 TemplateArgumentLocContainerIterator operator++(int) {
4864 TemplateArgumentLocContainerIterator Old(*this);
4865 ++(*this);
4866 return Old;
4867 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004868
Douglas Gregorfe921a72010-12-20 23:36:19 +00004869 TemplateArgumentLoc operator*() const {
4870 return Container->getArgLoc(Index);
4871 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004872
Douglas Gregorfe921a72010-12-20 23:36:19 +00004873 pointer operator->() const {
4874 return pointer(Container->getArgLoc(Index));
4875 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004876
Douglas Gregorfe921a72010-12-20 23:36:19 +00004877 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004878 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004879 return X.Container == Y.Container && X.Index == Y.Index;
4880 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004881
Douglas Gregorfe921a72010-12-20 23:36:19 +00004882 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004883 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004884 return !(X == Y);
4885 }
4886 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004887
4888
John McCall31f82722010-11-12 08:19:04 +00004889template <typename Derived>
4890QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4891 TypeLocBuilder &TLB,
4892 TemplateSpecializationTypeLoc TL,
4893 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004894 TemplateArgumentListInfo NewTemplateArgs;
4895 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4896 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004897 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4898 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004899 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004900 ArgIterator(TL, TL.getNumArgs()),
4901 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004902 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004903
John McCall0ad16662009-10-29 08:12:44 +00004904 // FIXME: maybe don't rebuild if all the template arguments are the same.
4905
4906 QualType Result =
4907 getDerived().RebuildTemplateSpecializationType(Template,
4908 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004909 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004910
4911 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004912 // Specializations of template template parameters are represented as
4913 // TemplateSpecializationTypes, and substitution of type alias templates
4914 // within a dependent context can transform them into
4915 // DependentTemplateSpecializationTypes.
4916 if (isa<DependentTemplateSpecializationType>(Result)) {
4917 DependentTemplateSpecializationTypeLoc NewTL
4918 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004919 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004920 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004921 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004922 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004923 NewTL.setLAngleLoc(TL.getLAngleLoc());
4924 NewTL.setRAngleLoc(TL.getRAngleLoc());
4925 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4926 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4927 return Result;
4928 }
4929
John McCall0ad16662009-10-29 08:12:44 +00004930 TemplateSpecializationTypeLoc NewTL
4931 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004932 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00004933 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4934 NewTL.setLAngleLoc(TL.getLAngleLoc());
4935 NewTL.setRAngleLoc(TL.getRAngleLoc());
4936 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4937 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004938 }
Mike Stump11289f42009-09-09 15:08:12 +00004939
John McCall0ad16662009-10-29 08:12:44 +00004940 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004941}
Mike Stump11289f42009-09-09 15:08:12 +00004942
Douglas Gregor5a064722011-02-28 17:23:35 +00004943template <typename Derived>
4944QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4945 TypeLocBuilder &TLB,
4946 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004947 TemplateName Template,
4948 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004949 TemplateArgumentListInfo NewTemplateArgs;
4950 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4951 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4952 typedef TemplateArgumentLocContainerIterator<
4953 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004954 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00004955 ArgIterator(TL, TL.getNumArgs()),
4956 NewTemplateArgs))
4957 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004958
Douglas Gregor5a064722011-02-28 17:23:35 +00004959 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00004960
Douglas Gregor5a064722011-02-28 17:23:35 +00004961 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4962 QualType Result
4963 = getSema().Context.getDependentTemplateSpecializationType(
4964 TL.getTypePtr()->getKeyword(),
4965 DTN->getQualifier(),
4966 DTN->getIdentifier(),
4967 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004968
Douglas Gregor5a064722011-02-28 17:23:35 +00004969 DependentTemplateSpecializationTypeLoc NewTL
4970 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004971 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004972 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004973 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004974 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004975 NewTL.setLAngleLoc(TL.getLAngleLoc());
4976 NewTL.setRAngleLoc(TL.getRAngleLoc());
4977 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4978 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4979 return Result;
4980 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004981
4982 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00004983 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004984 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00004985 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004986
Douglas Gregor5a064722011-02-28 17:23:35 +00004987 if (!Result.isNull()) {
4988 /// FIXME: Wrap this in an elaborated-type-specifier?
4989 TemplateSpecializationTypeLoc NewTL
4990 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004991 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004992 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004993 NewTL.setLAngleLoc(TL.getLAngleLoc());
4994 NewTL.setRAngleLoc(TL.getRAngleLoc());
4995 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4996 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4997 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004998
Douglas Gregor5a064722011-02-28 17:23:35 +00004999 return Result;
5000}
5001
Mike Stump11289f42009-09-09 15:08:12 +00005002template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005003QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005004TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005005 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005006 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005007
Douglas Gregor844cb502011-03-01 18:12:44 +00005008 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005009 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005010 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005011 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005012 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5013 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005014 return QualType();
5015 }
Mike Stump11289f42009-09-09 15:08:12 +00005016
John McCall31f82722010-11-12 08:19:04 +00005017 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5018 if (NamedT.isNull())
5019 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005020
Richard Smith3f1b5d02011-05-05 21:57:07 +00005021 // C++0x [dcl.type.elab]p2:
5022 // If the identifier resolves to a typedef-name or the simple-template-id
5023 // resolves to an alias template specialization, the
5024 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005025 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5026 if (const TemplateSpecializationType *TST =
5027 NamedT->getAs<TemplateSpecializationType>()) {
5028 TemplateName Template = TST->getTemplateName();
5029 if (TypeAliasTemplateDecl *TAT =
5030 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5031 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5032 diag::err_tag_reference_non_tag) << 4;
5033 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5034 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005035 }
5036 }
5037
John McCall550e0c22009-10-21 00:40:46 +00005038 QualType Result = TL.getType();
5039 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005040 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005041 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005042 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005043 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005044 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005045 if (Result.isNull())
5046 return QualType();
5047 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005048
Abramo Bagnara6150c882010-05-11 21:36:43 +00005049 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005050 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005051 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005052 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005053}
Mike Stump11289f42009-09-09 15:08:12 +00005054
5055template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005056QualType TreeTransform<Derived>::TransformAttributedType(
5057 TypeLocBuilder &TLB,
5058 AttributedTypeLoc TL) {
5059 const AttributedType *oldType = TL.getTypePtr();
5060 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5061 if (modifiedType.isNull())
5062 return QualType();
5063
5064 QualType result = TL.getType();
5065
5066 // FIXME: dependent operand expressions?
5067 if (getDerived().AlwaysRebuild() ||
5068 modifiedType != oldType->getModifiedType()) {
5069 // TODO: this is really lame; we should really be rebuilding the
5070 // equivalent type from first principles.
5071 QualType equivalentType
5072 = getDerived().TransformType(oldType->getEquivalentType());
5073 if (equivalentType.isNull())
5074 return QualType();
5075 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5076 modifiedType,
5077 equivalentType);
5078 }
5079
5080 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5081 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5082 if (TL.hasAttrOperand())
5083 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5084 if (TL.hasAttrExprOperand())
5085 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5086 else if (TL.hasAttrEnumOperand())
5087 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5088
5089 return result;
5090}
5091
5092template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005093QualType
5094TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5095 ParenTypeLoc TL) {
5096 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5097 if (Inner.isNull())
5098 return QualType();
5099
5100 QualType Result = TL.getType();
5101 if (getDerived().AlwaysRebuild() ||
5102 Inner != TL.getInnerLoc().getType()) {
5103 Result = getDerived().RebuildParenType(Inner);
5104 if (Result.isNull())
5105 return QualType();
5106 }
5107
5108 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5109 NewTL.setLParenLoc(TL.getLParenLoc());
5110 NewTL.setRParenLoc(TL.getRParenLoc());
5111 return Result;
5112}
5113
5114template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005115QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005116 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005117 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005118
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005119 NestedNameSpecifierLoc QualifierLoc
5120 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5121 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005122 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005123
John McCallc392f372010-06-11 00:33:02 +00005124 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005125 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005126 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005127 QualifierLoc,
5128 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005129 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005130 if (Result.isNull())
5131 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005132
Abramo Bagnarad7548482010-05-19 21:37:53 +00005133 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5134 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005135 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5136
Abramo Bagnarad7548482010-05-19 21:37:53 +00005137 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005138 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005139 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005140 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005141 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005142 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005143 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005144 NewTL.setNameLoc(TL.getNameLoc());
5145 }
John McCall550e0c22009-10-21 00:40:46 +00005146 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005147}
Mike Stump11289f42009-09-09 15:08:12 +00005148
Douglas Gregord6ff3322009-08-04 16:50:30 +00005149template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005150QualType TreeTransform<Derived>::
5151 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005152 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005153 NestedNameSpecifierLoc QualifierLoc;
5154 if (TL.getQualifierLoc()) {
5155 QualifierLoc
5156 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5157 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005158 return QualType();
5159 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005160
John McCall31f82722010-11-12 08:19:04 +00005161 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005162 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005163}
5164
5165template<typename Derived>
5166QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005167TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5168 DependentTemplateSpecializationTypeLoc TL,
5169 NestedNameSpecifierLoc QualifierLoc) {
5170 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005171
Douglas Gregora7a795b2011-03-01 20:11:18 +00005172 TemplateArgumentListInfo NewTemplateArgs;
5173 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5174 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005175
Douglas Gregora7a795b2011-03-01 20:11:18 +00005176 typedef TemplateArgumentLocContainerIterator<
5177 DependentTemplateSpecializationTypeLoc> ArgIterator;
5178 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5179 ArgIterator(TL, TL.getNumArgs()),
5180 NewTemplateArgs))
5181 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005182
Douglas Gregora7a795b2011-03-01 20:11:18 +00005183 QualType Result
5184 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5185 QualifierLoc,
5186 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005187 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005188 NewTemplateArgs);
5189 if (Result.isNull())
5190 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005191
Douglas Gregora7a795b2011-03-01 20:11:18 +00005192 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5193 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005194
Douglas Gregora7a795b2011-03-01 20:11:18 +00005195 // Copy information relevant to the template specialization.
5196 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005197 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005198 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005199 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005200 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5201 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005202 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005203 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005204
Douglas Gregora7a795b2011-03-01 20:11:18 +00005205 // Copy information relevant to the elaborated type.
5206 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005207 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005208 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005209 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5210 DependentTemplateSpecializationTypeLoc SpecTL
5211 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005212 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005213 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005214 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005215 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005216 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5217 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005218 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005219 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005220 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005221 TemplateSpecializationTypeLoc SpecTL
5222 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005223 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005224 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005225 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5226 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005227 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005228 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005229 }
5230 return Result;
5231}
5232
5233template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005234QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5235 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005236 QualType Pattern
5237 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005238 if (Pattern.isNull())
5239 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005240
5241 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005242 if (getDerived().AlwaysRebuild() ||
5243 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005244 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005245 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005246 TL.getEllipsisLoc(),
5247 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005248 if (Result.isNull())
5249 return QualType();
5250 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005251
Douglas Gregor822d0302011-01-12 17:07:58 +00005252 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5253 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5254 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005255}
5256
5257template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005258QualType
5259TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005260 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005261 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005262 TLB.pushFullCopy(TL);
5263 return TL.getType();
5264}
5265
5266template<typename Derived>
5267QualType
5268TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005269 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005270 // ObjCObjectType is never dependent.
5271 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005272 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005273}
Mike Stump11289f42009-09-09 15:08:12 +00005274
5275template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005276QualType
5277TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005278 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005279 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005280 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005281 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005282}
5283
Douglas Gregord6ff3322009-08-04 16:50:30 +00005284//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005285// Statement transformation
5286//===----------------------------------------------------------------------===//
5287template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005288StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005289TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005290 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005291}
5292
5293template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005294StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005295TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5296 return getDerived().TransformCompoundStmt(S, false);
5297}
5298
5299template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005300StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005301TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005302 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005303 Sema::CompoundScopeRAII CompoundScope(getSema());
5304
John McCall1ababa62010-08-27 19:56:05 +00005305 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005306 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005307 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005308 for (auto *B : S->body()) {
5309 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005310 if (Result.isInvalid()) {
5311 // Immediately fail if this was a DeclStmt, since it's very
5312 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005313 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005314 return StmtError();
5315
5316 // Otherwise, just keep processing substatements and fail later.
5317 SubStmtInvalid = true;
5318 continue;
5319 }
Mike Stump11289f42009-09-09 15:08:12 +00005320
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005321 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005322 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005323 }
Mike Stump11289f42009-09-09 15:08:12 +00005324
John McCall1ababa62010-08-27 19:56:05 +00005325 if (SubStmtInvalid)
5326 return StmtError();
5327
Douglas Gregorebe10102009-08-20 07:17:43 +00005328 if (!getDerived().AlwaysRebuild() &&
5329 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005330 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005331
5332 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005333 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005334 S->getRBracLoc(),
5335 IsStmtExpr);
5336}
Mike Stump11289f42009-09-09 15:08:12 +00005337
Douglas Gregorebe10102009-08-20 07:17:43 +00005338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005339StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005340TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005341 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005342 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005343 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5344 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005345
Eli Friedman06577382009-11-19 03:14:00 +00005346 // Transform the left-hand case value.
5347 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005348 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005349 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005350 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005351
Eli Friedman06577382009-11-19 03:14:00 +00005352 // Transform the right-hand case value (for the GNU case-range extension).
5353 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005354 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005355 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005356 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005357 }
Mike Stump11289f42009-09-09 15:08:12 +00005358
Douglas Gregorebe10102009-08-20 07:17:43 +00005359 // Build the case statement.
5360 // Case statements are always rebuilt so that they will attached to their
5361 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005362 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005363 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005364 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005365 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005366 S->getColonLoc());
5367 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005368 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005369
Douglas Gregorebe10102009-08-20 07:17:43 +00005370 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005371 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005372 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005373 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005374
Douglas Gregorebe10102009-08-20 07:17:43 +00005375 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005376 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005377}
5378
5379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005380StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005381TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005382 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005383 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005384 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005385 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005386
Douglas Gregorebe10102009-08-20 07:17:43 +00005387 // Default statements are always rebuilt
5388 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005389 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005390}
Mike Stump11289f42009-09-09 15:08:12 +00005391
Douglas Gregorebe10102009-08-20 07:17:43 +00005392template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005393StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005394TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005395 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005396 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005397 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005398
Chris Lattnercab02a62011-02-17 20:34:02 +00005399 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5400 S->getDecl());
5401 if (!LD)
5402 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005403
5404
Douglas Gregorebe10102009-08-20 07:17:43 +00005405 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005406 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005407 cast<LabelDecl>(LD), SourceLocation(),
5408 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005409}
Mike Stump11289f42009-09-09 15:08:12 +00005410
Douglas Gregorebe10102009-08-20 07:17:43 +00005411template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005412StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005413TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5414 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5415 if (SubStmt.isInvalid())
5416 return StmtError();
5417
5418 // TODO: transform attributes
5419 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5420 return S;
5421
5422 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5423 S->getAttrs(),
5424 SubStmt.get());
5425}
5426
5427template<typename Derived>
5428StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005429TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005430 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005431 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005432 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005433 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005434 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005435 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005436 getDerived().TransformDefinition(
5437 S->getConditionVariable()->getLocation(),
5438 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005439 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005440 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005441 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005442 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005443
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005444 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005445 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005446
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005447 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005448 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005449 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005450 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005451 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005452 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005453
John McCallb268a282010-08-23 23:25:46 +00005454 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005455 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005456 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005457
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005458 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005459 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005460 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005461
Douglas Gregorebe10102009-08-20 07:17:43 +00005462 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005463 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005464 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005465 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005466
Douglas Gregorebe10102009-08-20 07:17:43 +00005467 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005468 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005469 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005470 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005471
Douglas Gregorebe10102009-08-20 07:17:43 +00005472 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005473 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005474 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005475 Then.get() == S->getThen() &&
5476 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005477 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005478
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005479 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005480 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005481 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005482}
5483
5484template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005485StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005486TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005487 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005488 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005489 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005490 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005491 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005492 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005493 getDerived().TransformDefinition(
5494 S->getConditionVariable()->getLocation(),
5495 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005496 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005497 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005498 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005499 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005500
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005501 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005502 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005503 }
Mike Stump11289f42009-09-09 15:08:12 +00005504
Douglas Gregorebe10102009-08-20 07:17:43 +00005505 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005506 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005507 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005508 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005509 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005510 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005511
Douglas Gregorebe10102009-08-20 07:17:43 +00005512 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005513 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005514 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005515 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005516
Douglas Gregorebe10102009-08-20 07:17:43 +00005517 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005518 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5519 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005520}
Mike Stump11289f42009-09-09 15:08:12 +00005521
Douglas Gregorebe10102009-08-20 07:17:43 +00005522template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005523StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005524TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005525 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005526 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005527 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005528 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005529 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005530 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005531 getDerived().TransformDefinition(
5532 S->getConditionVariable()->getLocation(),
5533 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005534 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005535 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005536 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005537 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005538
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005539 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005540 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005541
5542 if (S->getCond()) {
5543 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005544 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5545 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005546 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005547 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005548 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005549 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005550 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005551 }
Mike Stump11289f42009-09-09 15:08:12 +00005552
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005553 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005554 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005555 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005556
Douglas Gregorebe10102009-08-20 07:17:43 +00005557 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005558 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005559 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005560 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005561
Douglas Gregorebe10102009-08-20 07:17:43 +00005562 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005563 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005564 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005565 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005566 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005567
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005568 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005569 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005570}
Mike Stump11289f42009-09-09 15:08:12 +00005571
Douglas Gregorebe10102009-08-20 07:17:43 +00005572template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005573StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005574TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005575 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005576 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005577 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005578 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005579
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005580 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005581 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005582 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005583 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005584
Douglas Gregorebe10102009-08-20 07:17:43 +00005585 if (!getDerived().AlwaysRebuild() &&
5586 Cond.get() == S->getCond() &&
5587 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005588 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005589
John McCallb268a282010-08-23 23:25:46 +00005590 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5591 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005592 S->getRParenLoc());
5593}
Mike Stump11289f42009-09-09 15:08:12 +00005594
Douglas Gregorebe10102009-08-20 07:17:43 +00005595template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005596StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005597TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005598 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005599 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005600 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005601 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005602
Douglas Gregorebe10102009-08-20 07:17:43 +00005603 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005604 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005605 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005606 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005607 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005608 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005609 getDerived().TransformDefinition(
5610 S->getConditionVariable()->getLocation(),
5611 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005612 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005613 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005614 } else {
5615 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005616
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005617 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005618 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005619
5620 if (S->getCond()) {
5621 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005622 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5623 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005624 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005625 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005626 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005627
John McCallb268a282010-08-23 23:25:46 +00005628 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005629 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005630 }
Mike Stump11289f42009-09-09 15:08:12 +00005631
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005632 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005633 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005634 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005635
Douglas Gregorebe10102009-08-20 07:17:43 +00005636 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005637 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005638 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005639 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005640
Richard Smith945f8d32013-01-14 22:39:08 +00005641 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005642 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005643 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005644
Douglas Gregorebe10102009-08-20 07:17:43 +00005645 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005646 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005647 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005648 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005649
Douglas Gregorebe10102009-08-20 07:17:43 +00005650 if (!getDerived().AlwaysRebuild() &&
5651 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005652 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005653 Inc.get() == S->getInc() &&
5654 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005655 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005656
Douglas Gregorebe10102009-08-20 07:17:43 +00005657 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005658 Init.get(), FullCond, ConditionVar,
5659 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005660}
5661
5662template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005663StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005664TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005665 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5666 S->getLabel());
5667 if (!LD)
5668 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005669
Douglas Gregorebe10102009-08-20 07:17:43 +00005670 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005671 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005672 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005673}
5674
5675template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005676StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005677TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005678 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005679 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005680 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005681 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00005682
Douglas Gregorebe10102009-08-20 07:17:43 +00005683 if (!getDerived().AlwaysRebuild() &&
5684 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005685 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005686
5687 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005688 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005689}
5690
5691template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005692StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005693TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005694 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005695}
Mike Stump11289f42009-09-09 15:08:12 +00005696
Douglas Gregorebe10102009-08-20 07:17:43 +00005697template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005698StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005699TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005700 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005701}
Mike Stump11289f42009-09-09 15:08:12 +00005702
Douglas Gregorebe10102009-08-20 07:17:43 +00005703template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005704StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005705TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005706 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005707 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005708 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005709
Mike Stump11289f42009-09-09 15:08:12 +00005710 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005711 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005712 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005713}
Mike Stump11289f42009-09-09 15:08:12 +00005714
Douglas Gregorebe10102009-08-20 07:17:43 +00005715template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005716StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005717TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005718 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005719 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005720 for (auto *D : S->decls()) {
5721 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005722 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005723 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005724
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005725 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005726 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005727
Douglas Gregorebe10102009-08-20 07:17:43 +00005728 Decls.push_back(Transformed);
5729 }
Mike Stump11289f42009-09-09 15:08:12 +00005730
Douglas Gregorebe10102009-08-20 07:17:43 +00005731 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005732 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005733
Rafael Espindolaab417692013-07-09 12:05:01 +00005734 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005735}
Mike Stump11289f42009-09-09 15:08:12 +00005736
Douglas Gregorebe10102009-08-20 07:17:43 +00005737template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005738StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005739TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005740
Benjamin Kramerf0623432012-08-23 22:51:59 +00005741 SmallVector<Expr*, 8> Constraints;
5742 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005743 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005744
John McCalldadc5752010-08-24 06:29:42 +00005745 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005746 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005747
5748 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005749
Anders Carlssonaaeef072010-01-24 05:50:09 +00005750 // Go through the outputs.
5751 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005752 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005753
Anders Carlssonaaeef072010-01-24 05:50:09 +00005754 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005755 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005756
Anders Carlssonaaeef072010-01-24 05:50:09 +00005757 // Transform the output expr.
5758 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005759 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005760 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005761 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005762
Anders Carlssonaaeef072010-01-24 05:50:09 +00005763 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005764
John McCallb268a282010-08-23 23:25:46 +00005765 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005766 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005767
Anders Carlssonaaeef072010-01-24 05:50:09 +00005768 // Go through the inputs.
5769 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005770 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005771
Anders Carlssonaaeef072010-01-24 05:50:09 +00005772 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005773 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005774
Anders Carlssonaaeef072010-01-24 05:50:09 +00005775 // Transform the input expr.
5776 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005777 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005778 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005779 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005780
Anders Carlssonaaeef072010-01-24 05:50:09 +00005781 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005782
John McCallb268a282010-08-23 23:25:46 +00005783 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005784 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005785
Anders Carlssonaaeef072010-01-24 05:50:09 +00005786 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005787 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005788
5789 // Go through the clobbers.
5790 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005791 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005792
5793 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005794 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00005795 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5796 S->isVolatile(), S->getNumOutputs(),
5797 S->getNumInputs(), Names.data(),
5798 Constraints, Exprs, AsmString.get(),
5799 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005800}
5801
Chad Rosier32503022012-06-11 20:47:18 +00005802template<typename Derived>
5803StmtResult
5804TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005805 ArrayRef<Token> AsmToks =
5806 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005807
John McCallf413f5e2013-05-03 00:10:13 +00005808 bool HadError = false, HadChange = false;
5809
5810 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5811 SmallVector<Expr*, 8> TransformedExprs;
5812 TransformedExprs.reserve(SrcExprs.size());
5813 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5814 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5815 if (!Result.isUsable()) {
5816 HadError = true;
5817 } else {
5818 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005819 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00005820 }
5821 }
5822
5823 if (HadError) return StmtError();
5824 if (!HadChange && !getDerived().AlwaysRebuild())
5825 return Owned(S);
5826
Chad Rosierb6f46c12012-08-15 16:53:30 +00005827 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005828 AsmToks, S->getAsmString(),
5829 S->getNumOutputs(), S->getNumInputs(),
5830 S->getAllConstraints(), S->getClobbers(),
5831 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005832}
Douglas Gregorebe10102009-08-20 07:17:43 +00005833
5834template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005835StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005836TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005837 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005838 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005839 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005840 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005841
Douglas Gregor96c79492010-04-23 22:50:49 +00005842 // Transform the @catch statements (if present).
5843 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005844 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005845 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005846 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005847 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005848 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005849 if (Catch.get() != S->getCatchStmt(I))
5850 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005851 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005852 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005853
Douglas Gregor306de2f2010-04-22 23:59:56 +00005854 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005855 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005856 if (S->getFinallyStmt()) {
5857 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5858 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005859 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005860 }
5861
5862 // If nothing changed, just retain this statement.
5863 if (!getDerived().AlwaysRebuild() &&
5864 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005865 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005866 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005867 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005868
Douglas Gregor306de2f2010-04-22 23:59:56 +00005869 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005870 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005871 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005872}
Mike Stump11289f42009-09-09 15:08:12 +00005873
Douglas Gregorebe10102009-08-20 07:17:43 +00005874template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005875StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005876TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005877 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00005878 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005879 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005880 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005881 if (FromVar->getTypeSourceInfo()) {
5882 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5883 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005884 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005885 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005886
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005887 QualType T;
5888 if (TSInfo)
5889 T = TSInfo->getType();
5890 else {
5891 T = getDerived().TransformType(FromVar->getType());
5892 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005893 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005894 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005895
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005896 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5897 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005898 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005899 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005900
John McCalldadc5752010-08-24 06:29:42 +00005901 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005902 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005903 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005904
5905 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005906 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005907 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005908}
Mike Stump11289f42009-09-09 15:08:12 +00005909
Douglas Gregorebe10102009-08-20 07:17:43 +00005910template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005911StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005912TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005913 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005914 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005915 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005916 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005917
Douglas Gregor306de2f2010-04-22 23:59:56 +00005918 // If nothing changed, just retain this statement.
5919 if (!getDerived().AlwaysRebuild() &&
5920 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005921 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005922
5923 // Build a new statement.
5924 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005925 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005926}
Mike Stump11289f42009-09-09 15:08:12 +00005927
Douglas Gregorebe10102009-08-20 07:17:43 +00005928template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005929StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005930TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005931 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005932 if (S->getThrowExpr()) {
5933 Operand = getDerived().TransformExpr(S->getThrowExpr());
5934 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005935 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005936 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005937
Douglas Gregor2900c162010-04-22 21:44:01 +00005938 if (!getDerived().AlwaysRebuild() &&
5939 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005940 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005941
John McCallb268a282010-08-23 23:25:46 +00005942 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005943}
Mike Stump11289f42009-09-09 15:08:12 +00005944
Douglas Gregorebe10102009-08-20 07:17:43 +00005945template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005946StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005947TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005948 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005949 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005950 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005951 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005952 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005953 Object =
5954 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5955 Object.get());
5956 if (Object.isInvalid())
5957 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005958
Douglas Gregor6148de72010-04-22 22:01:21 +00005959 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005960 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005961 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005962 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005963
Douglas Gregor6148de72010-04-22 22:01:21 +00005964 // If nothing change, just retain the current statement.
5965 if (!getDerived().AlwaysRebuild() &&
5966 Object.get() == S->getSynchExpr() &&
5967 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005968 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00005969
5970 // Build a new statement.
5971 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005972 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005973}
5974
5975template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005976StmtResult
John McCall31168b02011-06-15 23:02:42 +00005977TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5978 ObjCAutoreleasePoolStmt *S) {
5979 // Transform the body.
5980 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5981 if (Body.isInvalid())
5982 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005983
John McCall31168b02011-06-15 23:02:42 +00005984 // If nothing changed, just retain this statement.
5985 if (!getDerived().AlwaysRebuild() &&
5986 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005987 return S;
John McCall31168b02011-06-15 23:02:42 +00005988
5989 // Build a new statement.
5990 return getDerived().RebuildObjCAutoreleasePoolStmt(
5991 S->getAtLoc(), Body.get());
5992}
5993
5994template<typename Derived>
5995StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005996TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005997 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005998 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005999 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006000 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006001 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006002
Douglas Gregorf68a5082010-04-22 23:10:45 +00006003 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006004 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006005 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006006 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006007
Douglas Gregorf68a5082010-04-22 23:10:45 +00006008 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006009 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006010 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006011 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006012
Douglas Gregorf68a5082010-04-22 23:10:45 +00006013 // If nothing changed, just retain this statement.
6014 if (!getDerived().AlwaysRebuild() &&
6015 Element.get() == S->getElement() &&
6016 Collection.get() == S->getCollection() &&
6017 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006018 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006019
Douglas Gregorf68a5082010-04-22 23:10:45 +00006020 // Build a new statement.
6021 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006022 Element.get(),
6023 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006024 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006025 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006026}
6027
David Majnemer5f7efef2013-10-15 09:50:08 +00006028template <typename Derived>
6029StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006030 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006031 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006032 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6033 TypeSourceInfo *T =
6034 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006035 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006036 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006037
David Majnemer5f7efef2013-10-15 09:50:08 +00006038 Var = getDerived().RebuildExceptionDecl(
6039 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6040 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006041 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006042 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006043 }
Mike Stump11289f42009-09-09 15:08:12 +00006044
Douglas Gregorebe10102009-08-20 07:17:43 +00006045 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006046 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006047 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006048 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006049
David Majnemer5f7efef2013-10-15 09:50:08 +00006050 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006051 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006052 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006053
David Majnemer5f7efef2013-10-15 09:50:08 +00006054 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006055}
Mike Stump11289f42009-09-09 15:08:12 +00006056
David Majnemer5f7efef2013-10-15 09:50:08 +00006057template <typename Derived>
6058StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006059 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006060 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006061 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006062 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006063
Douglas Gregorebe10102009-08-20 07:17:43 +00006064 // Transform the handlers.
6065 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006066 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006067 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006068 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006069 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006070 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006071
Douglas Gregorebe10102009-08-20 07:17:43 +00006072 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006073 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006074 }
Mike Stump11289f42009-09-09 15:08:12 +00006075
David Majnemer5f7efef2013-10-15 09:50:08 +00006076 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006077 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006078 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006079
John McCallb268a282010-08-23 23:25:46 +00006080 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006081 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006082}
Mike Stump11289f42009-09-09 15:08:12 +00006083
Richard Smith02e85f32011-04-14 22:09:26 +00006084template<typename Derived>
6085StmtResult
6086TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6087 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6088 if (Range.isInvalid())
6089 return StmtError();
6090
6091 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6092 if (BeginEnd.isInvalid())
6093 return StmtError();
6094
6095 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6096 if (Cond.isInvalid())
6097 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006098 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006099 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006100 if (Cond.isInvalid())
6101 return StmtError();
6102 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006103 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006104
6105 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6106 if (Inc.isInvalid())
6107 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006108 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006109 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006110
6111 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6112 if (LoopVar.isInvalid())
6113 return StmtError();
6114
6115 StmtResult NewStmt = S;
6116 if (getDerived().AlwaysRebuild() ||
6117 Range.get() != S->getRangeStmt() ||
6118 BeginEnd.get() != S->getBeginEndStmt() ||
6119 Cond.get() != S->getCond() ||
6120 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006121 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006122 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6123 S->getColonLoc(), Range.get(),
6124 BeginEnd.get(), Cond.get(),
6125 Inc.get(), LoopVar.get(),
6126 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006127 if (NewStmt.isInvalid())
6128 return StmtError();
6129 }
Richard Smith02e85f32011-04-14 22:09:26 +00006130
6131 StmtResult Body = getDerived().TransformStmt(S->getBody());
6132 if (Body.isInvalid())
6133 return StmtError();
6134
6135 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6136 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006137 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006138 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6139 S->getColonLoc(), Range.get(),
6140 BeginEnd.get(), Cond.get(),
6141 Inc.get(), LoopVar.get(),
6142 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006143 if (NewStmt.isInvalid())
6144 return StmtError();
6145 }
Richard Smith02e85f32011-04-14 22:09:26 +00006146
6147 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006148 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006149
6150 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6151}
6152
John Wiegley1c0675e2011-04-28 01:08:34 +00006153template<typename Derived>
6154StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006155TreeTransform<Derived>::TransformMSDependentExistsStmt(
6156 MSDependentExistsStmt *S) {
6157 // Transform the nested-name-specifier, if any.
6158 NestedNameSpecifierLoc QualifierLoc;
6159 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006160 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006161 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6162 if (!QualifierLoc)
6163 return StmtError();
6164 }
6165
6166 // Transform the declaration name.
6167 DeclarationNameInfo NameInfo = S->getNameInfo();
6168 if (NameInfo.getName()) {
6169 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6170 if (!NameInfo.getName())
6171 return StmtError();
6172 }
6173
6174 // Check whether anything changed.
6175 if (!getDerived().AlwaysRebuild() &&
6176 QualifierLoc == S->getQualifierLoc() &&
6177 NameInfo.getName() == S->getNameInfo().getName())
6178 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006179
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006180 // Determine whether this name exists, if we can.
6181 CXXScopeSpec SS;
6182 SS.Adopt(QualifierLoc);
6183 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006184 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006185 case Sema::IER_Exists:
6186 if (S->isIfExists())
6187 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006188
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006189 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6190
6191 case Sema::IER_DoesNotExist:
6192 if (S->isIfNotExists())
6193 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006194
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006195 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006196
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006197 case Sema::IER_Dependent:
6198 Dependent = true;
6199 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006200
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006201 case Sema::IER_Error:
6202 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006203 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006204
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006205 // We need to continue with the instantiation, so do so now.
6206 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6207 if (SubStmt.isInvalid())
6208 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006209
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006210 // If we have resolved the name, just transform to the substatement.
6211 if (!Dependent)
6212 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006213
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006214 // The name is still dependent, so build a dependent expression again.
6215 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6216 S->isIfExists(),
6217 QualifierLoc,
6218 NameInfo,
6219 SubStmt.get());
6220}
6221
6222template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006223ExprResult
6224TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6225 NestedNameSpecifierLoc QualifierLoc;
6226 if (E->getQualifierLoc()) {
6227 QualifierLoc
6228 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6229 if (!QualifierLoc)
6230 return ExprError();
6231 }
6232
6233 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6234 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6235 if (!PD)
6236 return ExprError();
6237
6238 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6239 if (Base.isInvalid())
6240 return ExprError();
6241
6242 return new (SemaRef.getASTContext())
6243 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6244 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6245 QualifierLoc, E->getMemberLoc());
6246}
6247
David Majnemerfad8f482013-10-15 09:33:02 +00006248template <typename Derived>
6249StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006250 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006251 if (TryBlock.isInvalid())
6252 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006253
6254 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006255 if (Handler.isInvalid())
6256 return StmtError();
6257
David Majnemerfad8f482013-10-15 09:33:02 +00006258 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6259 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006260 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006261
David Majnemerfad8f482013-10-15 09:33:02 +00006262 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006263 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006264}
6265
David Majnemerfad8f482013-10-15 09:33:02 +00006266template <typename Derived>
6267StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006268 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006269 if (Block.isInvalid())
6270 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006271
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006272 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006273}
6274
David Majnemerfad8f482013-10-15 09:33:02 +00006275template <typename Derived>
6276StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006277 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006278 if (FilterExpr.isInvalid())
6279 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006280
David Majnemer7e755502013-10-15 09:30:14 +00006281 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006282 if (Block.isInvalid())
6283 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006284
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006285 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6286 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006287}
6288
David Majnemerfad8f482013-10-15 09:33:02 +00006289template <typename Derived>
6290StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6291 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006292 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6293 else
6294 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6295}
6296
Alexander Musman64d33f12014-06-04 07:53:32 +00006297//===----------------------------------------------------------------------===//
6298// OpenMP directive transformation
6299//===----------------------------------------------------------------------===//
6300template <typename Derived>
6301StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6302 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006303
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006304 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006305 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006306 ArrayRef<OMPClause *> Clauses = D->clauses();
6307 TClauses.reserve(Clauses.size());
6308 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6309 I != E; ++I) {
6310 if (*I) {
6311 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev758e55e2013-09-06 18:03:48 +00006312 if (!Clause) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006313 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006314 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006315 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006316 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006317 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006318 }
6319 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006320 if (!D->getAssociatedStmt()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006321 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006322 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006323 StmtResult AssociatedStmt =
Alexander Musman64d33f12014-06-04 07:53:32 +00006324 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006325 if (AssociatedStmt.isInvalid()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006326 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006327 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006328
Alexander Musman64d33f12014-06-04 07:53:32 +00006329 return getDerived().RebuildOMPExecutableDirective(
6330 D->getDirectiveKind(), TClauses, AssociatedStmt.get(), D->getLocStart(),
6331 D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006332}
6333
Alexander Musman64d33f12014-06-04 07:53:32 +00006334template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006335StmtResult
6336TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6337 DeclarationNameInfo DirName;
Craig Topperc3ec1492014-05-26 06:22:03 +00006338 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006339 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6340 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6341 return Res;
6342}
6343
Alexander Musman64d33f12014-06-04 07:53:32 +00006344template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006345StmtResult
6346TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6347 DeclarationNameInfo DirName;
Craig Topperc3ec1492014-05-26 06:22:03 +00006348 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006349 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6350 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006351 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006352}
6353
Alexander Musman64d33f12014-06-04 07:53:32 +00006354//===----------------------------------------------------------------------===//
6355// OpenMP clause transformation
6356//===----------------------------------------------------------------------===//
6357template <typename Derived>
6358OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006359 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6360 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006361 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006362 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006363 C->getLParenLoc(), C->getLocEnd());
6364}
6365
Alexander Musman64d33f12014-06-04 07:53:32 +00006366template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006367OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006368TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6369 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6370 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006371 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006372 return getDerived().RebuildOMPNumThreadsClause(
6373 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006374}
6375
Alexey Bataev62c87d22014-03-21 04:51:18 +00006376template <typename Derived>
6377OMPClause *
6378TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6379 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6380 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006381 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006382 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006383 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006384}
6385
Alexander Musman8bd31e62014-05-27 15:12:19 +00006386template <typename Derived>
6387OMPClause *
6388TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6389 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6390 if (E.isInvalid())
6391 return 0;
6392 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006393 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006394}
6395
Alexander Musman64d33f12014-06-04 07:53:32 +00006396template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006397OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006398TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006399 return getDerived().RebuildOMPDefaultClause(
6400 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6401 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006402}
6403
Alexander Musman64d33f12014-06-04 07:53:32 +00006404template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006405OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006406TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006407 return getDerived().RebuildOMPProcBindClause(
6408 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6409 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006410}
6411
Alexander Musman64d33f12014-06-04 07:53:32 +00006412template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006413OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006414TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006415 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006416 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006417 for (auto *VE : C->varlists()) {
6418 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006419 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006420 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006421 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006422 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006423 return getDerived().RebuildOMPPrivateClause(
6424 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006425}
6426
Alexander Musman64d33f12014-06-04 07:53:32 +00006427template <typename Derived>
6428OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
6429 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006430 llvm::SmallVector<Expr *, 16> Vars;
6431 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006432 for (auto *VE : C->varlists()) {
6433 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006434 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006435 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006436 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006437 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006438 return getDerived().RebuildOMPFirstprivateClause(
6439 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006440}
6441
Alexander Musman64d33f12014-06-04 07:53:32 +00006442template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006443OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006444TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6445 llvm::SmallVector<Expr *, 16> Vars;
6446 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006447 for (auto *VE : C->varlists()) {
6448 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006449 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006450 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006451 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006452 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006453 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
6454 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006455}
6456
Alexander Musman64d33f12014-06-04 07:53:32 +00006457template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006458OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006459TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6460 llvm::SmallVector<Expr *, 16> Vars;
6461 Vars.reserve(C->varlist_size());
6462 for (auto *VE : C->varlists()) {
6463 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6464 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006465 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006466 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00006467 }
6468 ExprResult Step = getDerived().TransformExpr(C->getStep());
6469 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006470 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006471 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
6472 C->getLParenLoc(),
6473 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00006474}
6475
Alexander Musman64d33f12014-06-04 07:53:32 +00006476template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00006477OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006478TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
6479 llvm::SmallVector<Expr *, 16> Vars;
6480 Vars.reserve(C->varlist_size());
6481 for (auto *VE : C->varlists()) {
6482 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6483 if (EVar.isInvalid())
6484 return nullptr;
6485 Vars.push_back(EVar.get());
6486 }
6487 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
6488 if (Alignment.isInvalid())
6489 return nullptr;
6490 return getDerived().RebuildOMPAlignedClause(
6491 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
6492 C->getColonLoc(), C->getLocEnd());
6493}
6494
Alexander Musman64d33f12014-06-04 07:53:32 +00006495template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006496OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006497TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6498 llvm::SmallVector<Expr *, 16> Vars;
6499 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006500 for (auto *VE : C->varlists()) {
6501 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006502 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006503 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006504 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006505 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006506 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
6507 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006508}
6509
Douglas Gregorebe10102009-08-20 07:17:43 +00006510//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006511// Expression transformation
6512//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006513template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006514ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006515TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006516 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006517}
Mike Stump11289f42009-09-09 15:08:12 +00006518
6519template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006520ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006521TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006522 NestedNameSpecifierLoc QualifierLoc;
6523 if (E->getQualifierLoc()) {
6524 QualifierLoc
6525 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6526 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006527 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006528 }
John McCallce546572009-12-08 09:08:17 +00006529
6530 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006531 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6532 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006533 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006534 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006535
John McCall815039a2010-08-17 21:27:17 +00006536 DeclarationNameInfo NameInfo = E->getNameInfo();
6537 if (NameInfo.getName()) {
6538 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6539 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006540 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006541 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006542
6543 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006544 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006545 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006546 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006547 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006548
6549 // Mark it referenced in the new context regardless.
6550 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006551 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006552
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006553 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006554 }
John McCallce546572009-12-08 09:08:17 +00006555
Craig Topperc3ec1492014-05-26 06:22:03 +00006556 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00006557 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006558 TemplateArgs = &TransArgs;
6559 TransArgs.setLAngleLoc(E->getLAngleLoc());
6560 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006561 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6562 E->getNumTemplateArgs(),
6563 TransArgs))
6564 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006565 }
6566
Chad Rosier1dcde962012-08-08 18:46:20 +00006567 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006568 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006569}
Mike Stump11289f42009-09-09 15:08:12 +00006570
Douglas Gregora16548e2009-08-11 05:31:07 +00006571template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006572ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006573TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006574 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006575}
Mike Stump11289f42009-09-09 15:08:12 +00006576
Douglas Gregora16548e2009-08-11 05:31:07 +00006577template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006578ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006579TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006580 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006581}
Mike Stump11289f42009-09-09 15:08:12 +00006582
Douglas Gregora16548e2009-08-11 05:31:07 +00006583template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006584ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006585TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006586 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006587}
Mike Stump11289f42009-09-09 15:08:12 +00006588
Douglas Gregora16548e2009-08-11 05:31:07 +00006589template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006590ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006591TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006592 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006593}
Mike Stump11289f42009-09-09 15:08:12 +00006594
Douglas Gregora16548e2009-08-11 05:31:07 +00006595template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006596ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006597TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006598 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006599}
6600
6601template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006602ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006603TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006604 if (FunctionDecl *FD = E->getDirectCallee())
6605 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006606 return SemaRef.MaybeBindToTemporary(E);
6607}
6608
6609template<typename Derived>
6610ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006611TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6612 ExprResult ControllingExpr =
6613 getDerived().TransformExpr(E->getControllingExpr());
6614 if (ControllingExpr.isInvalid())
6615 return ExprError();
6616
Chris Lattner01cf8db2011-07-20 06:58:45 +00006617 SmallVector<Expr *, 4> AssocExprs;
6618 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006619 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6620 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6621 if (TS) {
6622 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6623 if (!AssocType)
6624 return ExprError();
6625 AssocTypes.push_back(AssocType);
6626 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00006627 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00006628 }
6629
6630 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6631 if (AssocExpr.isInvalid())
6632 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006633 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00006634 }
6635
6636 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6637 E->getDefaultLoc(),
6638 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006639 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006640 AssocTypes,
6641 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006642}
6643
6644template<typename Derived>
6645ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006646TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006647 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006648 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006649 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006650
Douglas Gregora16548e2009-08-11 05:31:07 +00006651 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006652 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006653
John McCallb268a282010-08-23 23:25:46 +00006654 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006655 E->getRParen());
6656}
6657
Richard Smithdb2630f2012-10-21 03:28:35 +00006658/// \brief The operand of a unary address-of operator has special rules: it's
6659/// allowed to refer to a non-static member of a class even if there's no 'this'
6660/// object available.
6661template<typename Derived>
6662ExprResult
6663TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6664 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6665 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6666 else
6667 return getDerived().TransformExpr(E);
6668}
6669
Mike Stump11289f42009-09-09 15:08:12 +00006670template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006671ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006672TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006673 ExprResult SubExpr;
6674 if (E->getOpcode() == UO_AddrOf)
6675 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6676 else
6677 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006678 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006679 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006680
Douglas Gregora16548e2009-08-11 05:31:07 +00006681 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006682 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006683
Douglas Gregora16548e2009-08-11 05:31:07 +00006684 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6685 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006686 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006687}
Mike Stump11289f42009-09-09 15:08:12 +00006688
Douglas Gregora16548e2009-08-11 05:31:07 +00006689template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006690ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006691TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6692 // Transform the type.
6693 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6694 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006695 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006696
Douglas Gregor882211c2010-04-28 22:16:22 +00006697 // Transform all of the components into components similar to what the
6698 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006699 // FIXME: It would be slightly more efficient in the non-dependent case to
6700 // just map FieldDecls, rather than requiring the rebuilder to look for
6701 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006702 // template code that we don't care.
6703 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006704 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006705 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006706 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006707 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6708 const Node &ON = E->getComponent(I);
6709 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006710 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006711 Comp.LocStart = ON.getSourceRange().getBegin();
6712 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006713 switch (ON.getKind()) {
6714 case Node::Array: {
6715 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006716 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006717 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006718 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006719
Douglas Gregor882211c2010-04-28 22:16:22 +00006720 ExprChanged = ExprChanged || Index.get() != FromIndex;
6721 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006722 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006723 break;
6724 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006725
Douglas Gregor882211c2010-04-28 22:16:22 +00006726 case Node::Field:
6727 case Node::Identifier:
6728 Comp.isBrackets = false;
6729 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006730 if (!Comp.U.IdentInfo)
6731 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006732
Douglas Gregor882211c2010-04-28 22:16:22 +00006733 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006734
Douglas Gregord1702062010-04-29 00:18:15 +00006735 case Node::Base:
6736 // Will be recomputed during the rebuild.
6737 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006738 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006739
Douglas Gregor882211c2010-04-28 22:16:22 +00006740 Components.push_back(Comp);
6741 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006742
Douglas Gregor882211c2010-04-28 22:16:22 +00006743 // If nothing changed, retain the existing expression.
6744 if (!getDerived().AlwaysRebuild() &&
6745 Type == E->getTypeSourceInfo() &&
6746 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006747 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00006748
Douglas Gregor882211c2010-04-28 22:16:22 +00006749 // Build a new offsetof expression.
6750 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6751 Components.data(), Components.size(),
6752 E->getRParenLoc());
6753}
6754
6755template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006756ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006757TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6758 assert(getDerived().AlreadyTransformed(E->getType()) &&
6759 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006760 return E;
John McCall8d69a212010-11-15 23:31:06 +00006761}
6762
6763template<typename Derived>
6764ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006765TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006766 // Rebuild the syntactic form. The original syntactic form has
6767 // opaque-value expressions in it, so strip those away and rebuild
6768 // the result. This is a really awful way of doing this, but the
6769 // better solution (rebuilding the semantic expressions and
6770 // rebinding OVEs as necessary) doesn't work; we'd need
6771 // TreeTransform to not strip away implicit conversions.
6772 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6773 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006774 if (result.isInvalid()) return ExprError();
6775
6776 // If that gives us a pseudo-object result back, the pseudo-object
6777 // expression must have been an lvalue-to-rvalue conversion which we
6778 // should reapply.
6779 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006780 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00006781
6782 return result;
6783}
6784
6785template<typename Derived>
6786ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006787TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6788 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006789 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006790 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006791
John McCallbcd03502009-12-07 02:54:59 +00006792 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006793 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006794 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006795
John McCall4c98fd82009-11-04 07:28:41 +00006796 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006797 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006798
Peter Collingbournee190dee2011-03-11 19:24:49 +00006799 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6800 E->getKind(),
6801 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006802 }
Mike Stump11289f42009-09-09 15:08:12 +00006803
Eli Friedmane4f22df2012-02-29 04:03:55 +00006804 // C++0x [expr.sizeof]p1:
6805 // The operand is either an expression, which is an unevaluated operand
6806 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006807 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6808 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006809
Eli Friedmane4f22df2012-02-29 04:03:55 +00006810 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6811 if (SubExpr.isInvalid())
6812 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006813
Eli Friedmane4f22df2012-02-29 04:03:55 +00006814 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006815 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006816
Peter Collingbournee190dee2011-03-11 19:24:49 +00006817 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6818 E->getOperatorLoc(),
6819 E->getKind(),
6820 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006821}
Mike Stump11289f42009-09-09 15:08:12 +00006822
Douglas Gregora16548e2009-08-11 05:31:07 +00006823template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006824ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006825TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006826 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006827 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006828 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006829
John McCalldadc5752010-08-24 06:29:42 +00006830 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006831 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006832 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006833
6834
Douglas Gregora16548e2009-08-11 05:31:07 +00006835 if (!getDerived().AlwaysRebuild() &&
6836 LHS.get() == E->getLHS() &&
6837 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006838 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006839
John McCallb268a282010-08-23 23:25:46 +00006840 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006841 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006842 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006843 E->getRBracketLoc());
6844}
Mike Stump11289f42009-09-09 15:08:12 +00006845
6846template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006847ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006848TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006849 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006850 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006851 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006852 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006853
6854 // Transform arguments.
6855 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006856 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006857 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006858 &ArgChanged))
6859 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006860
Douglas Gregora16548e2009-08-11 05:31:07 +00006861 if (!getDerived().AlwaysRebuild() &&
6862 Callee.get() == E->getCallee() &&
6863 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006864 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006865
Douglas Gregora16548e2009-08-11 05:31:07 +00006866 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006867 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006868 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006869 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006870 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006871 E->getRParenLoc());
6872}
Mike Stump11289f42009-09-09 15:08:12 +00006873
6874template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006875ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006876TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006877 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006878 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006879 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006880
Douglas Gregorea972d32011-02-28 21:54:11 +00006881 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006882 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006883 QualifierLoc
6884 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006885
Douglas Gregorea972d32011-02-28 21:54:11 +00006886 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006887 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006888 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00006889 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00006890
Eli Friedman2cfcef62009-12-04 06:40:45 +00006891 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006892 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6893 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006894 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006895 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006896
John McCall16df1e52010-03-30 21:47:33 +00006897 NamedDecl *FoundDecl = E->getFoundDecl();
6898 if (FoundDecl == E->getMemberDecl()) {
6899 FoundDecl = Member;
6900 } else {
6901 FoundDecl = cast_or_null<NamedDecl>(
6902 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6903 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006904 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006905 }
6906
Douglas Gregora16548e2009-08-11 05:31:07 +00006907 if (!getDerived().AlwaysRebuild() &&
6908 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006909 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006910 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006911 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006912 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006913
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006914 // Mark it referenced in the new context regardless.
6915 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006916 SemaRef.MarkMemberReferenced(E);
6917
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006918 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006919 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006920
John McCall6b51f282009-11-23 01:53:49 +00006921 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006922 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006923 TransArgs.setLAngleLoc(E->getLAngleLoc());
6924 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006925 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6926 E->getNumTemplateArgs(),
6927 TransArgs))
6928 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006929 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006930
Douglas Gregora16548e2009-08-11 05:31:07 +00006931 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00006932 SourceLocation FakeOperatorLoc =
6933 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006934
John McCall38836f02010-01-15 08:34:02 +00006935 // FIXME: to do this check properly, we will need to preserve the
6936 // first-qualifier-in-scope here, just in case we had a dependent
6937 // base (and therefore couldn't do the check) and a
6938 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00006939 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00006940
John McCallb268a282010-08-23 23:25:46 +00006941 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006942 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006943 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00006944 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006945 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006946 Member,
John McCall16df1e52010-03-30 21:47:33 +00006947 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006948 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00006949 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00006950 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006951}
Mike Stump11289f42009-09-09 15:08:12 +00006952
Douglas Gregora16548e2009-08-11 05:31:07 +00006953template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006954ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006955TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006956 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006957 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006958 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006959
John McCalldadc5752010-08-24 06:29:42 +00006960 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006961 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006962 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006963
Douglas Gregora16548e2009-08-11 05:31:07 +00006964 if (!getDerived().AlwaysRebuild() &&
6965 LHS.get() == E->getLHS() &&
6966 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006967 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006968
Lang Hames5de91cc2012-10-02 04:45:10 +00006969 Sema::FPContractStateRAII FPContractState(getSema());
6970 getSema().FPFeatures.fp_contract = E->isFPContractable();
6971
Douglas Gregora16548e2009-08-11 05:31:07 +00006972 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006973 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006974}
6975
Mike Stump11289f42009-09-09 15:08:12 +00006976template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006977ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006978TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006979 CompoundAssignOperator *E) {
6980 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006981}
Mike Stump11289f42009-09-09 15:08:12 +00006982
Douglas Gregora16548e2009-08-11 05:31:07 +00006983template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006984ExprResult TreeTransform<Derived>::
6985TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6986 // Just rebuild the common and RHS expressions and see whether we
6987 // get any changes.
6988
6989 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6990 if (commonExpr.isInvalid())
6991 return ExprError();
6992
6993 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6994 if (rhs.isInvalid())
6995 return ExprError();
6996
6997 if (!getDerived().AlwaysRebuild() &&
6998 commonExpr.get() == e->getCommon() &&
6999 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007000 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007001
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007002 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007003 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007004 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007005 e->getColonLoc(),
7006 rhs.get());
7007}
7008
7009template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007010ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007011TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007012 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007013 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007014 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007015
John McCalldadc5752010-08-24 06:29:42 +00007016 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007017 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007018 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007019
John McCalldadc5752010-08-24 06:29:42 +00007020 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007021 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007022 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007023
Douglas Gregora16548e2009-08-11 05:31:07 +00007024 if (!getDerived().AlwaysRebuild() &&
7025 Cond.get() == E->getCond() &&
7026 LHS.get() == E->getLHS() &&
7027 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007028 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007029
John McCallb268a282010-08-23 23:25:46 +00007030 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007031 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007032 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007033 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007034 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007035}
Mike Stump11289f42009-09-09 15:08:12 +00007036
7037template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007038ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007039TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007040 // Implicit casts are eliminated during transformation, since they
7041 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007042 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007043}
Mike Stump11289f42009-09-09 15:08:12 +00007044
Douglas Gregora16548e2009-08-11 05:31:07 +00007045template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007046ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007047TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007048 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7049 if (!Type)
7050 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007051
John McCalldadc5752010-08-24 06:29:42 +00007052 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007053 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007054 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007055 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007056
Douglas Gregora16548e2009-08-11 05:31:07 +00007057 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007058 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007059 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007060 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007061
John McCall97513962010-01-15 18:39:57 +00007062 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007063 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007064 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007065 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007066}
Mike Stump11289f42009-09-09 15:08:12 +00007067
Douglas Gregora16548e2009-08-11 05:31:07 +00007068template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007069ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007070TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007071 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7072 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7073 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007074 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007075
John McCalldadc5752010-08-24 06:29:42 +00007076 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007077 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007078 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007079
Douglas Gregora16548e2009-08-11 05:31:07 +00007080 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007081 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007082 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007083 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007084
John McCall5d7aa7f2010-01-19 22:33:45 +00007085 // Note: the expression type doesn't necessarily match the
7086 // type-as-written, but that's okay, because it should always be
7087 // derivable from the initializer.
7088
John McCalle15bbff2010-01-18 19:35:47 +00007089 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007090 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007091 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007092}
Mike Stump11289f42009-09-09 15:08:12 +00007093
Douglas Gregora16548e2009-08-11 05:31:07 +00007094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007095ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007096TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007097 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007098 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007099 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007100
Douglas Gregora16548e2009-08-11 05:31:07 +00007101 if (!getDerived().AlwaysRebuild() &&
7102 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007103 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007104
Douglas Gregora16548e2009-08-11 05:31:07 +00007105 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007106 SourceLocation FakeOperatorLoc =
7107 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007108 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007109 E->getAccessorLoc(),
7110 E->getAccessor());
7111}
Mike Stump11289f42009-09-09 15:08:12 +00007112
Douglas Gregora16548e2009-08-11 05:31:07 +00007113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007114ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007115TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007116 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007117
Benjamin Kramerf0623432012-08-23 22:51:59 +00007118 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007119 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007120 Inits, &InitChanged))
7121 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007122
Douglas Gregora16548e2009-08-11 05:31:07 +00007123 if (!getDerived().AlwaysRebuild() && !InitChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007124 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007125
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007126 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007127 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007128}
Mike Stump11289f42009-09-09 15:08:12 +00007129
Douglas Gregora16548e2009-08-11 05:31:07 +00007130template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007131ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007132TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007133 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007134
Douglas Gregorebe10102009-08-20 07:17:43 +00007135 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007136 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007137 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007138 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007139
Douglas Gregorebe10102009-08-20 07:17:43 +00007140 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007141 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007142 bool ExprChanged = false;
7143 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7144 DEnd = E->designators_end();
7145 D != DEnd; ++D) {
7146 if (D->isFieldDesignator()) {
7147 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7148 D->getDotLoc(),
7149 D->getFieldLoc()));
7150 continue;
7151 }
Mike Stump11289f42009-09-09 15:08:12 +00007152
Douglas Gregora16548e2009-08-11 05:31:07 +00007153 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007154 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007155 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007156 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007157
7158 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007159 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007160
Douglas Gregora16548e2009-08-11 05:31:07 +00007161 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007162 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007163 continue;
7164 }
Mike Stump11289f42009-09-09 15:08:12 +00007165
Douglas Gregora16548e2009-08-11 05:31:07 +00007166 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007167 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007168 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7169 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007170 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007171
John McCalldadc5752010-08-24 06:29:42 +00007172 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007173 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007174 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007175
7176 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007177 End.get(),
7178 D->getLBracketLoc(),
7179 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007180
Douglas Gregora16548e2009-08-11 05:31:07 +00007181 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7182 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007183
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007184 ArrayExprs.push_back(Start.get());
7185 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007186 }
Mike Stump11289f42009-09-09 15:08:12 +00007187
Douglas Gregora16548e2009-08-11 05:31:07 +00007188 if (!getDerived().AlwaysRebuild() &&
7189 Init.get() == E->getInit() &&
7190 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007191 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007192
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007193 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007194 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007195 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007196}
Mike Stump11289f42009-09-09 15:08:12 +00007197
Douglas Gregora16548e2009-08-11 05:31:07 +00007198template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007199ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007200TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007201 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007202 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007203
Douglas Gregor3da3c062009-10-28 00:29:27 +00007204 // FIXME: Will we ever have proper type location here? Will we actually
7205 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007206 QualType T = getDerived().TransformType(E->getType());
7207 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007208 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007209
Douglas Gregora16548e2009-08-11 05:31:07 +00007210 if (!getDerived().AlwaysRebuild() &&
7211 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007212 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007213
Douglas Gregora16548e2009-08-11 05:31:07 +00007214 return getDerived().RebuildImplicitValueInitExpr(T);
7215}
Mike Stump11289f42009-09-09 15:08:12 +00007216
Douglas Gregora16548e2009-08-11 05:31:07 +00007217template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007218ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007219TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007220 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7221 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007222 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007223
John McCalldadc5752010-08-24 06:29:42 +00007224 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007225 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007226 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007227
Douglas Gregora16548e2009-08-11 05:31:07 +00007228 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007229 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007230 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007231 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007232
John McCallb268a282010-08-23 23:25:46 +00007233 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007234 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007235}
7236
7237template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007238ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007239TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007240 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007241 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007242 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7243 &ArgumentChanged))
7244 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007245
Douglas Gregora16548e2009-08-11 05:31:07 +00007246 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007247 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007248 E->getRParenLoc());
7249}
Mike Stump11289f42009-09-09 15:08:12 +00007250
Douglas Gregora16548e2009-08-11 05:31:07 +00007251/// \brief Transform an address-of-label expression.
7252///
7253/// By default, the transformation of an address-of-label expression always
7254/// rebuilds the expression, so that the label identifier can be resolved to
7255/// the corresponding label statement by semantic analysis.
7256template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007257ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007258TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007259 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7260 E->getLabel());
7261 if (!LD)
7262 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007263
Douglas Gregora16548e2009-08-11 05:31:07 +00007264 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007265 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007266}
Mike Stump11289f42009-09-09 15:08:12 +00007267
7268template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007269ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007270TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007271 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007272 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007273 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007274 if (SubStmt.isInvalid()) {
7275 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007276 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007277 }
Mike Stump11289f42009-09-09 15:08:12 +00007278
Douglas Gregora16548e2009-08-11 05:31:07 +00007279 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007280 SubStmt.get() == E->getSubStmt()) {
7281 // Calling this an 'error' is unintuitive, but it does the right thing.
7282 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007283 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007284 }
Mike Stump11289f42009-09-09 15:08:12 +00007285
7286 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007287 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007288 E->getRParenLoc());
7289}
Mike Stump11289f42009-09-09 15:08:12 +00007290
Douglas Gregora16548e2009-08-11 05:31:07 +00007291template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007292ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007293TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007294 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007295 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007296 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007297
John McCalldadc5752010-08-24 06:29:42 +00007298 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007299 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007300 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007301
John McCalldadc5752010-08-24 06:29:42 +00007302 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007303 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007304 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007305
Douglas Gregora16548e2009-08-11 05:31:07 +00007306 if (!getDerived().AlwaysRebuild() &&
7307 Cond.get() == E->getCond() &&
7308 LHS.get() == E->getLHS() &&
7309 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007310 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007311
Douglas Gregora16548e2009-08-11 05:31:07 +00007312 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007313 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007314 E->getRParenLoc());
7315}
Mike Stump11289f42009-09-09 15:08:12 +00007316
Douglas Gregora16548e2009-08-11 05:31:07 +00007317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007318ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007319TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007320 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007321}
7322
7323template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007324ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007325TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007326 switch (E->getOperator()) {
7327 case OO_New:
7328 case OO_Delete:
7329 case OO_Array_New:
7330 case OO_Array_Delete:
7331 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007332
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007333 case OO_Call: {
7334 // This is a call to an object's operator().
7335 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7336
7337 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007338 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007339 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007340 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007341
7342 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007343 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7344 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007345
7346 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007347 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007348 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007349 Args))
7350 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007351
John McCallb268a282010-08-23 23:25:46 +00007352 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007353 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007354 E->getLocEnd());
7355 }
7356
7357#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7358 case OO_##Name:
7359#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7360#include "clang/Basic/OperatorKinds.def"
7361 case OO_Subscript:
7362 // Handled below.
7363 break;
7364
7365 case OO_Conditional:
7366 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007367
7368 case OO_None:
7369 case NUM_OVERLOADED_OPERATORS:
7370 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007371 }
7372
John McCalldadc5752010-08-24 06:29:42 +00007373 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007374 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007375 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007376
Richard Smithdb2630f2012-10-21 03:28:35 +00007377 ExprResult First;
7378 if (E->getOperator() == OO_Amp)
7379 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7380 else
7381 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007382 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007383 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007384
John McCalldadc5752010-08-24 06:29:42 +00007385 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007386 if (E->getNumArgs() == 2) {
7387 Second = getDerived().TransformExpr(E->getArg(1));
7388 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007389 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007390 }
Mike Stump11289f42009-09-09 15:08:12 +00007391
Douglas Gregora16548e2009-08-11 05:31:07 +00007392 if (!getDerived().AlwaysRebuild() &&
7393 Callee.get() == E->getCallee() &&
7394 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007395 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007396 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007397
Lang Hames5de91cc2012-10-02 04:45:10 +00007398 Sema::FPContractStateRAII FPContractState(getSema());
7399 getSema().FPFeatures.fp_contract = E->isFPContractable();
7400
Douglas Gregora16548e2009-08-11 05:31:07 +00007401 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7402 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007403 Callee.get(),
7404 First.get(),
7405 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007406}
Mike Stump11289f42009-09-09 15:08:12 +00007407
Douglas Gregora16548e2009-08-11 05:31:07 +00007408template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007409ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007410TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7411 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007412}
Mike Stump11289f42009-09-09 15:08:12 +00007413
Douglas Gregora16548e2009-08-11 05:31:07 +00007414template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007415ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007416TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7417 // Transform the callee.
7418 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7419 if (Callee.isInvalid())
7420 return ExprError();
7421
7422 // Transform exec config.
7423 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7424 if (EC.isInvalid())
7425 return ExprError();
7426
7427 // Transform arguments.
7428 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007429 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007430 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007431 &ArgChanged))
7432 return ExprError();
7433
7434 if (!getDerived().AlwaysRebuild() &&
7435 Callee.get() == E->getCallee() &&
7436 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007437 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007438
7439 // FIXME: Wrong source location information for the '('.
7440 SourceLocation FakeLParenLoc
7441 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7442 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007443 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007444 E->getRParenLoc(), EC.get());
7445}
7446
7447template<typename Derived>
7448ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007449TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007450 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7451 if (!Type)
7452 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007453
John McCalldadc5752010-08-24 06:29:42 +00007454 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007455 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007456 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007457 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007458
Douglas Gregora16548e2009-08-11 05:31:07 +00007459 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007460 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007461 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007462 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007463 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007464 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007465 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007466 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007467 E->getAngleBrackets().getEnd(),
7468 // FIXME. this should be '(' location
7469 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007470 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007471 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007472}
Mike Stump11289f42009-09-09 15:08:12 +00007473
Douglas Gregora16548e2009-08-11 05:31:07 +00007474template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007475ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007476TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7477 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007478}
Mike Stump11289f42009-09-09 15:08:12 +00007479
7480template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007481ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007482TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7483 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007484}
7485
Douglas Gregora16548e2009-08-11 05:31:07 +00007486template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007487ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007488TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007489 CXXReinterpretCastExpr *E) {
7490 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007491}
Mike Stump11289f42009-09-09 15:08:12 +00007492
Douglas Gregora16548e2009-08-11 05:31:07 +00007493template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007494ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007495TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7496 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007497}
Mike Stump11289f42009-09-09 15:08:12 +00007498
Douglas Gregora16548e2009-08-11 05:31:07 +00007499template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007500ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007501TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007502 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007503 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7504 if (!Type)
7505 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007506
John McCalldadc5752010-08-24 06:29:42 +00007507 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007508 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007509 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007510 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007511
Douglas Gregora16548e2009-08-11 05:31:07 +00007512 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007513 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007514 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007515 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007516
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007517 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007518 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007519 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007520 E->getRParenLoc());
7521}
Mike Stump11289f42009-09-09 15:08:12 +00007522
Douglas Gregora16548e2009-08-11 05:31:07 +00007523template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007524ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007525TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007526 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007527 TypeSourceInfo *TInfo
7528 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7529 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007530 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007531
Douglas Gregora16548e2009-08-11 05:31:07 +00007532 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007533 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007534 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007535
Douglas Gregor9da64192010-04-26 22:37:10 +00007536 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7537 E->getLocStart(),
7538 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007539 E->getLocEnd());
7540 }
Mike Stump11289f42009-09-09 15:08:12 +00007541
Eli Friedman456f0182012-01-20 01:26:23 +00007542 // We don't know whether the subexpression is potentially evaluated until
7543 // after we perform semantic analysis. We speculatively assume it is
7544 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007545 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007546 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7547 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007548
John McCalldadc5752010-08-24 06:29:42 +00007549 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007550 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007551 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007552
Douglas Gregora16548e2009-08-11 05:31:07 +00007553 if (!getDerived().AlwaysRebuild() &&
7554 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007555 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007556
Douglas Gregor9da64192010-04-26 22:37:10 +00007557 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7558 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007559 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007560 E->getLocEnd());
7561}
7562
7563template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007564ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007565TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7566 if (E->isTypeOperand()) {
7567 TypeSourceInfo *TInfo
7568 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7569 if (!TInfo)
7570 return ExprError();
7571
7572 if (!getDerived().AlwaysRebuild() &&
7573 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007574 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007575
Douglas Gregor69735112011-03-06 17:40:41 +00007576 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007577 E->getLocStart(),
7578 TInfo,
7579 E->getLocEnd());
7580 }
7581
Francois Pichet9f4f2072010-09-08 12:20:18 +00007582 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7583
7584 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7585 if (SubExpr.isInvalid())
7586 return ExprError();
7587
7588 if (!getDerived().AlwaysRebuild() &&
7589 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007590 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007591
7592 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7593 E->getLocStart(),
7594 SubExpr.get(),
7595 E->getLocEnd());
7596}
7597
7598template<typename Derived>
7599ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007600TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007601 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007602}
Mike Stump11289f42009-09-09 15:08:12 +00007603
Douglas Gregora16548e2009-08-11 05:31:07 +00007604template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007605ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007606TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007607 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007608 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007609}
Mike Stump11289f42009-09-09 15:08:12 +00007610
Douglas Gregora16548e2009-08-11 05:31:07 +00007611template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007612ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007613TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007614 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007615
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007616 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7617 // Make sure that we capture 'this'.
7618 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007619 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007620 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007621
Douglas Gregorb15af892010-01-07 23:12:05 +00007622 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007623}
Mike Stump11289f42009-09-09 15:08:12 +00007624
Douglas Gregora16548e2009-08-11 05:31:07 +00007625template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007626ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007627TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007628 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007629 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007630 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007631
Douglas Gregora16548e2009-08-11 05:31:07 +00007632 if (!getDerived().AlwaysRebuild() &&
7633 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007634 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007635
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007636 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7637 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007638}
Mike Stump11289f42009-09-09 15:08:12 +00007639
Douglas Gregora16548e2009-08-11 05:31:07 +00007640template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007641ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007642TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007643 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007644 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7645 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007646 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007647 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007648
Chandler Carruth794da4c2010-02-08 06:42:49 +00007649 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007650 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007651 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007652
Douglas Gregor033f6752009-12-23 23:03:06 +00007653 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007654}
Mike Stump11289f42009-09-09 15:08:12 +00007655
Douglas Gregora16548e2009-08-11 05:31:07 +00007656template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007657ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007658TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7659 FieldDecl *Field
7660 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7661 E->getField()));
7662 if (!Field)
7663 return ExprError();
7664
7665 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007666 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00007667
7668 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7669}
7670
7671template<typename Derived>
7672ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007673TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7674 CXXScalarValueInitExpr *E) {
7675 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7676 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007677 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007678
Douglas Gregora16548e2009-08-11 05:31:07 +00007679 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007680 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007681 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007682
Chad Rosier1dcde962012-08-08 18:46:20 +00007683 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007684 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007685 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007686}
Mike Stump11289f42009-09-09 15:08:12 +00007687
Douglas Gregora16548e2009-08-11 05:31:07 +00007688template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007689ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007690TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007691 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007692 TypeSourceInfo *AllocTypeInfo
7693 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7694 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007695 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007696
Douglas Gregora16548e2009-08-11 05:31:07 +00007697 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007698 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007699 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007700 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007701
Douglas Gregora16548e2009-08-11 05:31:07 +00007702 // Transform the placement arguments (if any).
7703 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007704 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007705 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007706 E->getNumPlacementArgs(), true,
7707 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007708 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007709
Sebastian Redl6047f072012-02-16 12:22:20 +00007710 // Transform the initializer (if any).
7711 Expr *OldInit = E->getInitializer();
7712 ExprResult NewInit;
7713 if (OldInit)
7714 NewInit = getDerived().TransformExpr(OldInit);
7715 if (NewInit.isInvalid())
7716 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007717
Sebastian Redl6047f072012-02-16 12:22:20 +00007718 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00007719 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007720 if (E->getOperatorNew()) {
7721 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007722 getDerived().TransformDecl(E->getLocStart(),
7723 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007724 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007725 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007726 }
7727
Craig Topperc3ec1492014-05-26 06:22:03 +00007728 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007729 if (E->getOperatorDelete()) {
7730 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007731 getDerived().TransformDecl(E->getLocStart(),
7732 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007733 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007734 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007735 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007736
Douglas Gregora16548e2009-08-11 05:31:07 +00007737 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007738 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007739 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007740 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007741 OperatorNew == E->getOperatorNew() &&
7742 OperatorDelete == E->getOperatorDelete() &&
7743 !ArgumentChanged) {
7744 // Mark any declarations we need as referenced.
7745 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007746 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007747 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007748 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007749 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007750
Sebastian Redl6047f072012-02-16 12:22:20 +00007751 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007752 QualType ElementType
7753 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7754 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7755 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7756 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007757 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007758 }
7759 }
7760 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007761
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007762 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007763 }
Mike Stump11289f42009-09-09 15:08:12 +00007764
Douglas Gregor0744ef62010-09-07 21:49:58 +00007765 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007766 if (!ArraySize.get()) {
7767 // If no array size was specified, but the new expression was
7768 // instantiated with an array type (e.g., "new T" where T is
7769 // instantiated with "int[4]"), extract the outer bound from the
7770 // array type as our array size. We do this with constant and
7771 // dependently-sized array types.
7772 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7773 if (!ArrayT) {
7774 // Do nothing
7775 } else if (const ConstantArrayType *ConsArrayT
7776 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007777 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
7778 SemaRef.Context.getSizeType(),
7779 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007780 AllocType = ConsArrayT->getElementType();
7781 } else if (const DependentSizedArrayType *DepArrayT
7782 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7783 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007784 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007785 AllocType = DepArrayT->getElementType();
7786 }
7787 }
7788 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007789
Douglas Gregora16548e2009-08-11 05:31:07 +00007790 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7791 E->isGlobalNew(),
7792 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007793 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007794 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007795 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007796 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007797 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007798 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007799 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007800 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007801}
Mike Stump11289f42009-09-09 15:08:12 +00007802
Douglas Gregora16548e2009-08-11 05:31:07 +00007803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007804ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007805TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007806 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007807 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007808 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007809
Douglas Gregord2d9da02010-02-26 00:38:10 +00007810 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00007811 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007812 if (E->getOperatorDelete()) {
7813 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007814 getDerived().TransformDecl(E->getLocStart(),
7815 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007816 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007817 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007818 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007819
Douglas Gregora16548e2009-08-11 05:31:07 +00007820 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007821 Operand.get() == E->getArgument() &&
7822 OperatorDelete == E->getOperatorDelete()) {
7823 // Mark any declarations we need as referenced.
7824 // FIXME: instantiation-specific.
7825 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007826 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007827
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007828 if (!E->getArgument()->isTypeDependent()) {
7829 QualType Destroyed = SemaRef.Context.getBaseElementType(
7830 E->getDestroyedType());
7831 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7832 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007833 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007834 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007835 }
7836 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007837
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007838 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007839 }
Mike Stump11289f42009-09-09 15:08:12 +00007840
Douglas Gregora16548e2009-08-11 05:31:07 +00007841 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7842 E->isGlobalDelete(),
7843 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007844 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007845}
Mike Stump11289f42009-09-09 15:08:12 +00007846
Douglas Gregora16548e2009-08-11 05:31:07 +00007847template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007848ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007849TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007850 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007851 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007852 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007853 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007854
John McCallba7bf592010-08-24 05:47:05 +00007855 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007856 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007857 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007858 E->getOperatorLoc(),
7859 E->isArrow()? tok::arrow : tok::period,
7860 ObjectTypePtr,
7861 MayBePseudoDestructor);
7862 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007863 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007864
John McCallba7bf592010-08-24 05:47:05 +00007865 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007866 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7867 if (QualifierLoc) {
7868 QualifierLoc
7869 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7870 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007871 return ExprError();
7872 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007873 CXXScopeSpec SS;
7874 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007875
Douglas Gregor678f90d2010-02-25 01:56:36 +00007876 PseudoDestructorTypeStorage Destroyed;
7877 if (E->getDestroyedTypeInfo()) {
7878 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007879 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007880 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007881 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007882 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007883 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007884 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007885 // We aren't likely to be able to resolve the identifier down to a type
7886 // now anyway, so just retain the identifier.
7887 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7888 E->getDestroyedTypeLoc());
7889 } else {
7890 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007891 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007892 *E->getDestroyedTypeIdentifier(),
7893 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007894 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007895 SS, ObjectTypePtr,
7896 false);
7897 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007898 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007899
Douglas Gregor678f90d2010-02-25 01:56:36 +00007900 Destroyed
7901 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7902 E->getDestroyedTypeLoc());
7903 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007904
Craig Topperc3ec1492014-05-26 06:22:03 +00007905 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007906 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00007907 CXXScopeSpec EmptySS;
7908 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00007909 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007910 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007911 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007912 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007913
John McCallb268a282010-08-23 23:25:46 +00007914 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007915 E->getOperatorLoc(),
7916 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007917 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007918 ScopeTypeInfo,
7919 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007920 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007921 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007922}
Mike Stump11289f42009-09-09 15:08:12 +00007923
Douglas Gregorad8a3362009-09-04 17:36:40 +00007924template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007925ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007926TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007927 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007928 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7929 Sema::LookupOrdinaryName);
7930
7931 // Transform all the decls.
7932 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7933 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007934 NamedDecl *InstD = static_cast<NamedDecl*>(
7935 getDerived().TransformDecl(Old->getNameLoc(),
7936 *I));
John McCall84d87672009-12-10 09:41:52 +00007937 if (!InstD) {
7938 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7939 // This can happen because of dependent hiding.
7940 if (isa<UsingShadowDecl>(*I))
7941 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00007942 else {
7943 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007944 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007945 }
John McCall84d87672009-12-10 09:41:52 +00007946 }
John McCalle66edc12009-11-24 19:00:30 +00007947
7948 // Expand using declarations.
7949 if (isa<UsingDecl>(InstD)) {
7950 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00007951 for (auto *I : UD->shadows())
7952 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00007953 continue;
7954 }
7955
7956 R.addDecl(InstD);
7957 }
7958
7959 // Resolve a kind, but don't do any further analysis. If it's
7960 // ambiguous, the callee needs to deal with it.
7961 R.resolveKind();
7962
7963 // Rebuild the nested-name qualifier, if present.
7964 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007965 if (Old->getQualifierLoc()) {
7966 NestedNameSpecifierLoc QualifierLoc
7967 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7968 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007969 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007970
Douglas Gregor0da1d432011-02-28 20:01:57 +00007971 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00007972 }
7973
Douglas Gregor9262f472010-04-27 18:19:34 +00007974 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007975 CXXRecordDecl *NamingClass
7976 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7977 Old->getNameLoc(),
7978 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00007979 if (!NamingClass) {
7980 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007981 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007982 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007983
Douglas Gregorda7be082010-04-27 16:10:10 +00007984 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007985 }
7986
Abramo Bagnara7945c982012-01-27 09:46:47 +00007987 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7988
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007989 // If we have neither explicit template arguments, nor the template keyword,
7990 // it's a normal declaration name.
7991 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00007992 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7993
7994 // If we have template arguments, rebuild them, then rebuild the
7995 // templateid expression.
7996 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00007997 if (Old->hasExplicitTemplateArgs() &&
7998 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00007999 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008000 TransArgs)) {
8001 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008002 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008003 }
John McCalle66edc12009-11-24 19:00:30 +00008004
Abramo Bagnara7945c982012-01-27 09:46:47 +00008005 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008006 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008007}
Mike Stump11289f42009-09-09 15:08:12 +00008008
Douglas Gregora16548e2009-08-11 05:31:07 +00008009template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008010ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008011TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8012 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008013 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008014 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8015 TypeSourceInfo *From = E->getArg(I);
8016 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008017 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008018 TypeLocBuilder TLB;
8019 TLB.reserve(FromTL.getFullDataSize());
8020 QualType To = getDerived().TransformType(TLB, FromTL);
8021 if (To.isNull())
8022 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008023
Douglas Gregor29c42f22012-02-24 07:38:34 +00008024 if (To == From->getType())
8025 Args.push_back(From);
8026 else {
8027 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8028 ArgChanged = true;
8029 }
8030 continue;
8031 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008032
Douglas Gregor29c42f22012-02-24 07:38:34 +00008033 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008034
Douglas Gregor29c42f22012-02-24 07:38:34 +00008035 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008036 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008037 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8038 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8039 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008040
Douglas Gregor29c42f22012-02-24 07:38:34 +00008041 // Determine whether the set of unexpanded parameter packs can and should
8042 // be expanded.
8043 bool Expand = true;
8044 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008045 Optional<unsigned> OrigNumExpansions =
8046 ExpansionTL.getTypePtr()->getNumExpansions();
8047 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008048 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8049 PatternTL.getSourceRange(),
8050 Unexpanded,
8051 Expand, RetainExpansion,
8052 NumExpansions))
8053 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008054
Douglas Gregor29c42f22012-02-24 07:38:34 +00008055 if (!Expand) {
8056 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008057 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008058 // expansion.
8059 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008060
Douglas Gregor29c42f22012-02-24 07:38:34 +00008061 TypeLocBuilder TLB;
8062 TLB.reserve(From->getTypeLoc().getFullDataSize());
8063
8064 QualType To = getDerived().TransformType(TLB, PatternTL);
8065 if (To.isNull())
8066 return ExprError();
8067
Chad Rosier1dcde962012-08-08 18:46:20 +00008068 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008069 PatternTL.getSourceRange(),
8070 ExpansionTL.getEllipsisLoc(),
8071 NumExpansions);
8072 if (To.isNull())
8073 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008074
Douglas Gregor29c42f22012-02-24 07:38:34 +00008075 PackExpansionTypeLoc ToExpansionTL
8076 = TLB.push<PackExpansionTypeLoc>(To);
8077 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8078 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8079 continue;
8080 }
8081
8082 // Expand the pack expansion by substituting for each argument in the
8083 // pack(s).
8084 for (unsigned I = 0; I != *NumExpansions; ++I) {
8085 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8086 TypeLocBuilder TLB;
8087 TLB.reserve(PatternTL.getFullDataSize());
8088 QualType To = getDerived().TransformType(TLB, PatternTL);
8089 if (To.isNull())
8090 return ExprError();
8091
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008092 if (To->containsUnexpandedParameterPack()) {
8093 To = getDerived().RebuildPackExpansionType(To,
8094 PatternTL.getSourceRange(),
8095 ExpansionTL.getEllipsisLoc(),
8096 NumExpansions);
8097 if (To.isNull())
8098 return ExprError();
8099
8100 PackExpansionTypeLoc ToExpansionTL
8101 = TLB.push<PackExpansionTypeLoc>(To);
8102 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8103 }
8104
Douglas Gregor29c42f22012-02-24 07:38:34 +00008105 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8106 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008107
Douglas Gregor29c42f22012-02-24 07:38:34 +00008108 if (!RetainExpansion)
8109 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008110
Douglas Gregor29c42f22012-02-24 07:38:34 +00008111 // If we're supposed to retain a pack expansion, do so by temporarily
8112 // forgetting the partially-substituted parameter pack.
8113 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8114
8115 TypeLocBuilder TLB;
8116 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008117
Douglas Gregor29c42f22012-02-24 07:38:34 +00008118 QualType To = getDerived().TransformType(TLB, PatternTL);
8119 if (To.isNull())
8120 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008121
8122 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008123 PatternTL.getSourceRange(),
8124 ExpansionTL.getEllipsisLoc(),
8125 NumExpansions);
8126 if (To.isNull())
8127 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008128
Douglas Gregor29c42f22012-02-24 07:38:34 +00008129 PackExpansionTypeLoc ToExpansionTL
8130 = TLB.push<PackExpansionTypeLoc>(To);
8131 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8132 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8133 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008134
Douglas Gregor29c42f22012-02-24 07:38:34 +00008135 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008136 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008137
8138 return getDerived().RebuildTypeTrait(E->getTrait(),
8139 E->getLocStart(),
8140 Args,
8141 E->getLocEnd());
8142}
8143
8144template<typename Derived>
8145ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008146TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8147 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8148 if (!T)
8149 return ExprError();
8150
8151 if (!getDerived().AlwaysRebuild() &&
8152 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008153 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008154
8155 ExprResult SubExpr;
8156 {
8157 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8158 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8159 if (SubExpr.isInvalid())
8160 return ExprError();
8161
8162 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008163 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008164 }
8165
8166 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8167 E->getLocStart(),
8168 T,
8169 SubExpr.get(),
8170 E->getLocEnd());
8171}
8172
8173template<typename Derived>
8174ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008175TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8176 ExprResult SubExpr;
8177 {
8178 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8179 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8180 if (SubExpr.isInvalid())
8181 return ExprError();
8182
8183 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008184 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008185 }
8186
8187 return getDerived().RebuildExpressionTrait(
8188 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8189}
8190
8191template<typename Derived>
8192ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008193TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008194 DependentScopeDeclRefExpr *E) {
Richard Smithdb2630f2012-10-21 03:28:35 +00008195 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8196}
8197
8198template<typename Derived>
8199ExprResult
8200TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8201 DependentScopeDeclRefExpr *E,
8202 bool IsAddressOfOperand) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008203 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008204 NestedNameSpecifierLoc QualifierLoc
8205 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8206 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008207 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008208 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008209
John McCall31f82722010-11-12 08:19:04 +00008210 // TODO: If this is a conversion-function-id, verify that the
8211 // destination type name (if present) resolves the same way after
8212 // instantiation as it did in the local scope.
8213
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008214 DeclarationNameInfo NameInfo
8215 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8216 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008217 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008218
John McCalle66edc12009-11-24 19:00:30 +00008219 if (!E->hasExplicitTemplateArgs()) {
8220 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008221 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008222 // Note: it is sufficient to compare the Name component of NameInfo:
8223 // if name has not changed, DNLoc has not changed either.
8224 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008225 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008226
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008227 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00008228 TemplateKWLoc,
8229 NameInfo,
8230 /*TemplateArgs*/nullptr,
8231 IsAddressOfOperand);
Douglas Gregord019ff62009-10-22 17:20:55 +00008232 }
John McCall6b51f282009-11-23 01:53:49 +00008233
8234 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008235 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8236 E->getNumTemplateArgs(),
8237 TransArgs))
8238 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008239
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008240 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008241 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008242 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008243 &TransArgs,
8244 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00008245}
8246
8247template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008248ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008249TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008250 // CXXConstructExprs other than for list-initialization and
8251 // CXXTemporaryObjectExpr are always implicit, so when we have
8252 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008253 if ((E->getNumArgs() == 1 ||
8254 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008255 (!getDerived().DropCallArgument(E->getArg(0))) &&
8256 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008257 return getDerived().TransformExpr(E->getArg(0));
8258
Douglas Gregora16548e2009-08-11 05:31:07 +00008259 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8260
8261 QualType T = getDerived().TransformType(E->getType());
8262 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008263 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008264
8265 CXXConstructorDecl *Constructor
8266 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008267 getDerived().TransformDecl(E->getLocStart(),
8268 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008269 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008270 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008271
Douglas Gregora16548e2009-08-11 05:31:07 +00008272 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008273 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008274 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008275 &ArgumentChanged))
8276 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008277
Douglas Gregora16548e2009-08-11 05:31:07 +00008278 if (!getDerived().AlwaysRebuild() &&
8279 T == E->getType() &&
8280 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008281 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008282 // Mark the constructor as referenced.
8283 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008284 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008285 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00008286 }
Mike Stump11289f42009-09-09 15:08:12 +00008287
Douglas Gregordb121ba2009-12-14 16:27:04 +00008288 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8289 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008290 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008291 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008292 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008293 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008294 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008295 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008296}
Mike Stump11289f42009-09-09 15:08:12 +00008297
Douglas Gregora16548e2009-08-11 05:31:07 +00008298/// \brief Transform a C++ temporary-binding expression.
8299///
Douglas Gregor363b1512009-12-24 18:51:59 +00008300/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8301/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008302template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008303ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008304TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008305 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008306}
Mike Stump11289f42009-09-09 15:08:12 +00008307
John McCall5d413782010-12-06 08:20:24 +00008308/// \brief Transform a C++ expression that contains cleanups that should
8309/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008310///
John McCall5d413782010-12-06 08:20:24 +00008311/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008312/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008313template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008314ExprResult
John McCall5d413782010-12-06 08:20:24 +00008315TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008316 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008317}
Mike Stump11289f42009-09-09 15:08:12 +00008318
Douglas Gregora16548e2009-08-11 05:31:07 +00008319template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008320ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008321TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008322 CXXTemporaryObjectExpr *E) {
8323 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8324 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008325 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008326
Douglas Gregora16548e2009-08-11 05:31:07 +00008327 CXXConstructorDecl *Constructor
8328 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008329 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008330 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008331 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008332 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008333
Douglas Gregora16548e2009-08-11 05:31:07 +00008334 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008335 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008336 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008337 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008338 &ArgumentChanged))
8339 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008340
Douglas Gregora16548e2009-08-11 05:31:07 +00008341 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008342 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008343 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008344 !ArgumentChanged) {
8345 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008346 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008347 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008348 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008349
Richard Smithd59b8322012-12-19 01:39:02 +00008350 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008351 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8352 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008353 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008354 E->getLocEnd());
8355}
Mike Stump11289f42009-09-09 15:08:12 +00008356
Douglas Gregora16548e2009-08-11 05:31:07 +00008357template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008358ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008359TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008360
8361 // Transform any init-capture expressions before entering the scope of the
8362 // lambda body, because they are not semantically within that scope.
8363 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8364 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8365 E->explicit_capture_begin());
8366
8367 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8368 CEnd = E->capture_end();
8369 C != CEnd; ++C) {
8370 if (!C->isInitCapture())
8371 continue;
8372 EnterExpressionEvaluationContext EEEC(getSema(),
8373 Sema::PotentiallyEvaluated);
8374 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8375 C->getCapturedVar()->getInit(),
8376 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8377
8378 if (NewExprInitResult.isInvalid())
8379 return ExprError();
8380 Expr *NewExprInit = NewExprInitResult.get();
8381
8382 VarDecl *OldVD = C->getCapturedVar();
8383 QualType NewInitCaptureType =
8384 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8385 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8386 NewExprInit);
8387 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008388 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8389 std::make_pair(NewExprInitResult, NewInitCaptureType);
8390
8391 }
8392
Faisal Vali524ca282013-11-12 01:40:44 +00008393 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008394 // Transform the template parameters, and add them to the current
8395 // instantiation scope. The null case is handled correctly.
8396 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8397 E->getTemplateParameterList());
8398
8399 // Check to see if the TypeSourceInfo of the call operator needs to
8400 // be transformed, and if so do the transformation in the
8401 // CurrentInstantiationScope.
8402
8403 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8404 FunctionProtoTypeLoc OldCallOpFPTL =
8405 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Craig Topperc3ec1492014-05-26 06:22:03 +00008406 TypeSourceInfo *NewCallOpTSI = nullptr;
8407
Faisal Vali2cba1332013-10-23 06:44:28 +00008408 const bool CallOpWasAlreadyTransformed =
8409 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8410
8411 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8412 if (CallOpWasAlreadyTransformed)
8413 NewCallOpTSI = OldCallOpTSI;
8414 else {
8415 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8416 // The transformation MUST be done in the CurrentInstantiationScope since
8417 // it introduces a mapping of the original to the newly created
8418 // transformed parameters.
8419
8420 TypeLocBuilder NewCallOpTLBuilder;
8421 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8422 OldCallOpFPTL,
Craig Topperc3ec1492014-05-26 06:22:03 +00008423 nullptr, 0);
Faisal Vali2cba1332013-10-23 06:44:28 +00008424 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8425 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008426 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008427 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8428 // the vector below - this will be used to synthesize the
8429 // NewCallOperator. Additionally, add the parameters of the untransformed
8430 // lambda call operator to the CurrentInstantiationScope.
8431 SmallVector<ParmVarDecl *, 4> Params;
8432 {
8433 FunctionProtoTypeLoc NewCallOpFPTL =
8434 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8435 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008436 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008437
8438 for (unsigned I = 0; I < NewNumArgs; ++I) {
8439 // If this call operator's type does not require transformation,
8440 // the parameters do not get added to the current instantiation scope,
8441 // - so ADD them! This allows the following to compile when the enclosing
8442 // template is specialized and the entire lambda expression has to be
8443 // transformed.
8444 // template<class T> void foo(T t) {
8445 // auto L = [](auto a) {
8446 // auto M = [](char b) { <-- note: non-generic lambda
8447 // auto N = [](auto c) {
8448 // int x = sizeof(a);
8449 // x = sizeof(b); <-- specifically this line
8450 // x = sizeof(c);
8451 // };
8452 // };
8453 // };
8454 // }
8455 // foo('a')
8456 if (CallOpWasAlreadyTransformed)
8457 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8458 NewParamDeclArray[I]);
8459 // Add to Params array, so these parameters can be used to create
8460 // the newly transformed call operator.
8461 Params.push_back(NewParamDeclArray[I]);
8462 }
8463 }
8464
8465 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008466 return ExprError();
8467
Eli Friedmand564afb2012-09-19 01:18:11 +00008468 // Create the local class that will describe the lambda.
8469 CXXRecordDecl *Class
8470 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008471 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008472 /*KnownDependent=*/false,
8473 E->getCaptureDefault());
8474
Eli Friedmand564afb2012-09-19 01:18:11 +00008475 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8476
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008477 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008478 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008479 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008480 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008481 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008482 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008483 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008484
Faisal Vali2cba1332013-10-23 06:44:28 +00008485 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8486
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008487 return getDerived().TransformLambdaScope(E, NewCallOperator,
8488 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008489}
8490
8491template<typename Derived>
8492ExprResult
8493TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008494 CXXMethodDecl *CallOperator,
8495 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008496 bool Invalid = false;
8497
Douglas Gregorb4328232012-02-14 00:00:48 +00008498 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008499 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8500 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008501
Faisal Vali2b391ab2013-09-26 19:54:12 +00008502 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008503 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008504 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008505 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008506 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008507 E->hasExplicitParameters(),
8508 E->hasExplicitResultType(),
8509 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008510
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008511 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008512 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008513 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008514 CEnd = E->capture_end();
8515 C != CEnd; ++C) {
8516 // When we hit the first implicit capture, tell Sema that we've finished
8517 // the list of explicit captures.
8518 if (!FinishedExplicitCaptures && C->isImplicit()) {
8519 getSema().finishLambdaExplicitCaptures(LSI);
8520 FinishedExplicitCaptures = true;
8521 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008522
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008523 // Capturing 'this' is trivial.
8524 if (C->capturesThis()) {
8525 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8526 continue;
8527 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008528
Richard Smithba71c082013-05-16 06:20:58 +00008529 // Rebuild init-captures, including the implied field declaration.
8530 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008531
8532 InitCaptureInfoTy InitExprTypePair =
8533 InitCaptureExprsAndTypes[C - E->capture_begin()];
8534 ExprResult Init = InitExprTypePair.first;
8535 QualType InitQualType = InitExprTypePair.second;
8536 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008537 Invalid = true;
8538 continue;
8539 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008540 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008541 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8542 OldVD->getLocation(), InitExprTypePair.second,
8543 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008544 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008545 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008546 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008547 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008548 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008549 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008550 continue;
8551 }
8552
8553 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8554
Douglas Gregor3e308b12012-02-14 19:27:52 +00008555 // Determine the capture kind for Sema.
8556 Sema::TryCaptureKind Kind
8557 = C->isImplicit()? Sema::TryCapture_Implicit
8558 : C->getCaptureKind() == LCK_ByCopy
8559 ? Sema::TryCapture_ExplicitByVal
8560 : Sema::TryCapture_ExplicitByRef;
8561 SourceLocation EllipsisLoc;
8562 if (C->isPackExpansion()) {
8563 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8564 bool ShouldExpand = false;
8565 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008566 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008567 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8568 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008569 Unexpanded,
8570 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008571 NumExpansions)) {
8572 Invalid = true;
8573 continue;
8574 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008575
Douglas Gregor3e308b12012-02-14 19:27:52 +00008576 if (ShouldExpand) {
8577 // The transform has determined that we should perform an expansion;
8578 // transform and capture each of the arguments.
8579 // expansion of the pattern. Do so.
8580 VarDecl *Pack = C->getCapturedVar();
8581 for (unsigned I = 0; I != *NumExpansions; ++I) {
8582 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8583 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008584 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008585 Pack));
8586 if (!CapturedVar) {
8587 Invalid = true;
8588 continue;
8589 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008590
Douglas Gregor3e308b12012-02-14 19:27:52 +00008591 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008592 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8593 }
Douglas Gregor3e308b12012-02-14 19:27:52 +00008594 continue;
8595 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008596
Douglas Gregor3e308b12012-02-14 19:27:52 +00008597 EllipsisLoc = C->getEllipsisLoc();
8598 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008599
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008600 // Transform the captured variable.
8601 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008602 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008603 C->getCapturedVar()));
8604 if (!CapturedVar) {
8605 Invalid = true;
8606 continue;
8607 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008608
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008609 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008610 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008611 }
8612 if (!FinishedExplicitCaptures)
8613 getSema().finishLambdaExplicitCaptures(LSI);
8614
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008615
8616 // Enter a new evaluation context to insulate the lambda from any
8617 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008618 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008619
8620 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008621 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008622 /*IsInstantiation=*/true);
8623 return ExprError();
8624 }
8625
8626 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008627 StmtResult Body = getDerived().TransformStmt(E->getBody());
8628 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008629 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00008630 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008631 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008632 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008633
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008634 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008635 /*CurScope=*/nullptr,
8636 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008637}
8638
8639template<typename Derived>
8640ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008641TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008642 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008643 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8644 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008645 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008646
Douglas Gregora16548e2009-08-11 05:31:07 +00008647 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008648 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008649 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008650 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008651 &ArgumentChanged))
8652 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008653
Douglas Gregora16548e2009-08-11 05:31:07 +00008654 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008655 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008656 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008657 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008658
Douglas Gregora16548e2009-08-11 05:31:07 +00008659 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008660 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008661 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008662 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008663 E->getRParenLoc());
8664}
Mike Stump11289f42009-09-09 15:08:12 +00008665
Douglas Gregora16548e2009-08-11 05:31:07 +00008666template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008667ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008668TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008669 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008670 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00008671 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00008672 Expr *OldBase;
8673 QualType BaseType;
8674 QualType ObjectType;
8675 if (!E->isImplicitAccess()) {
8676 OldBase = E->getBase();
8677 Base = getDerived().TransformExpr(OldBase);
8678 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008679 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008680
John McCall2d74de92009-12-01 22:10:20 +00008681 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008682 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008683 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008684 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008685 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008686 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008687 ObjectTy,
8688 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008689 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008690 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008691
John McCallba7bf592010-08-24 05:47:05 +00008692 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008693 BaseType = ((Expr*) Base.get())->getType();
8694 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008695 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00008696 BaseType = getDerived().TransformType(E->getBaseType());
8697 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8698 }
Mike Stump11289f42009-09-09 15:08:12 +00008699
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008700 // Transform the first part of the nested-name-specifier that qualifies
8701 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008702 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008703 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008704 E->getFirstQualifierFoundInScope(),
8705 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008706
Douglas Gregore16af532011-02-28 18:50:33 +00008707 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008708 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008709 QualifierLoc
8710 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8711 ObjectType,
8712 FirstQualifierInScope);
8713 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008714 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008715 }
Mike Stump11289f42009-09-09 15:08:12 +00008716
Abramo Bagnara7945c982012-01-27 09:46:47 +00008717 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8718
John McCall31f82722010-11-12 08:19:04 +00008719 // TODO: If this is a conversion-function-id, verify that the
8720 // destination type name (if present) resolves the same way after
8721 // instantiation as it did in the local scope.
8722
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008723 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008724 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008725 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008726 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008727
John McCall2d74de92009-12-01 22:10:20 +00008728 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008729 // This is a reference to a member without an explicitly-specified
8730 // template argument list. Optimize for this common case.
8731 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008732 Base.get() == OldBase &&
8733 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008734 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008735 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008736 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008737 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008738
John McCallb268a282010-08-23 23:25:46 +00008739 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008740 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008741 E->isArrow(),
8742 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008743 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008744 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008745 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008746 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00008747 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00008748 }
8749
John McCall6b51f282009-11-23 01:53:49 +00008750 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008751 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8752 E->getNumTemplateArgs(),
8753 TransArgs))
8754 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008755
John McCallb268a282010-08-23 23:25:46 +00008756 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008757 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008758 E->isArrow(),
8759 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008760 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008761 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008762 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008763 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008764 &TransArgs);
8765}
8766
8767template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008768ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008769TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008770 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00008771 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00008772 QualType BaseType;
8773 if (!Old->isImplicitAccess()) {
8774 Base = getDerived().TransformExpr(Old->getBase());
8775 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008776 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008777 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00008778 Old->isArrow());
8779 if (Base.isInvalid())
8780 return ExprError();
8781 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008782 } else {
8783 BaseType = getDerived().TransformType(Old->getBaseType());
8784 }
John McCall10eae182009-11-30 22:42:35 +00008785
Douglas Gregor0da1d432011-02-28 20:01:57 +00008786 NestedNameSpecifierLoc QualifierLoc;
8787 if (Old->getQualifierLoc()) {
8788 QualifierLoc
8789 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8790 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008791 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008792 }
8793
Abramo Bagnara7945c982012-01-27 09:46:47 +00008794 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8795
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008796 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008797 Sema::LookupOrdinaryName);
8798
8799 // Transform all the decls.
8800 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8801 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008802 NamedDecl *InstD = static_cast<NamedDecl*>(
8803 getDerived().TransformDecl(Old->getMemberLoc(),
8804 *I));
John McCall84d87672009-12-10 09:41:52 +00008805 if (!InstD) {
8806 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8807 // This can happen because of dependent hiding.
8808 if (isa<UsingShadowDecl>(*I))
8809 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008810 else {
8811 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008812 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008813 }
John McCall84d87672009-12-10 09:41:52 +00008814 }
John McCall10eae182009-11-30 22:42:35 +00008815
8816 // Expand using declarations.
8817 if (isa<UsingDecl>(InstD)) {
8818 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008819 for (auto *I : UD->shadows())
8820 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00008821 continue;
8822 }
8823
8824 R.addDecl(InstD);
8825 }
8826
8827 R.resolveKind();
8828
Douglas Gregor9262f472010-04-27 18:19:34 +00008829 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008830 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008831 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008832 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008833 Old->getMemberLoc(),
8834 Old->getNamingClass()));
8835 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008836 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008837
Douglas Gregorda7be082010-04-27 16:10:10 +00008838 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008839 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008840
John McCall10eae182009-11-30 22:42:35 +00008841 TemplateArgumentListInfo TransArgs;
8842 if (Old->hasExplicitTemplateArgs()) {
8843 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8844 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008845 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8846 Old->getNumTemplateArgs(),
8847 TransArgs))
8848 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008849 }
John McCall38836f02010-01-15 08:34:02 +00008850
8851 // FIXME: to do this check properly, we will need to preserve the
8852 // first-qualifier-in-scope here, just in case we had a dependent
8853 // base (and therefore couldn't do the check) and a
8854 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008855 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00008856
John McCallb268a282010-08-23 23:25:46 +00008857 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008858 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008859 Old->getOperatorLoc(),
8860 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008861 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008862 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008863 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008864 R,
8865 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008866 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00008867}
8868
8869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008870ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008871TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00008872 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008873 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8874 if (SubExpr.isInvalid())
8875 return ExprError();
8876
8877 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008878 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008879
8880 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8881}
8882
8883template<typename Derived>
8884ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008885TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008886 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8887 if (Pattern.isInvalid())
8888 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008889
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008890 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008891 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008892
Douglas Gregorb8840002011-01-14 21:20:45 +00008893 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8894 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008895}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008896
8897template<typename Derived>
8898ExprResult
8899TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8900 // If E is not value-dependent, then nothing will change when we transform it.
8901 // Note: This is an instantiation-centric view.
8902 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008903 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008904
8905 // Note: None of the implementations of TryExpandParameterPacks can ever
8906 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00008907 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008908 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8909 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008910 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008911 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008912 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00008913 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008914 ShouldExpand, RetainExpansion,
8915 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008916 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008917
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008918 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008919 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008920
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008921 NamedDecl *Pack = E->getPack();
8922 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008923 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008924 Pack));
8925 if (!Pack)
8926 return ExprError();
8927 }
8928
Chad Rosier1dcde962012-08-08 18:46:20 +00008929
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008930 // We now know the length of the parameter pack, so build a new expression
8931 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00008932 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8933 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008934 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008935}
8936
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008937template<typename Derived>
8938ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008939TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8940 SubstNonTypeTemplateParmPackExpr *E) {
8941 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008942 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008943}
8944
8945template<typename Derived>
8946ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00008947TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8948 SubstNonTypeTemplateParmExpr *E) {
8949 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008950 return E;
John McCall7c454bb2011-07-15 05:09:51 +00008951}
8952
8953template<typename Derived>
8954ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00008955TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8956 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008957 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00008958}
8959
8960template<typename Derived>
8961ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00008962TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8963 MaterializeTemporaryExpr *E) {
8964 return getDerived().TransformExpr(E->GetTemporaryExpr());
8965}
Chad Rosier1dcde962012-08-08 18:46:20 +00008966
Douglas Gregorfe314812011-06-21 17:03:29 +00008967template<typename Derived>
8968ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00008969TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8970 CXXStdInitializerListExpr *E) {
8971 return getDerived().TransformExpr(E->getSubExpr());
8972}
8973
8974template<typename Derived>
8975ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008976TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008977 return SemaRef.MaybeBindToTemporary(E);
8978}
8979
8980template<typename Derived>
8981ExprResult
8982TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008983 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008984}
8985
8986template<typename Derived>
8987ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00008988TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8989 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8990 if (SubExpr.isInvalid())
8991 return ExprError();
8992
8993 if (!getDerived().AlwaysRebuild() &&
8994 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008995 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00008996
8997 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00008998}
8999
9000template<typename Derived>
9001ExprResult
9002TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9003 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009004 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009005 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009006 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009007 /*IsCall=*/false, Elements, &ArgChanged))
9008 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009009
Ted Kremeneke65b0862012-03-06 20:05:56 +00009010 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9011 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009012
Ted Kremeneke65b0862012-03-06 20:05:56 +00009013 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9014 Elements.data(),
9015 Elements.size());
9016}
9017
9018template<typename Derived>
9019ExprResult
9020TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009021 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009022 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009023 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009024 bool ArgChanged = false;
9025 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9026 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009027
Ted Kremeneke65b0862012-03-06 20:05:56 +00009028 if (OrigElement.isPackExpansion()) {
9029 // This key/value element is a pack expansion.
9030 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9031 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9032 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9033 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9034
9035 // Determine whether the set of unexpanded parameter packs can
9036 // and should be expanded.
9037 bool Expand = true;
9038 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009039 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9040 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009041 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9042 OrigElement.Value->getLocEnd());
9043 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9044 PatternRange,
9045 Unexpanded,
9046 Expand, RetainExpansion,
9047 NumExpansions))
9048 return ExprError();
9049
9050 if (!Expand) {
9051 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009052 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009053 // expansion.
9054 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9055 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9056 if (Key.isInvalid())
9057 return ExprError();
9058
9059 if (Key.get() != OrigElement.Key)
9060 ArgChanged = true;
9061
9062 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9063 if (Value.isInvalid())
9064 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009065
Ted Kremeneke65b0862012-03-06 20:05:56 +00009066 if (Value.get() != OrigElement.Value)
9067 ArgChanged = true;
9068
Chad Rosier1dcde962012-08-08 18:46:20 +00009069 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009070 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9071 };
9072 Elements.push_back(Expansion);
9073 continue;
9074 }
9075
9076 // Record right away that the argument was changed. This needs
9077 // to happen even if the array expands to nothing.
9078 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009079
Ted Kremeneke65b0862012-03-06 20:05:56 +00009080 // The transform has determined that we should perform an elementwise
9081 // expansion of the pattern. Do so.
9082 for (unsigned I = 0; I != *NumExpansions; ++I) {
9083 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9084 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9085 if (Key.isInvalid())
9086 return ExprError();
9087
9088 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9089 if (Value.isInvalid())
9090 return ExprError();
9091
Chad Rosier1dcde962012-08-08 18:46:20 +00009092 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009093 Key.get(), Value.get(), SourceLocation(), NumExpansions
9094 };
9095
9096 // If any unexpanded parameter packs remain, we still have a
9097 // pack expansion.
9098 if (Key.get()->containsUnexpandedParameterPack() ||
9099 Value.get()->containsUnexpandedParameterPack())
9100 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009101
Ted Kremeneke65b0862012-03-06 20:05:56 +00009102 Elements.push_back(Element);
9103 }
9104
9105 // We've finished with this pack expansion.
9106 continue;
9107 }
9108
9109 // Transform and check key.
9110 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9111 if (Key.isInvalid())
9112 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009113
Ted Kremeneke65b0862012-03-06 20:05:56 +00009114 if (Key.get() != OrigElement.Key)
9115 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009116
Ted Kremeneke65b0862012-03-06 20:05:56 +00009117 // Transform and check value.
9118 ExprResult Value
9119 = getDerived().TransformExpr(OrigElement.Value);
9120 if (Value.isInvalid())
9121 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009122
Ted Kremeneke65b0862012-03-06 20:05:56 +00009123 if (Value.get() != OrigElement.Value)
9124 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009125
9126 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009127 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009128 };
9129 Elements.push_back(Element);
9130 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009131
Ted Kremeneke65b0862012-03-06 20:05:56 +00009132 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9133 return SemaRef.MaybeBindToTemporary(E);
9134
9135 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9136 Elements.data(),
9137 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009138}
9139
Mike Stump11289f42009-09-09 15:08:12 +00009140template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009141ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009142TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009143 TypeSourceInfo *EncodedTypeInfo
9144 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9145 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009146 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009147
Douglas Gregora16548e2009-08-11 05:31:07 +00009148 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009149 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009150 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009151
9152 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009153 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009154 E->getRParenLoc());
9155}
Mike Stump11289f42009-09-09 15:08:12 +00009156
Douglas Gregora16548e2009-08-11 05:31:07 +00009157template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009158ExprResult TreeTransform<Derived>::
9159TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009160 // This is a kind of implicit conversion, and it needs to get dropped
9161 // and recomputed for the same general reasons that ImplicitCastExprs
9162 // do, as well a more specific one: this expression is only valid when
9163 // it appears *immediately* as an argument expression.
9164 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009165}
9166
9167template<typename Derived>
9168ExprResult TreeTransform<Derived>::
9169TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009170 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009171 = getDerived().TransformType(E->getTypeInfoAsWritten());
9172 if (!TSInfo)
9173 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009174
John McCall31168b02011-06-15 23:02:42 +00009175 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009176 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009177 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009178
John McCall31168b02011-06-15 23:02:42 +00009179 if (!getDerived().AlwaysRebuild() &&
9180 TSInfo == E->getTypeInfoAsWritten() &&
9181 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009182 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009183
John McCall31168b02011-06-15 23:02:42 +00009184 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009185 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009186 Result.get());
9187}
9188
9189template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009190ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009191TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009192 // Transform arguments.
9193 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009194 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009195 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009196 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009197 &ArgChanged))
9198 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009199
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009200 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9201 // Class message: transform the receiver type.
9202 TypeSourceInfo *ReceiverTypeInfo
9203 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9204 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009205 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009206
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009207 // If nothing changed, just retain the existing message send.
9208 if (!getDerived().AlwaysRebuild() &&
9209 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009210 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009211
9212 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009213 SmallVector<SourceLocation, 16> SelLocs;
9214 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009215 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9216 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009217 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009218 E->getMethodDecl(),
9219 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009220 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009221 E->getRightLoc());
9222 }
9223
9224 // Instance message: transform the receiver
9225 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9226 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009227 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009228 = getDerived().TransformExpr(E->getInstanceReceiver());
9229 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009230 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009231
9232 // If nothing changed, just retain the existing message send.
9233 if (!getDerived().AlwaysRebuild() &&
9234 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009235 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009236
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009237 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009238 SmallVector<SourceLocation, 16> SelLocs;
9239 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009240 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009241 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009242 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009243 E->getMethodDecl(),
9244 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009245 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009246 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009247}
9248
Mike Stump11289f42009-09-09 15:08:12 +00009249template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009250ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009251TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009252 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009253}
9254
Mike Stump11289f42009-09-09 15:08:12 +00009255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009256ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009257TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009258 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009259}
9260
Mike Stump11289f42009-09-09 15:08:12 +00009261template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009262ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009263TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009264 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009265 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009266 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009267 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009268
9269 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009270
Douglas Gregord51d90d2010-04-26 20:11:03 +00009271 // If nothing changed, just retain the existing expression.
9272 if (!getDerived().AlwaysRebuild() &&
9273 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009274 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009275
John McCallb268a282010-08-23 23:25:46 +00009276 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009277 E->getLocation(),
9278 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009279}
9280
Mike Stump11289f42009-09-09 15:08:12 +00009281template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009282ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009283TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009284 // 'super' and types never change. Property never changes. Just
9285 // retain the existing expression.
9286 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009287 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009288
Douglas Gregor9faee212010-04-26 20:47:02 +00009289 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009290 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009291 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009292 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009293
Douglas Gregor9faee212010-04-26 20:47:02 +00009294 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009295
Douglas Gregor9faee212010-04-26 20:47:02 +00009296 // If nothing changed, just retain the existing expression.
9297 if (!getDerived().AlwaysRebuild() &&
9298 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009299 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009300
John McCallb7bd14f2010-12-02 01:19:52 +00009301 if (E->isExplicitProperty())
9302 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9303 E->getExplicitProperty(),
9304 E->getLocation());
9305
9306 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009307 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009308 E->getImplicitPropertyGetter(),
9309 E->getImplicitPropertySetter(),
9310 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009311}
9312
Mike Stump11289f42009-09-09 15:08:12 +00009313template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009314ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009315TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9316 // Transform the base expression.
9317 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9318 if (Base.isInvalid())
9319 return ExprError();
9320
9321 // Transform the key expression.
9322 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9323 if (Key.isInvalid())
9324 return ExprError();
9325
9326 // If nothing changed, just retain the existing expression.
9327 if (!getDerived().AlwaysRebuild() &&
9328 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009329 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009330
Chad Rosier1dcde962012-08-08 18:46:20 +00009331 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009332 Base.get(), Key.get(),
9333 E->getAtIndexMethodDecl(),
9334 E->setAtIndexMethodDecl());
9335}
9336
9337template<typename Derived>
9338ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009339TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009340 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009341 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009342 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009343 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009344
Douglas Gregord51d90d2010-04-26 20:11:03 +00009345 // If nothing changed, just retain the existing expression.
9346 if (!getDerived().AlwaysRebuild() &&
9347 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009348 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009349
John McCallb268a282010-08-23 23:25:46 +00009350 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009351 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009352 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009353}
9354
Mike Stump11289f42009-09-09 15:08:12 +00009355template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009356ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009357TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009358 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009359 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009360 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009361 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009362 SubExprs, &ArgumentChanged))
9363 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009364
Douglas Gregora16548e2009-08-11 05:31:07 +00009365 if (!getDerived().AlwaysRebuild() &&
9366 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009367 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009368
Douglas Gregora16548e2009-08-11 05:31:07 +00009369 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009370 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009371 E->getRParenLoc());
9372}
9373
Mike Stump11289f42009-09-09 15:08:12 +00009374template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009375ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009376TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9377 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9378 if (SrcExpr.isInvalid())
9379 return ExprError();
9380
9381 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9382 if (!Type)
9383 return ExprError();
9384
9385 if (!getDerived().AlwaysRebuild() &&
9386 Type == E->getTypeSourceInfo() &&
9387 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009388 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +00009389
9390 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9391 SrcExpr.get(), Type,
9392 E->getRParenLoc());
9393}
9394
9395template<typename Derived>
9396ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009397TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009398 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009399
Craig Topperc3ec1492014-05-26 06:22:03 +00009400 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +00009401 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9402
9403 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009404 blockScope->TheDecl->setBlockMissingReturnType(
9405 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009406
Chris Lattner01cf8db2011-07-20 06:58:45 +00009407 SmallVector<ParmVarDecl*, 4> params;
9408 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009409
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009410 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009411 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9412 oldBlock->param_begin(),
9413 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009414 nullptr, paramTypes, &params)) {
9415 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009416 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009417 }
John McCall490112f2011-02-04 18:33:18 +00009418
Jordan Rosea0a86be2013-03-08 22:25:36 +00009419 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009420 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009421 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009422
Jordan Rose5c382722013-03-08 21:51:21 +00009423 QualType functionType =
9424 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009425 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009426 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009427
9428 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009429 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009430 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009431
9432 if (!oldBlock->blockMissingReturnType()) {
9433 blockScope->HasImplicitReturnType = false;
9434 blockScope->ReturnType = exprResultType;
9435 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009436
John McCall3882ace2011-01-05 12:14:39 +00009437 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009438 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009439 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009440 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +00009441 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009442 }
John McCall3882ace2011-01-05 12:14:39 +00009443
John McCall490112f2011-02-04 18:33:18 +00009444#ifndef NDEBUG
9445 // In builds with assertions, make sure that we captured everything we
9446 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009447 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009448 for (const auto &I : oldBlock->captures()) {
9449 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009450
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009451 // Ignore parameter packs.
9452 if (isa<ParmVarDecl>(oldCapture) &&
9453 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9454 continue;
John McCall490112f2011-02-04 18:33:18 +00009455
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009456 VarDecl *newCapture =
9457 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9458 oldCapture));
9459 assert(blockScope->CaptureMap.count(newCapture));
9460 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009461 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009462 }
9463#endif
9464
9465 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009466 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00009467}
9468
Mike Stump11289f42009-09-09 15:08:12 +00009469template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009470ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009471TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009472 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009473}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009474
9475template<typename Derived>
9476ExprResult
9477TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009478 QualType RetTy = getDerived().TransformType(E->getType());
9479 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009480 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009481 SubExprs.reserve(E->getNumSubExprs());
9482 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9483 SubExprs, &ArgumentChanged))
9484 return ExprError();
9485
9486 if (!getDerived().AlwaysRebuild() &&
9487 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009488 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009489
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009490 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009491 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009492}
Chad Rosier1dcde962012-08-08 18:46:20 +00009493
Douglas Gregora16548e2009-08-11 05:31:07 +00009494//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009495// Type reconstruction
9496//===----------------------------------------------------------------------===//
9497
Mike Stump11289f42009-09-09 15:08:12 +00009498template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009499QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9500 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009501 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009502 getDerived().getBaseEntity());
9503}
9504
Mike Stump11289f42009-09-09 15:08:12 +00009505template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009506QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9507 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009508 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009509 getDerived().getBaseEntity());
9510}
9511
Mike Stump11289f42009-09-09 15:08:12 +00009512template<typename Derived>
9513QualType
John McCall70dd5f62009-10-30 00:06:24 +00009514TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9515 bool WrittenAsLValue,
9516 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009517 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009518 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009519}
9520
9521template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009522QualType
John McCall70dd5f62009-10-30 00:06:24 +00009523TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9524 QualType ClassType,
9525 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009526 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9527 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009528}
9529
9530template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009531QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009532TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9533 ArrayType::ArraySizeModifier SizeMod,
9534 const llvm::APInt *Size,
9535 Expr *SizeExpr,
9536 unsigned IndexTypeQuals,
9537 SourceRange BracketsRange) {
9538 if (SizeExpr || !Size)
9539 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9540 IndexTypeQuals, BracketsRange,
9541 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009542
9543 QualType Types[] = {
9544 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9545 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9546 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009547 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009548 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009549 QualType SizeType;
9550 for (unsigned I = 0; I != NumTypes; ++I)
9551 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9552 SizeType = Types[I];
9553 break;
9554 }
Mike Stump11289f42009-09-09 15:08:12 +00009555
Eli Friedman9562f392012-01-25 23:20:27 +00009556 // Note that we can return a VariableArrayType here in the case where
9557 // the element type was a dependent VariableArrayType.
9558 IntegerLiteral *ArraySize
9559 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9560 /*FIXME*/BracketsRange.getBegin());
9561 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009562 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009563 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009564}
Mike Stump11289f42009-09-09 15:08:12 +00009565
Douglas Gregord6ff3322009-08-04 16:50:30 +00009566template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009567QualType
9568TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009569 ArrayType::ArraySizeModifier SizeMod,
9570 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009571 unsigned IndexTypeQuals,
9572 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009573 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009574 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009575}
9576
9577template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009578QualType
Mike Stump11289f42009-09-09 15:08:12 +00009579TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009580 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009581 unsigned IndexTypeQuals,
9582 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009583 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009584 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009585}
Mike Stump11289f42009-09-09 15:08:12 +00009586
Douglas Gregord6ff3322009-08-04 16:50:30 +00009587template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009588QualType
9589TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009590 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009591 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009592 unsigned IndexTypeQuals,
9593 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009594 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009595 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009596 IndexTypeQuals, BracketsRange);
9597}
9598
9599template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009600QualType
9601TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009602 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009603 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009604 unsigned IndexTypeQuals,
9605 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009606 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009607 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009608 IndexTypeQuals, BracketsRange);
9609}
9610
9611template<typename Derived>
9612QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009613 unsigned NumElements,
9614 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009615 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009616 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009617}
Mike Stump11289f42009-09-09 15:08:12 +00009618
Douglas Gregord6ff3322009-08-04 16:50:30 +00009619template<typename Derived>
9620QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9621 unsigned NumElements,
9622 SourceLocation AttributeLoc) {
9623 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9624 NumElements, true);
9625 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009626 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9627 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009628 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009629}
Mike Stump11289f42009-09-09 15:08:12 +00009630
Douglas Gregord6ff3322009-08-04 16:50:30 +00009631template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009632QualType
9633TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009634 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009635 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009636 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009637}
Mike Stump11289f42009-09-09 15:08:12 +00009638
Douglas Gregord6ff3322009-08-04 16:50:30 +00009639template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009640QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9641 QualType T,
9642 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009643 const FunctionProtoType::ExtProtoInfo &EPI) {
9644 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009645 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009646 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009647 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009648}
Mike Stump11289f42009-09-09 15:08:12 +00009649
Douglas Gregord6ff3322009-08-04 16:50:30 +00009650template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009651QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9652 return SemaRef.Context.getFunctionNoProtoType(T);
9653}
9654
9655template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009656QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9657 assert(D && "no decl found");
9658 if (D->isInvalidDecl()) return QualType();
9659
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009660 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009661 TypeDecl *Ty;
9662 if (isa<UsingDecl>(D)) {
9663 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009664 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009665 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9666
9667 // A valid resolved using typename decl points to exactly one type decl.
9668 assert(++Using->shadow_begin() == Using->shadow_end());
9669 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009670
John McCallb96ec562009-12-04 22:46:56 +00009671 } else {
9672 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9673 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9674 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9675 }
9676
9677 return SemaRef.Context.getTypeDeclType(Ty);
9678}
9679
9680template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009681QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9682 SourceLocation Loc) {
9683 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009684}
9685
9686template<typename Derived>
9687QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9688 return SemaRef.Context.getTypeOfType(Underlying);
9689}
9690
9691template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009692QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9693 SourceLocation Loc) {
9694 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009695}
9696
9697template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009698QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9699 UnaryTransformType::UTTKind UKind,
9700 SourceLocation Loc) {
9701 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9702}
9703
9704template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009705QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009706 TemplateName Template,
9707 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009708 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009709 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009710}
Mike Stump11289f42009-09-09 15:08:12 +00009711
Douglas Gregor1135c352009-08-06 05:28:30 +00009712template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009713QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9714 SourceLocation KWLoc) {
9715 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9716}
9717
9718template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009719TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009720TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009721 bool TemplateKW,
9722 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009723 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009724 Template);
9725}
9726
9727template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009728TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009729TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9730 const IdentifierInfo &Name,
9731 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009732 QualType ObjectType,
9733 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009734 UnqualifiedId TemplateName;
9735 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009736 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009737 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +00009738 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009739 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009740 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009741 /*EnteringContext=*/false,
9742 Template);
John McCall31f82722010-11-12 08:19:04 +00009743 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009744}
Mike Stump11289f42009-09-09 15:08:12 +00009745
Douglas Gregora16548e2009-08-11 05:31:07 +00009746template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009747TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009748TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009749 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009750 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009751 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009752 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009753 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009754 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009755 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009756 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009757 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +00009758 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009759 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009760 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009761 /*EnteringContext=*/false,
9762 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009763 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009764}
Chad Rosier1dcde962012-08-08 18:46:20 +00009765
Douglas Gregor71395fa2009-11-04 00:56:37 +00009766template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009767ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009768TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9769 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009770 Expr *OrigCallee,
9771 Expr *First,
9772 Expr *Second) {
9773 Expr *Callee = OrigCallee->IgnoreParenCasts();
9774 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009775
Douglas Gregora16548e2009-08-11 05:31:07 +00009776 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009777 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009778 if (!First->getType()->isOverloadableType() &&
9779 !Second->getType()->isOverloadableType())
9780 return getSema().CreateBuiltinArraySubscriptExpr(First,
9781 Callee->getLocStart(),
9782 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009783 } else if (Op == OO_Arrow) {
9784 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +00009785 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
9786 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +00009787 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009788 // The argument is not of overloadable type, so try to create a
9789 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009790 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009791 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009792
John McCallb268a282010-08-23 23:25:46 +00009793 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009794 }
9795 } else {
John McCallb268a282010-08-23 23:25:46 +00009796 if (!First->getType()->isOverloadableType() &&
9797 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009798 // Neither of the arguments is an overloadable type, so try to
9799 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009800 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009801 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009802 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009803 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009804 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009805
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009806 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009807 }
9808 }
Mike Stump11289f42009-09-09 15:08:12 +00009809
9810 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009811 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009812 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009813
John McCallb268a282010-08-23 23:25:46 +00009814 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009815 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +00009816 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009817 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009818 // If we've resolved this to a particular non-member function, just call
9819 // that function. If we resolved it to a member function,
9820 // CreateOverloaded* will find that function for us.
9821 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9822 if (!isa<CXXMethodDecl>(ND))
9823 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009824 }
Mike Stump11289f42009-09-09 15:08:12 +00009825
Douglas Gregora16548e2009-08-11 05:31:07 +00009826 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009827 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +00009828 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +00009829
Douglas Gregora16548e2009-08-11 05:31:07 +00009830 // Create the overloaded operator invocation for unary operators.
9831 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009832 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009833 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009834 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009835 }
Mike Stump11289f42009-09-09 15:08:12 +00009836
Douglas Gregore9d62932011-07-15 16:25:15 +00009837 if (Op == OO_Subscript) {
9838 SourceLocation LBrace;
9839 SourceLocation RBrace;
9840
9841 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9842 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9843 LBrace = SourceLocation::getFromRawEncoding(
9844 NameLoc.CXXOperatorName.BeginOpNameLoc);
9845 RBrace = SourceLocation::getFromRawEncoding(
9846 NameLoc.CXXOperatorName.EndOpNameLoc);
9847 } else {
9848 LBrace = Callee->getLocStart();
9849 RBrace = OpLoc;
9850 }
9851
9852 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9853 First, Second);
9854 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009855
Douglas Gregora16548e2009-08-11 05:31:07 +00009856 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009857 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009858 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009859 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9860 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009861 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009862
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009863 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009864}
Mike Stump11289f42009-09-09 15:08:12 +00009865
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009866template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009867ExprResult
John McCallb268a282010-08-23 23:25:46 +00009868TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009869 SourceLocation OperatorLoc,
9870 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00009871 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009872 TypeSourceInfo *ScopeType,
9873 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009874 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009875 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00009876 QualType BaseType = Base->getType();
9877 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009878 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +00009879 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00009880 !BaseType->getAs<PointerType>()->getPointeeType()
9881 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009882 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00009883 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009884 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009885 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009886 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009887 /*FIXME?*/true);
9888 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009889
Douglas Gregor678f90d2010-02-25 01:56:36 +00009890 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009891 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9892 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9893 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9894 NameInfo.setNamedTypeInfo(DestroyedType);
9895
Richard Smith8e4a3862012-05-15 06:15:11 +00009896 // The scope type is now known to be a valid nested name specifier
9897 // component. Tack it on to the end of the nested name specifier.
9898 if (ScopeType)
9899 SS.Extend(SemaRef.Context, SourceLocation(),
9900 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009901
Abramo Bagnara7945c982012-01-27 09:46:47 +00009902 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +00009903 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009904 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009905 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00009906 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009907 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009908 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009909}
9910
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009911template<typename Derived>
9912StmtResult
9913TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +00009914 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +00009915 CapturedDecl *CD = S->getCapturedDecl();
9916 unsigned NumParams = CD->getNumParams();
9917 unsigned ContextParamPos = CD->getContextParamPosition();
9918 SmallVector<Sema::CapturedParamNameType, 4> Params;
9919 for (unsigned I = 0; I < NumParams; ++I) {
9920 if (I != ContextParamPos) {
9921 Params.push_back(
9922 std::make_pair(
9923 CD->getParam(I)->getName(),
9924 getDerived().TransformType(CD->getParam(I)->getType())));
9925 } else {
9926 Params.push_back(std::make_pair(StringRef(), QualType()));
9927 }
9928 }
Craig Topperc3ec1492014-05-26 06:22:03 +00009929 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +00009930 S->getCapturedRegionKind(), Params);
Wei Pan17fbf6e2013-05-04 03:59:06 +00009931 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9932
9933 if (Body.isInvalid()) {
9934 getSema().ActOnCapturedRegionError();
9935 return StmtError();
9936 }
9937
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009938 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009939}
9940
Douglas Gregord6ff3322009-08-04 16:50:30 +00009941} // end namespace clang
9942
9943#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H