blob: 59208737b752d321ff840cae1096895394395fc9 [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);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000607
Richard Smithdb2630f2012-10-21 03:28:35 +0000608 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000609 bool IsAddressOfOperand,
610 TypeSourceInfo **RecoveryTSI);
611
612 ExprResult TransformParenDependentScopeDeclRefExpr(
613 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
614 TypeSourceInfo **RecoveryTSI);
615
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000616 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000617
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000618// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
619// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000620#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000621 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000622 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000623#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000624 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000625 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000626#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000627#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000628
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000629#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000630 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000631 OMPClause *Transform ## Class(Class *S);
632#include "clang/Basic/OpenMPKinds.def"
633
Douglas Gregord6ff3322009-08-04 16:50:30 +0000634 /// \brief Build a new pointer type given its pointee type.
635 ///
636 /// By default, performs semantic analysis when building the pointer type.
637 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000638 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000639
640 /// \brief Build a new block pointer type given its pointee type.
641 ///
Mike Stump11289f42009-09-09 15:08:12 +0000642 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000643 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000644 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000645
John McCall70dd5f62009-10-30 00:06:24 +0000646 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000647 ///
John McCall70dd5f62009-10-30 00:06:24 +0000648 /// By default, performs semantic analysis when building the
649 /// reference type. Subclasses may override this routine to provide
650 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000651 ///
John McCall70dd5f62009-10-30 00:06:24 +0000652 /// \param LValue whether the type was written with an lvalue sigil
653 /// or an rvalue sigil.
654 QualType RebuildReferenceType(QualType ReferentType,
655 bool LValue,
656 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000657
Douglas Gregord6ff3322009-08-04 16:50:30 +0000658 /// \brief Build a new member pointer type given the pointee type and the
659 /// class type it refers into.
660 ///
661 /// By default, performs semantic analysis when building the member pointer
662 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000663 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
664 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000665
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666 /// \brief Build a new array type given the element type, size
667 /// modifier, size of the array (if known), size expression, and index type
668 /// qualifiers.
669 ///
670 /// By default, performs semantic analysis when building the array type.
671 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000672 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000673 QualType RebuildArrayType(QualType ElementType,
674 ArrayType::ArraySizeModifier SizeMod,
675 const llvm::APInt *Size,
676 Expr *SizeExpr,
677 unsigned IndexTypeQuals,
678 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000679
Douglas Gregord6ff3322009-08-04 16:50:30 +0000680 /// \brief Build a new constant array type given the element type, size
681 /// modifier, (known) size of the array, and index type qualifiers.
682 ///
683 /// By default, performs semantic analysis when building the array type.
684 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000685 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000686 ArrayType::ArraySizeModifier SizeMod,
687 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000688 unsigned IndexTypeQuals,
689 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000690
Douglas Gregord6ff3322009-08-04 16:50:30 +0000691 /// \brief Build a new incomplete array type given the element type, size
692 /// modifier, and index type qualifiers.
693 ///
694 /// By default, performs semantic analysis when building the array type.
695 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000696 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000697 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000698 unsigned IndexTypeQuals,
699 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000700
Mike Stump11289f42009-09-09 15:08:12 +0000701 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702 /// size modifier, size expression, and index type qualifiers.
703 ///
704 /// By default, performs semantic analysis when building the array type.
705 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000706 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000707 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000708 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000709 unsigned IndexTypeQuals,
710 SourceRange BracketsRange);
711
Mike Stump11289f42009-09-09 15:08:12 +0000712 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000713 /// size modifier, size expression, and index type qualifiers.
714 ///
715 /// By default, performs semantic analysis when building the array type.
716 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000717 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000718 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000719 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000720 unsigned IndexTypeQuals,
721 SourceRange BracketsRange);
722
723 /// \brief Build a new vector type given the element type and
724 /// number of elements.
725 ///
726 /// By default, performs semantic analysis when building the vector type.
727 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000728 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000729 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000730
Douglas Gregord6ff3322009-08-04 16:50:30 +0000731 /// \brief Build a new extended vector type given the element type and
732 /// number of elements.
733 ///
734 /// By default, performs semantic analysis when building the vector type.
735 /// Subclasses may override this routine to provide different behavior.
736 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
737 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000738
739 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 /// given the element type and number of elements.
741 ///
742 /// By default, performs semantic analysis when building the vector type.
743 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000744 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000745 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000746 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000747
Douglas Gregord6ff3322009-08-04 16:50:30 +0000748 /// \brief Build a new function type.
749 ///
750 /// By default, performs semantic analysis when building the function type.
751 /// Subclasses may override this routine to provide different behavior.
752 QualType RebuildFunctionProtoType(QualType T,
Jordan Rose5c382722013-03-08 21:51:21 +0000753 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000754 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000755
John McCall550e0c22009-10-21 00:40:46 +0000756 /// \brief Build a new unprototyped function type.
757 QualType RebuildFunctionNoProtoType(QualType ResultType);
758
John McCallb96ec562009-12-04 22:46:56 +0000759 /// \brief Rebuild an unresolved typename type, given the decl that
760 /// the UnresolvedUsingTypenameDecl was transformed to.
761 QualType RebuildUnresolvedUsingType(Decl *D);
762
Douglas Gregord6ff3322009-08-04 16:50:30 +0000763 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000764 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000765 return SemaRef.Context.getTypeDeclType(Typedef);
766 }
767
768 /// \brief Build a new class/struct/union type.
769 QualType RebuildRecordType(RecordDecl *Record) {
770 return SemaRef.Context.getTypeDeclType(Record);
771 }
772
773 /// \brief Build a new Enum type.
774 QualType RebuildEnumType(EnumDecl *Enum) {
775 return SemaRef.Context.getTypeDeclType(Enum);
776 }
John McCallfcc33b02009-09-05 00:15:47 +0000777
Mike Stump11289f42009-09-09 15:08:12 +0000778 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000779 ///
780 /// By default, performs semantic analysis when building the typeof type.
781 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000782 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000783
Mike Stump11289f42009-09-09 15:08:12 +0000784 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000785 ///
786 /// By default, builds a new TypeOfType with the given underlying type.
787 QualType RebuildTypeOfType(QualType Underlying);
788
Alexis Hunte852b102011-05-24 22:41:36 +0000789 /// \brief Build a new unary transform type.
790 QualType RebuildUnaryTransformType(QualType BaseType,
791 UnaryTransformType::UTTKind UKind,
792 SourceLocation Loc);
793
Richard Smith74aeef52013-04-26 16:15:35 +0000794 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000795 ///
796 /// By default, performs semantic analysis when building the decltype type.
797 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000798 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000799
Richard Smith74aeef52013-04-26 16:15:35 +0000800 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000801 ///
802 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000803 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000804 // Note, IsDependent is always false here: we implicitly convert an 'auto'
805 // which has been deduced to a dependent type into an undeduced 'auto', so
806 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000807 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
808 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000809 }
810
Douglas Gregord6ff3322009-08-04 16:50:30 +0000811 /// \brief Build a new template specialization type.
812 ///
813 /// By default, performs semantic analysis when building the template
814 /// specialization type. Subclasses may override this routine to provide
815 /// different behavior.
816 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000817 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000818 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000819
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000820 /// \brief Build a new parenthesized type.
821 ///
822 /// By default, builds a new ParenType type from the inner type.
823 /// Subclasses may override this routine to provide different behavior.
824 QualType RebuildParenType(QualType InnerType) {
825 return SemaRef.Context.getParenType(InnerType);
826 }
827
Douglas Gregord6ff3322009-08-04 16:50:30 +0000828 /// \brief Build a new qualified name type.
829 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000830 /// By default, builds a new ElaboratedType type from the keyword,
831 /// the nested-name-specifier and the named type.
832 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000833 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
834 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000835 NestedNameSpecifierLoc QualifierLoc,
836 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000837 return SemaRef.Context.getElaboratedType(Keyword,
838 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000839 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000840 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000841
842 /// \brief Build a new typename type that refers to a template-id.
843 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000844 /// By default, builds a new DependentNameType type from the
845 /// nested-name-specifier and the given type. Subclasses may override
846 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000847 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000848 ElaboratedTypeKeyword Keyword,
849 NestedNameSpecifierLoc QualifierLoc,
850 const IdentifierInfo *Name,
851 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000852 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000853 // Rebuild the template name.
854 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000855 CXXScopeSpec SS;
856 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000857 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000858 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
859 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000860
Douglas Gregora7a795b2011-03-01 20:11:18 +0000861 if (InstName.isNull())
862 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000863
Douglas Gregora7a795b2011-03-01 20:11:18 +0000864 // If it's still dependent, make a dependent specialization.
865 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000866 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
867 QualifierLoc.getNestedNameSpecifier(),
868 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000869 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000870
Douglas Gregora7a795b2011-03-01 20:11:18 +0000871 // Otherwise, make an elaborated type wrapping a non-dependent
872 // specialization.
873 QualType T =
874 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
875 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000876
Craig Topperc3ec1492014-05-26 06:22:03 +0000877 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000878 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000879
880 return SemaRef.Context.getElaboratedType(Keyword,
881 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000882 T);
883 }
884
Douglas Gregord6ff3322009-08-04 16:50:30 +0000885 /// \brief Build a new typename type that refers to an identifier.
886 ///
887 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000888 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000889 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000890 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000891 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000892 NestedNameSpecifierLoc QualifierLoc,
893 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000894 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000895 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000896 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000897
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000898 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000899 // If the name is still dependent, just build a new dependent name type.
900 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000901 return SemaRef.Context.getDependentNameType(Keyword,
902 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000903 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000904 }
905
Abramo Bagnara6150c882010-05-11 21:36:43 +0000906 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000907 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000908 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000909
910 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
911
Abramo Bagnarad7548482010-05-19 21:37:53 +0000912 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000913 // into a non-dependent elaborated-type-specifier. Find the tag we're
914 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000915 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000916 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
917 if (!DC)
918 return QualType();
919
John McCallbf8c5192010-05-27 06:40:31 +0000920 if (SemaRef.RequireCompleteDeclContext(SS, DC))
921 return QualType();
922
Craig Topperc3ec1492014-05-26 06:22:03 +0000923 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000924 SemaRef.LookupQualifiedName(Result, DC);
925 switch (Result.getResultKind()) {
926 case LookupResult::NotFound:
927 case LookupResult::NotFoundInCurrentInstantiation:
928 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000929
Douglas Gregore677daf2010-03-31 22:19:08 +0000930 case LookupResult::Found:
931 Tag = Result.getAsSingle<TagDecl>();
932 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000933
Douglas Gregore677daf2010-03-31 22:19:08 +0000934 case LookupResult::FoundOverloaded:
935 case LookupResult::FoundUnresolvedValue:
936 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000937
Douglas Gregore677daf2010-03-31 22:19:08 +0000938 case LookupResult::Ambiguous:
939 // Let the LookupResult structure handle ambiguities.
940 return QualType();
941 }
942
943 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000944 // Check where the name exists but isn't a tag type and use that to emit
945 // better diagnostics.
946 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
947 SemaRef.LookupQualifiedName(Result, DC);
948 switch (Result.getResultKind()) {
949 case LookupResult::Found:
950 case LookupResult::FoundOverloaded:
951 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000952 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000953 unsigned Kind = 0;
954 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000955 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
956 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000957 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
958 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
959 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000960 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000961 default:
Nick Lewycky0c438082011-01-24 19:01:04 +0000962 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000963 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000964 break;
965 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000966 return QualType();
967 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000968
Richard Trieucaa33d32011-06-10 03:11:26 +0000969 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
970 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000971 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000972 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
973 return QualType();
974 }
975
976 // Build the elaborated-type-specifier type.
977 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000978 return SemaRef.Context.getElaboratedType(Keyword,
979 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000980 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000981 }
Mike Stump11289f42009-09-09 15:08:12 +0000982
Douglas Gregor822d0302011-01-12 17:07:58 +0000983 /// \brief Build a new pack expansion type.
984 ///
985 /// By default, builds a new PackExpansionType type from the given pattern.
986 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000987 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +0000988 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000989 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +0000990 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000991 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
992 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000993 }
994
Eli Friedman0dfb8892011-10-06 23:00:33 +0000995 /// \brief Build a new atomic type given its value type.
996 ///
997 /// By default, performs semantic analysis when building the atomic type.
998 /// Subclasses may override this routine to provide different behavior.
999 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1000
Douglas Gregor71dc5092009-08-06 06:41:21 +00001001 /// \brief Build a new template name given a nested name specifier, a flag
1002 /// indicating whether the "template" keyword was provided, and the template
1003 /// that the template name refers to.
1004 ///
1005 /// By default, builds the new template name directly. Subclasses may override
1006 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001007 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001008 bool TemplateKW,
1009 TemplateDecl *Template);
1010
Douglas Gregor71dc5092009-08-06 06:41:21 +00001011 /// \brief Build a new template name given a nested name specifier and the
1012 /// name that is referred to as a template.
1013 ///
1014 /// By default, performs semantic analysis to determine whether the name can
1015 /// be resolved to a specific template, then builds the appropriate kind of
1016 /// template name. Subclasses may override this routine to provide different
1017 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001018 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1019 const IdentifierInfo &Name,
1020 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001021 QualType ObjectType,
1022 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001023
Douglas Gregor71395fa2009-11-04 00:56:37 +00001024 /// \brief Build a new template name given a nested name specifier and the
1025 /// overloaded operator name that is referred to as a template.
1026 ///
1027 /// By default, performs semantic analysis to determine whether the name can
1028 /// be resolved to a specific template, then builds the appropriate kind of
1029 /// template name. Subclasses may override this routine to provide different
1030 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001031 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001032 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001033 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001034 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001035
1036 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001037 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001038 ///
1039 /// By default, performs semantic analysis to determine whether the name can
1040 /// be resolved to a specific template, then builds the appropriate kind of
1041 /// template name. Subclasses may override this routine to provide different
1042 /// behavior.
1043 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1044 const TemplateArgument &ArgPack) {
1045 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1046 }
1047
Douglas Gregorebe10102009-08-20 07:17:43 +00001048 /// \brief Build a new compound statement.
1049 ///
1050 /// By default, performs semantic analysis to build the new statement.
1051 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001052 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001053 MultiStmtArg Statements,
1054 SourceLocation RBraceLoc,
1055 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001056 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001057 IsStmtExpr);
1058 }
1059
1060 /// \brief Build a new case statement.
1061 ///
1062 /// By default, performs semantic analysis to build the new statement.
1063 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001064 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001065 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001066 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001067 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001068 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001069 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001070 ColonLoc);
1071 }
Mike Stump11289f42009-09-09 15:08:12 +00001072
Douglas Gregorebe10102009-08-20 07:17:43 +00001073 /// \brief Attach the body to a new case statement.
1074 ///
1075 /// By default, performs semantic analysis to build the new statement.
1076 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001077 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001078 getSema().ActOnCaseStmtBody(S, Body);
1079 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001080 }
Mike Stump11289f42009-09-09 15:08:12 +00001081
Douglas Gregorebe10102009-08-20 07:17:43 +00001082 /// \brief Build a new default statement.
1083 ///
1084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001086 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001087 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001088 Stmt *SubStmt) {
1089 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001090 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001091 }
Mike Stump11289f42009-09-09 15:08:12 +00001092
Douglas Gregorebe10102009-08-20 07:17:43 +00001093 /// \brief Build a new label statement.
1094 ///
1095 /// By default, performs semantic analysis to build the new statement.
1096 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001097 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1098 SourceLocation ColonLoc, Stmt *SubStmt) {
1099 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001100 }
Mike Stump11289f42009-09-09 15:08:12 +00001101
Richard Smithc202b282012-04-14 00:33:13 +00001102 /// \brief Build a new label statement.
1103 ///
1104 /// By default, performs semantic analysis to build the new statement.
1105 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001106 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1107 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001108 Stmt *SubStmt) {
1109 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1110 }
1111
Douglas Gregorebe10102009-08-20 07:17:43 +00001112 /// \brief Build a new "if" statement.
1113 ///
1114 /// By default, performs semantic analysis to build the new statement.
1115 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001116 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001117 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001118 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001119 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001120 }
Mike Stump11289f42009-09-09 15:08:12 +00001121
Douglas Gregorebe10102009-08-20 07:17:43 +00001122 /// \brief Start building a new switch statement.
1123 ///
1124 /// By default, performs semantic analysis to build the new statement.
1125 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001126 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001127 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001128 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001129 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001130 }
Mike Stump11289f42009-09-09 15:08:12 +00001131
Douglas Gregorebe10102009-08-20 07:17:43 +00001132 /// \brief Attach the body to the switch statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001136 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001137 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001138 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001139 }
1140
1141 /// \brief Build a new while statement.
1142 ///
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001145 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1146 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001147 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001148 }
Mike Stump11289f42009-09-09 15:08:12 +00001149
Douglas Gregorebe10102009-08-20 07:17:43 +00001150 /// \brief Build a new do-while statement.
1151 ///
1152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001154 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001155 SourceLocation WhileLoc, SourceLocation LParenLoc,
1156 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001157 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1158 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001159 }
1160
1161 /// \brief Build a new for statement.
1162 ///
1163 /// By default, performs semantic analysis to build the new statement.
1164 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001165 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001166 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001167 VarDecl *CondVar, Sema::FullExprArg Inc,
1168 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001169 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001170 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001171 }
Mike Stump11289f42009-09-09 15:08:12 +00001172
Douglas Gregorebe10102009-08-20 07:17:43 +00001173 /// \brief Build a new goto statement.
1174 ///
1175 /// By default, performs semantic analysis to build the new statement.
1176 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001177 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1178 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001179 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001180 }
1181
1182 /// \brief Build a new indirect goto statement.
1183 ///
1184 /// By default, performs semantic analysis to build the new statement.
1185 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001186 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001187 SourceLocation StarLoc,
1188 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001189 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001190 }
Mike Stump11289f42009-09-09 15:08:12 +00001191
Douglas Gregorebe10102009-08-20 07:17:43 +00001192 /// \brief Build a new return statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001196 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001197 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001198 }
Mike Stump11289f42009-09-09 15:08:12 +00001199
Douglas Gregorebe10102009-08-20 07:17:43 +00001200 /// \brief Build a new declaration statement.
1201 ///
1202 /// By default, performs semantic analysis to build the new statement.
1203 /// Subclasses may override this routine to provide different behavior.
Rafael Espindolaab417692013-07-09 12:05:01 +00001204 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1205 SourceLocation StartLoc, SourceLocation EndLoc) {
1206 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001207 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001208 }
Mike Stump11289f42009-09-09 15:08:12 +00001209
Anders Carlssonaaeef072010-01-24 05:50:09 +00001210 /// \brief Build a new inline asm statement.
1211 ///
1212 /// By default, performs semantic analysis to build the new statement.
1213 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001214 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1215 bool IsVolatile, unsigned NumOutputs,
1216 unsigned NumInputs, IdentifierInfo **Names,
1217 MultiExprArg Constraints, MultiExprArg Exprs,
1218 Expr *AsmString, MultiExprArg Clobbers,
1219 SourceLocation RParenLoc) {
1220 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1221 NumInputs, Names, Constraints, Exprs,
1222 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001223 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001224
Chad Rosier32503022012-06-11 20:47:18 +00001225 /// \brief Build a new MS style inline asm statement.
1226 ///
1227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001229 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001230 ArrayRef<Token> AsmToks,
1231 StringRef AsmString,
1232 unsigned NumOutputs, unsigned NumInputs,
1233 ArrayRef<StringRef> Constraints,
1234 ArrayRef<StringRef> Clobbers,
1235 ArrayRef<Expr*> Exprs,
1236 SourceLocation EndLoc) {
1237 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1238 NumOutputs, NumInputs,
1239 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001240 }
1241
James Dennett2a4d13c2012-06-15 07:13:21 +00001242 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001243 ///
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001246 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001247 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001248 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001249 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001250 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001251 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001252 }
1253
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001254 /// \brief Rebuild an Objective-C exception declaration.
1255 ///
1256 /// By default, performs semantic analysis to build the new declaration.
1257 /// Subclasses may override this routine to provide different behavior.
1258 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1259 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001260 return getSema().BuildObjCExceptionDecl(TInfo, T,
1261 ExceptionDecl->getInnerLocStart(),
1262 ExceptionDecl->getLocation(),
1263 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001264 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001265
James Dennett2a4d13c2012-06-15 07:13:21 +00001266 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001267 ///
1268 /// By default, performs semantic analysis to build the new statement.
1269 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001270 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001271 SourceLocation RParenLoc,
1272 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001273 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001274 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001275 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001276 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001277
James Dennett2a4d13c2012-06-15 07:13:21 +00001278 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001279 ///
1280 /// By default, performs semantic analysis to build the new statement.
1281 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001282 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001283 Stmt *Body) {
1284 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001285 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001286
James Dennett2a4d13c2012-06-15 07:13:21 +00001287 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001288 ///
1289 /// By default, performs semantic analysis to build the new statement.
1290 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001291 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001292 Expr *Operand) {
1293 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001294 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001295
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001296 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001297 ///
1298 /// By default, performs semantic analysis to build the new statement.
1299 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001300 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1301 ArrayRef<OMPClause *> Clauses,
1302 Stmt *AStmt,
1303 SourceLocation StartLoc,
1304 SourceLocation EndLoc) {
1305 return getSema().ActOnOpenMPExecutableDirective(Kind, Clauses, AStmt,
1306 StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001307 }
1308
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001309 /// \brief Build a new OpenMP 'if' clause.
1310 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001311 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001312 /// Subclasses may override this routine to provide different behavior.
1313 OMPClause *RebuildOMPIfClause(Expr *Condition,
1314 SourceLocation StartLoc,
1315 SourceLocation LParenLoc,
1316 SourceLocation EndLoc) {
1317 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1318 LParenLoc, EndLoc);
1319 }
1320
Alexey Bataev568a8332014-03-06 06:15:19 +00001321 /// \brief Build a new OpenMP 'num_threads' clause.
1322 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001323 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001324 /// Subclasses may override this routine to provide different behavior.
1325 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1326 SourceLocation StartLoc,
1327 SourceLocation LParenLoc,
1328 SourceLocation EndLoc) {
1329 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1330 LParenLoc, EndLoc);
1331 }
1332
Alexey Bataev62c87d22014-03-21 04:51:18 +00001333 /// \brief Build a new OpenMP 'safelen' clause.
1334 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001335 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001336 /// Subclasses may override this routine to provide different behavior.
1337 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1338 SourceLocation LParenLoc,
1339 SourceLocation EndLoc) {
1340 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1341 }
1342
Alexander Musman8bd31e62014-05-27 15:12:19 +00001343 /// \brief Build a new OpenMP 'collapse' clause.
1344 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001345 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001346 /// Subclasses may override this routine to provide different behavior.
1347 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1348 SourceLocation LParenLoc,
1349 SourceLocation EndLoc) {
1350 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1351 EndLoc);
1352 }
1353
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001354 /// \brief Build a new OpenMP 'default' clause.
1355 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001356 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001357 /// Subclasses may override this routine to provide different behavior.
1358 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1359 SourceLocation KindKwLoc,
1360 SourceLocation StartLoc,
1361 SourceLocation LParenLoc,
1362 SourceLocation EndLoc) {
1363 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1364 StartLoc, LParenLoc, EndLoc);
1365 }
1366
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001367 /// \brief Build a new OpenMP 'proc_bind' clause.
1368 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001369 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001370 /// Subclasses may override this routine to provide different behavior.
1371 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1372 SourceLocation KindKwLoc,
1373 SourceLocation StartLoc,
1374 SourceLocation LParenLoc,
1375 SourceLocation EndLoc) {
1376 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1377 StartLoc, LParenLoc, EndLoc);
1378 }
1379
Alexey Bataev56dafe82014-06-20 07:16:17 +00001380 /// \brief Build a new OpenMP 'schedule' clause.
1381 ///
1382 /// By default, performs semantic analysis to build the new OpenMP clause.
1383 /// Subclasses may override this routine to provide different behavior.
1384 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1385 Expr *ChunkSize,
1386 SourceLocation StartLoc,
1387 SourceLocation LParenLoc,
1388 SourceLocation KindLoc,
1389 SourceLocation CommaLoc,
1390 SourceLocation EndLoc) {
1391 return getSema().ActOnOpenMPScheduleClause(
1392 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1393 }
1394
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001395 /// \brief Build a new OpenMP 'private' clause.
1396 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001397 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001398 /// Subclasses may override this routine to provide different behavior.
1399 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1400 SourceLocation StartLoc,
1401 SourceLocation LParenLoc,
1402 SourceLocation EndLoc) {
1403 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1404 EndLoc);
1405 }
1406
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001407 /// \brief Build a new OpenMP 'firstprivate' clause.
1408 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001409 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001410 /// Subclasses may override this routine to provide different behavior.
1411 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1412 SourceLocation StartLoc,
1413 SourceLocation LParenLoc,
1414 SourceLocation EndLoc) {
1415 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1416 EndLoc);
1417 }
1418
Alexander Musman1bb328c2014-06-04 13:06:39 +00001419 /// \brief Build a new OpenMP 'lastprivate' clause.
1420 ///
1421 /// By default, performs semantic analysis to build the new OpenMP clause.
1422 /// Subclasses may override this routine to provide different behavior.
1423 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1424 SourceLocation StartLoc,
1425 SourceLocation LParenLoc,
1426 SourceLocation EndLoc) {
1427 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1428 EndLoc);
1429 }
1430
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001431 /// \brief Build a new OpenMP 'shared' clause.
1432 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001433 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001434 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001435 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1436 SourceLocation StartLoc,
1437 SourceLocation LParenLoc,
1438 SourceLocation EndLoc) {
1439 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1440 EndLoc);
1441 }
1442
Alexey Bataevc5e02582014-06-16 07:08:35 +00001443 /// \brief Build a new OpenMP 'reduction' clause.
1444 ///
1445 /// By default, performs semantic analysis to build the new statement.
1446 /// Subclasses may override this routine to provide different behavior.
1447 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1448 SourceLocation StartLoc,
1449 SourceLocation LParenLoc,
1450 SourceLocation ColonLoc,
1451 SourceLocation EndLoc,
1452 CXXScopeSpec &ReductionIdScopeSpec,
1453 const DeclarationNameInfo &ReductionId) {
1454 return getSema().ActOnOpenMPReductionClause(
1455 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1456 ReductionId);
1457 }
1458
Alexander Musman8dba6642014-04-22 13:09:42 +00001459 /// \brief Build a new OpenMP 'linear' clause.
1460 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001461 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001462 /// Subclasses may override this routine to provide different behavior.
1463 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1464 SourceLocation StartLoc,
1465 SourceLocation LParenLoc,
1466 SourceLocation ColonLoc,
1467 SourceLocation EndLoc) {
1468 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1469 ColonLoc, EndLoc);
1470 }
1471
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001472 /// \brief Build a new OpenMP 'aligned' clause.
1473 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001474 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001475 /// Subclasses may override this routine to provide different behavior.
1476 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1477 SourceLocation StartLoc,
1478 SourceLocation LParenLoc,
1479 SourceLocation ColonLoc,
1480 SourceLocation EndLoc) {
1481 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1482 LParenLoc, ColonLoc, EndLoc);
1483 }
1484
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001485 /// \brief Build a new OpenMP 'copyin' clause.
1486 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001487 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001488 /// Subclasses may override this routine to provide different behavior.
1489 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1490 SourceLocation StartLoc,
1491 SourceLocation LParenLoc,
1492 SourceLocation EndLoc) {
1493 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1494 EndLoc);
1495 }
1496
James Dennett2a4d13c2012-06-15 07:13:21 +00001497 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001498 ///
1499 /// By default, performs semantic analysis to build the new statement.
1500 /// Subclasses may override this routine to provide different behavior.
1501 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1502 Expr *object) {
1503 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1504 }
1505
James Dennett2a4d13c2012-06-15 07:13:21 +00001506 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001507 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001508 /// By default, performs semantic analysis to build the new statement.
1509 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001510 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001511 Expr *Object, Stmt *Body) {
1512 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001513 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001514
James Dennett2a4d13c2012-06-15 07:13:21 +00001515 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001516 ///
1517 /// By default, performs semantic analysis to build the new statement.
1518 /// Subclasses may override this routine to provide different behavior.
1519 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1520 Stmt *Body) {
1521 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1522 }
John McCall53848232011-07-27 01:07:15 +00001523
Douglas Gregorf68a5082010-04-22 23:10:45 +00001524 /// \brief Build a new Objective-C fast enumeration statement.
1525 ///
1526 /// By default, performs semantic analysis to build the new statement.
1527 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001528 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001529 Stmt *Element,
1530 Expr *Collection,
1531 SourceLocation RParenLoc,
1532 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001533 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001534 Element,
John McCallb268a282010-08-23 23:25:46 +00001535 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001536 RParenLoc);
1537 if (ForEachStmt.isInvalid())
1538 return StmtError();
1539
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001540 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001541 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001542
Douglas Gregorebe10102009-08-20 07:17:43 +00001543 /// \brief Build a new C++ exception declaration.
1544 ///
1545 /// By default, performs semantic analysis to build the new decaration.
1546 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001547 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001548 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001549 SourceLocation StartLoc,
1550 SourceLocation IdLoc,
1551 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001552 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001553 StartLoc, IdLoc, Id);
1554 if (Var)
1555 getSema().CurContext->addDecl(Var);
1556 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001557 }
1558
1559 /// \brief Build a new C++ catch statement.
1560 ///
1561 /// By default, performs semantic analysis to build the new statement.
1562 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001563 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001564 VarDecl *ExceptionDecl,
1565 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001566 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1567 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001568 }
Mike Stump11289f42009-09-09 15:08:12 +00001569
Douglas Gregorebe10102009-08-20 07:17:43 +00001570 /// \brief Build a new C++ try statement.
1571 ///
1572 /// By default, performs semantic analysis to build the new statement.
1573 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001574 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1575 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001576 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001577 }
Mike Stump11289f42009-09-09 15:08:12 +00001578
Richard Smith02e85f32011-04-14 22:09:26 +00001579 /// \brief Build a new C++0x range-based for statement.
1580 ///
1581 /// By default, performs semantic analysis to build the new statement.
1582 /// Subclasses may override this routine to provide different behavior.
1583 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1584 SourceLocation ColonLoc,
1585 Stmt *Range, Stmt *BeginEnd,
1586 Expr *Cond, Expr *Inc,
1587 Stmt *LoopVar,
1588 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001589 // If we've just learned that the range is actually an Objective-C
1590 // collection, treat this as an Objective-C fast enumeration loop.
1591 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1592 if (RangeStmt->isSingleDecl()) {
1593 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001594 if (RangeVar->isInvalidDecl())
1595 return StmtError();
1596
Douglas Gregorf7106af2013-04-08 18:40:13 +00001597 Expr *RangeExpr = RangeVar->getInit();
1598 if (!RangeExpr->isTypeDependent() &&
1599 RangeExpr->getType()->isObjCObjectPointerType())
1600 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1601 RParenLoc);
1602 }
1603 }
1604 }
1605
Richard Smith02e85f32011-04-14 22:09:26 +00001606 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001607 Cond, Inc, LoopVar, RParenLoc,
1608 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001609 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001610
1611 /// \brief Build a new C++0x range-based for statement.
1612 ///
1613 /// By default, performs semantic analysis to build the new statement.
1614 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001615 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001616 bool IsIfExists,
1617 NestedNameSpecifierLoc QualifierLoc,
1618 DeclarationNameInfo NameInfo,
1619 Stmt *Nested) {
1620 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1621 QualifierLoc, NameInfo, Nested);
1622 }
1623
Richard Smith02e85f32011-04-14 22:09:26 +00001624 /// \brief Attach body to a C++0x range-based for statement.
1625 ///
1626 /// By default, performs semantic analysis to finish the new statement.
1627 /// Subclasses may override this routine to provide different behavior.
1628 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1629 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1630 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001631
David Majnemerfad8f482013-10-15 09:33:02 +00001632 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1633 Stmt *TryBlock, Stmt *Handler) {
1634 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001635 }
1636
David Majnemerfad8f482013-10-15 09:33:02 +00001637 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001638 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001639 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001640 }
1641
David Majnemerfad8f482013-10-15 09:33:02 +00001642 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1643 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001644 }
1645
Douglas Gregora16548e2009-08-11 05:31:07 +00001646 /// \brief Build a new expression that references a declaration.
1647 ///
1648 /// By default, performs semantic analysis to build the new expression.
1649 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001650 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001651 LookupResult &R,
1652 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001653 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1654 }
1655
1656
1657 /// \brief Build a new expression that references a declaration.
1658 ///
1659 /// By default, performs semantic analysis to build the new expression.
1660 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001661 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001662 ValueDecl *VD,
1663 const DeclarationNameInfo &NameInfo,
1664 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001665 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001666 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001667
1668 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001669
1670 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001671 }
Mike Stump11289f42009-09-09 15:08:12 +00001672
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001674 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001675 /// By default, performs semantic analysis to build the new expression.
1676 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001677 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001678 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001679 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001680 }
1681
Douglas Gregorad8a3362009-09-04 17:36:40 +00001682 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001683 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001684 /// By default, performs semantic analysis to build the new expression.
1685 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001686 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001687 SourceLocation OperatorLoc,
1688 bool isArrow,
1689 CXXScopeSpec &SS,
1690 TypeSourceInfo *ScopeType,
1691 SourceLocation CCLoc,
1692 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001693 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001694
Douglas Gregora16548e2009-08-11 05:31:07 +00001695 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001696 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001697 /// By default, performs semantic analysis to build the new expression.
1698 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001699 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001700 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001701 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001702 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001703 }
Mike Stump11289f42009-09-09 15:08:12 +00001704
Douglas Gregor882211c2010-04-28 22:16:22 +00001705 /// \brief Build a new builtin offsetof expression.
1706 ///
1707 /// By default, performs semantic analysis to build the new expression.
1708 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001709 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001710 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001711 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001712 unsigned NumComponents,
1713 SourceLocation RParenLoc) {
1714 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1715 NumComponents, RParenLoc);
1716 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001717
1718 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001719 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001720 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001721 /// By default, performs semantic analysis to build the new expression.
1722 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001723 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1724 SourceLocation OpLoc,
1725 UnaryExprOrTypeTrait ExprKind,
1726 SourceRange R) {
1727 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 }
1729
Peter Collingbournee190dee2011-03-11 19:24:49 +00001730 /// \brief Build a new sizeof, alignof or vec step expression with an
1731 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001732 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001733 /// By default, performs semantic analysis to build the new expression.
1734 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001735 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1736 UnaryExprOrTypeTrait ExprKind,
1737 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001738 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001739 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001740 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001741 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001742
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001743 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001744 }
Mike Stump11289f42009-09-09 15:08:12 +00001745
Douglas Gregora16548e2009-08-11 05:31:07 +00001746 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001747 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001748 /// By default, performs semantic analysis to build the new expression.
1749 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001750 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001751 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001752 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001754 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001755 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001756 RBracketLoc);
1757 }
1758
1759 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001760 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 /// By default, performs semantic analysis to build the new expression.
1762 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001763 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001764 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001765 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001766 Expr *ExecConfig = nullptr) {
1767 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001768 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001769 }
1770
1771 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001772 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001773 /// By default, performs semantic analysis to build the new expression.
1774 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001775 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001776 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001777 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001778 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001779 const DeclarationNameInfo &MemberNameInfo,
1780 ValueDecl *Member,
1781 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001782 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001783 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001784 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1785 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001786 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001787 // We have a reference to an unnamed field. This is always the
1788 // base of an anonymous struct/union member access, i.e. the
1789 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001790 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001791 assert(Member->getType()->isRecordType() &&
1792 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001793
Richard Smithcab9a7d2011-10-26 19:06:56 +00001794 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001795 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001796 QualifierLoc.getNestedNameSpecifier(),
1797 FoundDecl, Member);
1798 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001799 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001800 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001801 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001802 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001803 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001804 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001805 cast<FieldDecl>(Member)->getType(),
1806 VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001807 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001808 }
Mike Stump11289f42009-09-09 15:08:12 +00001809
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001810 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001811 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001812
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001813 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001814 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001815
John McCall16df1e52010-03-30 21:47:33 +00001816 // FIXME: this involves duplicating earlier analysis in a lot of
1817 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001818 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001819 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001820 R.resolveKind();
1821
John McCallb268a282010-08-23 23:25:46 +00001822 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001823 SS, TemplateKWLoc,
1824 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001825 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001826 }
Mike Stump11289f42009-09-09 15:08:12 +00001827
Douglas Gregora16548e2009-08-11 05:31:07 +00001828 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001829 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001830 /// By default, performs semantic analysis to build the new expression.
1831 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001832 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001833 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001834 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001835 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001836 }
1837
1838 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001839 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001840 /// By default, performs semantic analysis to build the new expression.
1841 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001842 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001843 SourceLocation QuestionLoc,
1844 Expr *LHS,
1845 SourceLocation ColonLoc,
1846 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001847 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1848 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 }
1850
Douglas Gregora16548e2009-08-11 05:31:07 +00001851 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001852 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001853 /// By default, performs semantic analysis to build the new expression.
1854 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001855 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001856 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001857 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001858 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001859 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001860 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001861 }
Mike Stump11289f42009-09-09 15:08:12 +00001862
Douglas Gregora16548e2009-08-11 05:31:07 +00001863 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001864 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001865 /// By default, performs semantic analysis to build the new expression.
1866 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001867 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001868 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001869 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001870 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001871 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001872 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001873 }
Mike Stump11289f42009-09-09 15:08:12 +00001874
Douglas Gregora16548e2009-08-11 05:31:07 +00001875 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001876 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001877 /// By default, performs semantic analysis to build the new expression.
1878 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001879 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001880 SourceLocation OpLoc,
1881 SourceLocation AccessorLoc,
1882 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001883
John McCall10eae182009-11-30 22:42:35 +00001884 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001885 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001886 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001887 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001888 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001889 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001890 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001891 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 }
Mike Stump11289f42009-09-09 15:08:12 +00001893
Douglas Gregora16548e2009-08-11 05:31:07 +00001894 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001895 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 /// By default, performs semantic analysis to build the new expression.
1897 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001898 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001899 MultiExprArg Inits,
1900 SourceLocation RBraceLoc,
1901 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001902 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001903 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001904 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001905 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001906
Douglas Gregord3d93062009-11-09 17:16:50 +00001907 // Patch in the result type we were given, which may have been computed
1908 // when the initial InitListExpr was built.
1909 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1910 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001911 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001912 }
Mike Stump11289f42009-09-09 15:08:12 +00001913
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001915 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001916 /// By default, performs semantic analysis to build the new expression.
1917 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001918 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001919 MultiExprArg ArrayExprs,
1920 SourceLocation EqualOrColonLoc,
1921 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001922 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001923 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001924 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001925 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001927 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001928
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001929 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 }
Mike Stump11289f42009-09-09 15:08:12 +00001931
Douglas Gregora16548e2009-08-11 05:31:07 +00001932 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001933 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001934 /// By default, builds the implicit value initialization without performing
1935 /// any semantic analysis. Subclasses may override this routine to provide
1936 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001937 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001938 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 }
Mike Stump11289f42009-09-09 15:08:12 +00001940
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001942 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 /// By default, performs semantic analysis to build the new expression.
1944 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001945 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001946 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001947 SourceLocation RParenLoc) {
1948 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001949 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001950 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 }
1952
1953 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001954 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001955 /// By default, performs semantic analysis to build the new expression.
1956 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001957 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001958 MultiExprArg SubExprs,
1959 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001960 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001961 }
Mike Stump11289f42009-09-09 15:08:12 +00001962
Douglas Gregora16548e2009-08-11 05:31:07 +00001963 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001964 ///
1965 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 /// rather than attempting to map the label statement itself.
1967 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001968 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001969 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001970 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 }
Mike Stump11289f42009-09-09 15:08:12 +00001972
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001974 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001975 /// By default, performs semantic analysis to build the new expression.
1976 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001977 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001978 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001979 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001980 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001981 }
Mike Stump11289f42009-09-09 15:08:12 +00001982
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 /// \brief Build a new __builtin_choose_expr expression.
1984 ///
1985 /// By default, performs semantic analysis to build the new expression.
1986 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001987 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001988 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001989 SourceLocation RParenLoc) {
1990 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001991 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001992 RParenLoc);
1993 }
Mike Stump11289f42009-09-09 15:08:12 +00001994
Peter Collingbourne91147592011-04-15 00:35:48 +00001995 /// \brief Build a new generic selection expression.
1996 ///
1997 /// By default, performs semantic analysis to build the new expression.
1998 /// Subclasses may override this routine to provide different behavior.
1999 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2000 SourceLocation DefaultLoc,
2001 SourceLocation RParenLoc,
2002 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002003 ArrayRef<TypeSourceInfo *> Types,
2004 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002005 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002006 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002007 }
2008
Douglas Gregora16548e2009-08-11 05:31:07 +00002009 /// \brief Build a new overloaded operator call expression.
2010 ///
2011 /// By default, performs semantic analysis to build the new expression.
2012 /// The semantic analysis provides the behavior of template instantiation,
2013 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002014 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002015 /// argument-dependent lookup, etc. Subclasses may override this routine to
2016 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002017 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002019 Expr *Callee,
2020 Expr *First,
2021 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002022
2023 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002024 /// reinterpret_cast.
2025 ///
2026 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002027 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002028 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002029 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 Stmt::StmtClass Class,
2031 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002032 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002033 SourceLocation RAngleLoc,
2034 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002035 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002036 SourceLocation RParenLoc) {
2037 switch (Class) {
2038 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002039 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002040 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002041 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002042
2043 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002044 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002045 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002046 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002047
Douglas Gregora16548e2009-08-11 05:31:07 +00002048 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002049 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002050 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002051 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002052 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002053
Douglas Gregora16548e2009-08-11 05:31:07 +00002054 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002055 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002056 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002057 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002058
Douglas Gregora16548e2009-08-11 05:31:07 +00002059 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002060 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002061 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002062 }
Mike Stump11289f42009-09-09 15:08:12 +00002063
Douglas Gregora16548e2009-08-11 05:31:07 +00002064 /// \brief Build a new C++ static_cast expression.
2065 ///
2066 /// By default, performs semantic analysis to build the new expression.
2067 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002068 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002069 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002070 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002071 SourceLocation RAngleLoc,
2072 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002073 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002074 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002075 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002076 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002077 SourceRange(LAngleLoc, RAngleLoc),
2078 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002079 }
2080
2081 /// \brief Build a new C++ dynamic_cast expression.
2082 ///
2083 /// By default, performs semantic analysis to build the new expression.
2084 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002085 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002086 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002087 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002088 SourceLocation RAngleLoc,
2089 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002090 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002091 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002092 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002093 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002094 SourceRange(LAngleLoc, RAngleLoc),
2095 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002096 }
2097
2098 /// \brief Build a new C++ reinterpret_cast expression.
2099 ///
2100 /// By default, performs semantic analysis to build the new expression.
2101 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002102 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002103 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002104 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002105 SourceLocation RAngleLoc,
2106 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002107 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002108 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002109 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002110 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002111 SourceRange(LAngleLoc, RAngleLoc),
2112 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002113 }
2114
2115 /// \brief Build a new C++ const_cast expression.
2116 ///
2117 /// By default, performs semantic analysis to build the new expression.
2118 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002119 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002120 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002121 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002122 SourceLocation RAngleLoc,
2123 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002124 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002125 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002126 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002127 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002128 SourceRange(LAngleLoc, RAngleLoc),
2129 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002130 }
Mike Stump11289f42009-09-09 15:08:12 +00002131
Douglas Gregora16548e2009-08-11 05:31:07 +00002132 /// \brief Build a new C++ functional-style cast expression.
2133 ///
2134 /// By default, performs semantic analysis to build the new expression.
2135 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002136 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2137 SourceLocation LParenLoc,
2138 Expr *Sub,
2139 SourceLocation RParenLoc) {
2140 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002141 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002142 RParenLoc);
2143 }
Mike Stump11289f42009-09-09 15:08:12 +00002144
Douglas Gregora16548e2009-08-11 05:31:07 +00002145 /// \brief Build a new C++ typeid(type) expression.
2146 ///
2147 /// By default, performs semantic analysis to build the new expression.
2148 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002149 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002150 SourceLocation TypeidLoc,
2151 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002152 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002153 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002154 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002155 }
Mike Stump11289f42009-09-09 15:08:12 +00002156
Francois Pichet9f4f2072010-09-08 12:20:18 +00002157
Douglas Gregora16548e2009-08-11 05:31:07 +00002158 /// \brief Build a new C++ typeid(expr) expression.
2159 ///
2160 /// By default, performs semantic analysis to build the new expression.
2161 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002162 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002163 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002164 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002165 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002166 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002167 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002168 }
2169
Francois Pichet9f4f2072010-09-08 12:20:18 +00002170 /// \brief Build a new C++ __uuidof(type) expression.
2171 ///
2172 /// By default, performs semantic analysis to build the new expression.
2173 /// Subclasses may override this routine to provide different behavior.
2174 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2175 SourceLocation TypeidLoc,
2176 TypeSourceInfo *Operand,
2177 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002178 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002179 RParenLoc);
2180 }
2181
2182 /// \brief Build a new C++ __uuidof(expr) expression.
2183 ///
2184 /// By default, performs semantic analysis to build the new expression.
2185 /// Subclasses may override this routine to provide different behavior.
2186 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2187 SourceLocation TypeidLoc,
2188 Expr *Operand,
2189 SourceLocation RParenLoc) {
2190 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2191 RParenLoc);
2192 }
2193
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 /// \brief Build a new C++ "this" expression.
2195 ///
2196 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002197 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002198 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002199 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002200 QualType ThisType,
2201 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002202 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002203 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002204 }
2205
2206 /// \brief Build a new C++ throw expression.
2207 ///
2208 /// By default, performs semantic analysis to build the new expression.
2209 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002210 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2211 bool IsThrownVariableInScope) {
2212 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002213 }
2214
2215 /// \brief Build a new C++ default-argument expression.
2216 ///
2217 /// By default, builds a new default-argument expression, which does not
2218 /// require any semantic analysis. Subclasses may override this routine to
2219 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002220 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002221 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002222 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002223 }
2224
Richard Smith852c9db2013-04-20 22:23:05 +00002225 /// \brief Build a new C++11 default-initialization expression.
2226 ///
2227 /// By default, builds a new default field initialization expression, which
2228 /// does not require any semantic analysis. Subclasses may override this
2229 /// routine to provide different behavior.
2230 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2231 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002232 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002233 }
2234
Douglas Gregora16548e2009-08-11 05:31:07 +00002235 /// \brief Build a new C++ zero-initialization expression.
2236 ///
2237 /// By default, performs semantic analysis to build the new expression.
2238 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002239 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2240 SourceLocation LParenLoc,
2241 SourceLocation RParenLoc) {
2242 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002243 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002244 }
Mike Stump11289f42009-09-09 15:08:12 +00002245
Douglas Gregora16548e2009-08-11 05:31:07 +00002246 /// \brief Build a new C++ "new" expression.
2247 ///
2248 /// By default, performs semantic analysis to build the new expression.
2249 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002250 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002251 bool UseGlobal,
2252 SourceLocation PlacementLParen,
2253 MultiExprArg PlacementArgs,
2254 SourceLocation PlacementRParen,
2255 SourceRange TypeIdParens,
2256 QualType AllocatedType,
2257 TypeSourceInfo *AllocatedTypeInfo,
2258 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002259 SourceRange DirectInitRange,
2260 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002261 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002262 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002263 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002264 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002265 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002266 AllocatedType,
2267 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002268 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002269 DirectInitRange,
2270 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002271 }
Mike Stump11289f42009-09-09 15:08:12 +00002272
Douglas Gregora16548e2009-08-11 05:31:07 +00002273 /// \brief Build a new C++ "delete" expression.
2274 ///
2275 /// By default, performs semantic analysis to build the new expression.
2276 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002277 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002278 bool IsGlobalDelete,
2279 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002280 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002281 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002282 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002283 }
Mike Stump11289f42009-09-09 15:08:12 +00002284
Douglas Gregor29c42f22012-02-24 07:38:34 +00002285 /// \brief Build a new type trait expression.
2286 ///
2287 /// By default, performs semantic analysis to build the new expression.
2288 /// Subclasses may override this routine to provide different behavior.
2289 ExprResult RebuildTypeTrait(TypeTrait Trait,
2290 SourceLocation StartLoc,
2291 ArrayRef<TypeSourceInfo *> Args,
2292 SourceLocation RParenLoc) {
2293 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2294 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002295
John Wiegley6242b6a2011-04-28 00:16:57 +00002296 /// \brief Build a new array type trait expression.
2297 ///
2298 /// By default, performs semantic analysis to build the new expression.
2299 /// Subclasses may override this routine to provide different behavior.
2300 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2301 SourceLocation StartLoc,
2302 TypeSourceInfo *TSInfo,
2303 Expr *DimExpr,
2304 SourceLocation RParenLoc) {
2305 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2306 }
2307
John Wiegleyf9f65842011-04-25 06:54:41 +00002308 /// \brief Build a new expression trait expression.
2309 ///
2310 /// By default, performs semantic analysis to build the new expression.
2311 /// Subclasses may override this routine to provide different behavior.
2312 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2313 SourceLocation StartLoc,
2314 Expr *Queried,
2315 SourceLocation RParenLoc) {
2316 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2317 }
2318
Mike Stump11289f42009-09-09 15:08:12 +00002319 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002320 /// expression.
2321 ///
2322 /// By default, performs semantic analysis to build the new expression.
2323 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002324 ExprResult RebuildDependentScopeDeclRefExpr(
2325 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002326 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002327 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002328 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002329 bool IsAddressOfOperand,
2330 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002331 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002332 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002333
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002334 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002335 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2336 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002337
Reid Kleckner32506ed2014-06-12 23:03:48 +00002338 return getSema().BuildQualifiedDeclarationNameExpr(
2339 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002340 }
2341
2342 /// \brief Build a new template-id expression.
2343 ///
2344 /// By default, performs semantic analysis to build the new expression.
2345 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002346 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002347 SourceLocation TemplateKWLoc,
2348 LookupResult &R,
2349 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002350 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002351 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2352 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002353 }
2354
2355 /// \brief Build a new object-construction expression.
2356 ///
2357 /// By default, performs semantic analysis to build the new expression.
2358 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002359 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002360 SourceLocation Loc,
2361 CXXConstructorDecl *Constructor,
2362 bool IsElidable,
2363 MultiExprArg Args,
2364 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002365 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002366 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002367 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002368 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002369 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002370 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002371 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002372 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002373
Douglas Gregordb121ba2009-12-14 16:27:04 +00002374 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002375 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002376 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002377 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002378 RequiresZeroInit, ConstructKind,
2379 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002380 }
2381
2382 /// \brief Build a new object-construction expression.
2383 ///
2384 /// By default, performs semantic analysis to build the new expression.
2385 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002386 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2387 SourceLocation LParenLoc,
2388 MultiExprArg Args,
2389 SourceLocation RParenLoc) {
2390 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002391 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002392 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002393 RParenLoc);
2394 }
2395
2396 /// \brief Build a new object-construction expression.
2397 ///
2398 /// By default, performs semantic analysis to build the new expression.
2399 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002400 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2401 SourceLocation LParenLoc,
2402 MultiExprArg Args,
2403 SourceLocation RParenLoc) {
2404 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002405 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002406 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002407 RParenLoc);
2408 }
Mike Stump11289f42009-09-09 15:08:12 +00002409
Douglas Gregora16548e2009-08-11 05:31:07 +00002410 /// \brief Build a new member reference expression.
2411 ///
2412 /// By default, performs semantic analysis to build the new expression.
2413 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002414 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002415 QualType BaseType,
2416 bool IsArrow,
2417 SourceLocation OperatorLoc,
2418 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002419 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002420 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002421 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002422 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002423 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002424 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002425
John McCallb268a282010-08-23 23:25:46 +00002426 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002427 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002428 SS, TemplateKWLoc,
2429 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002430 MemberNameInfo,
2431 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002432 }
2433
John McCall10eae182009-11-30 22:42:35 +00002434 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002435 ///
2436 /// By default, performs semantic analysis to build the new expression.
2437 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002438 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2439 SourceLocation OperatorLoc,
2440 bool IsArrow,
2441 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002442 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002443 NamedDecl *FirstQualifierInScope,
2444 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002445 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002446 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002447 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002448
John McCallb268a282010-08-23 23:25:46 +00002449 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002450 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002451 SS, TemplateKWLoc,
2452 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002453 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002454 }
Mike Stump11289f42009-09-09 15:08:12 +00002455
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002456 /// \brief Build a new noexcept expression.
2457 ///
2458 /// By default, performs semantic analysis to build the new expression.
2459 /// Subclasses may override this routine to provide different behavior.
2460 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2461 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2462 }
2463
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002464 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002465 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2466 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002467 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002468 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002469 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002470 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2471 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002472 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002473
2474 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2475 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002476 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002477 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002478
Patrick Beard0caa3942012-04-19 00:25:12 +00002479 /// \brief Build a new Objective-C boxed expression.
2480 ///
2481 /// By default, performs semantic analysis to build the new expression.
2482 /// Subclasses may override this routine to provide different behavior.
2483 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2484 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2485 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002486
Ted Kremeneke65b0862012-03-06 20:05:56 +00002487 /// \brief Build a new Objective-C array literal.
2488 ///
2489 /// By default, performs semantic analysis to build the new expression.
2490 /// Subclasses may override this routine to provide different behavior.
2491 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2492 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002493 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002494 MultiExprArg(Elements, NumElements));
2495 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002496
2497 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002498 Expr *Base, Expr *Key,
2499 ObjCMethodDecl *getterMethod,
2500 ObjCMethodDecl *setterMethod) {
2501 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2502 getterMethod, setterMethod);
2503 }
2504
2505 /// \brief Build a new Objective-C dictionary literal.
2506 ///
2507 /// By default, performs semantic analysis to build the new expression.
2508 /// Subclasses may override this routine to provide different behavior.
2509 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2510 ObjCDictionaryElement *Elements,
2511 unsigned NumElements) {
2512 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2513 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002514
James Dennett2a4d13c2012-06-15 07:13:21 +00002515 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002516 ///
2517 /// By default, performs semantic analysis to build the new expression.
2518 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002519 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002520 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002521 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002522 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002523 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002524
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002525 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002526 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002527 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002528 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002529 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002530 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002531 MultiExprArg Args,
2532 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002533 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2534 ReceiverTypeInfo->getType(),
2535 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002536 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002537 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002538 }
2539
2540 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002541 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002542 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002543 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002544 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002545 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002546 MultiExprArg Args,
2547 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002548 return SemaRef.BuildInstanceMessage(Receiver,
2549 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002550 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002551 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002552 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002553 }
2554
Douglas Gregord51d90d2010-04-26 20:11:03 +00002555 /// \brief Build a new Objective-C ivar reference expression.
2556 ///
2557 /// By default, performs semantic analysis to build the new expression.
2558 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002559 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002560 SourceLocation IvarLoc,
2561 bool IsArrow, bool IsFreeIvar) {
2562 // FIXME: We lose track of the IsFreeIvar bit.
2563 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002564 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2565 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002566 /*FIXME:*/IvarLoc, IsArrow,
2567 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002568 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002569 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002570 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002571 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002572
2573 /// \brief Build a new Objective-C property reference expression.
2574 ///
2575 /// By default, performs semantic analysis to build the new expression.
2576 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002577 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002578 ObjCPropertyDecl *Property,
2579 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002580 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002581 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2582 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2583 /*FIXME:*/PropertyLoc,
2584 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002585 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002586 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002587 NameInfo,
2588 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002589 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002590
John McCallb7bd14f2010-12-02 01:19:52 +00002591 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002592 ///
2593 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002594 /// Subclasses may override this routine to provide different behavior.
2595 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2596 ObjCMethodDecl *Getter,
2597 ObjCMethodDecl *Setter,
2598 SourceLocation PropertyLoc) {
2599 // Since these expressions can only be value-dependent, we do not
2600 // need to perform semantic analysis again.
2601 return Owned(
2602 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2603 VK_LValue, OK_ObjCProperty,
2604 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002605 }
2606
Douglas Gregord51d90d2010-04-26 20:11:03 +00002607 /// \brief Build a new Objective-C "isa" expression.
2608 ///
2609 /// By default, performs semantic analysis to build the new expression.
2610 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002611 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002612 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002613 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002614 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2615 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002616 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002617 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002618 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002619 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002620 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002621 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002622
Douglas Gregora16548e2009-08-11 05:31:07 +00002623 /// \brief Build a new shuffle vector expression.
2624 ///
2625 /// By default, performs semantic analysis to build the new expression.
2626 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002627 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002628 MultiExprArg SubExprs,
2629 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002630 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002631 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002632 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2633 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2634 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002635 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002636
Douglas Gregora16548e2009-08-11 05:31:07 +00002637 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002638 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002639 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2640 SemaRef.Context.BuiltinFnTy,
2641 VK_RValue, BuiltinLoc);
2642 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2643 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002644 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002645
2646 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002647 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002648 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002649 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002650
Douglas Gregora16548e2009-08-11 05:31:07 +00002651 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002652 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002653 }
John McCall31f82722010-11-12 08:19:04 +00002654
Hal Finkelc4d7c822013-09-18 03:29:45 +00002655 /// \brief Build a new convert vector expression.
2656 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2657 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2658 SourceLocation RParenLoc) {
2659 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2660 BuiltinLoc, RParenLoc);
2661 }
2662
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002663 /// \brief Build a new template argument pack expansion.
2664 ///
2665 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002666 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002667 /// different behavior.
2668 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002669 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002670 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002671 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002672 case TemplateArgument::Expression: {
2673 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002674 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2675 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002676 if (Result.isInvalid())
2677 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002678
Douglas Gregor98318c22011-01-03 21:37:45 +00002679 return TemplateArgumentLoc(Result.get(), Result.get());
2680 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002681
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002682 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002683 return TemplateArgumentLoc(TemplateArgument(
2684 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002685 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002686 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002687 Pattern.getTemplateNameLoc(),
2688 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002689
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002690 case TemplateArgument::Null:
2691 case TemplateArgument::Integral:
2692 case TemplateArgument::Declaration:
2693 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002694 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002695 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002696 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002697
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002698 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002699 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002700 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002701 EllipsisLoc,
2702 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002703 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2704 Expansion);
2705 break;
2706 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002707
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002708 return TemplateArgumentLoc();
2709 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002710
Douglas Gregor968f23a2011-01-03 19:31:53 +00002711 /// \brief Build a new expression pack expansion.
2712 ///
2713 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002714 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002715 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002716 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002717 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002718 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002719 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002720
2721 /// \brief Build a new atomic operation expression.
2722 ///
2723 /// By default, performs semantic analysis to build the new expression.
2724 /// Subclasses may override this routine to provide different behavior.
2725 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2726 MultiExprArg SubExprs,
2727 QualType RetTy,
2728 AtomicExpr::AtomicOp Op,
2729 SourceLocation RParenLoc) {
2730 // Just create the expression; there is not any interesting semantic
2731 // analysis here because we can't actually build an AtomicExpr until
2732 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002733 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002734 RParenLoc);
2735 }
2736
John McCall31f82722010-11-12 08:19:04 +00002737private:
Douglas Gregor14454802011-02-25 02:25:35 +00002738 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2739 QualType ObjectType,
2740 NamedDecl *FirstQualifierInScope,
2741 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002742
2743 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2744 QualType ObjectType,
2745 NamedDecl *FirstQualifierInScope,
2746 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002747
2748 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2749 NamedDecl *FirstQualifierInScope,
2750 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002751};
Douglas Gregora16548e2009-08-11 05:31:07 +00002752
Douglas Gregorebe10102009-08-20 07:17:43 +00002753template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002754StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002755 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002756 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002757
Douglas Gregorebe10102009-08-20 07:17:43 +00002758 switch (S->getStmtClass()) {
2759 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002760
Douglas Gregorebe10102009-08-20 07:17:43 +00002761 // Transform individual statement nodes
2762#define STMT(Node, Parent) \
2763 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002764#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002765#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002766#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002767
Douglas Gregorebe10102009-08-20 07:17:43 +00002768 // Transform expressions by calling TransformExpr.
2769#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002770#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002771#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002772#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002773 {
John McCalldadc5752010-08-24 06:29:42 +00002774 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002775 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002776 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002777
Richard Smith945f8d32013-01-14 22:39:08 +00002778 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002779 }
Mike Stump11289f42009-09-09 15:08:12 +00002780 }
2781
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002782 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002783}
Mike Stump11289f42009-09-09 15:08:12 +00002784
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002785template<typename Derived>
2786OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2787 if (!S)
2788 return S;
2789
2790 switch (S->getClauseKind()) {
2791 default: break;
2792 // Transform individual clause nodes
2793#define OPENMP_CLAUSE(Name, Class) \
2794 case OMPC_ ## Name : \
2795 return getDerived().Transform ## Class(cast<Class>(S));
2796#include "clang/Basic/OpenMPKinds.def"
2797 }
2798
2799 return S;
2800}
2801
Mike Stump11289f42009-09-09 15:08:12 +00002802
Douglas Gregore922c772009-08-04 22:27:00 +00002803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002804ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002805 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002806 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002807
2808 switch (E->getStmtClass()) {
2809 case Stmt::NoStmtClass: break;
2810#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002811#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002812#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002813 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002814#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002815 }
2816
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002817 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002818}
2819
2820template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002821ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2822 bool CXXDirectInit) {
2823 // Initializers are instantiated like expressions, except that various outer
2824 // layers are stripped.
2825 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002826 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002827
2828 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2829 Init = ExprTemp->getSubExpr();
2830
Richard Smithe6ca4752013-05-30 22:40:16 +00002831 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2832 Init = MTE->GetTemporaryExpr();
2833
Richard Smithd59b8322012-12-19 01:39:02 +00002834 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2835 Init = Binder->getSubExpr();
2836
2837 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2838 Init = ICE->getSubExprAsWritten();
2839
Richard Smithcc1b96d2013-06-12 22:31:48 +00002840 if (CXXStdInitializerListExpr *ILE =
2841 dyn_cast<CXXStdInitializerListExpr>(Init))
2842 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2843
Richard Smith38a549b2012-12-21 08:13:35 +00002844 // If this is not a direct-initializer, we only need to reconstruct
2845 // InitListExprs. Other forms of copy-initialization will be a no-op if
2846 // the initializer is already the right type.
2847 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2848 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2849 return getDerived().TransformExpr(Init);
2850
2851 // Revert value-initialization back to empty parens.
2852 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2853 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002854 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002855 Parens.getEnd());
2856 }
2857
2858 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2859 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002860 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002861 SourceLocation());
2862
2863 // Revert initialization by constructor back to a parenthesized or braced list
2864 // of expressions. Any other form of initializer can just be reused directly.
2865 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002866 return getDerived().TransformExpr(Init);
2867
2868 SmallVector<Expr*, 8> NewArgs;
2869 bool ArgChanged = false;
2870 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2871 /*IsCall*/true, NewArgs, &ArgChanged))
2872 return ExprError();
2873
2874 // If this was list initialization, revert to list form.
2875 if (Construct->isListInitialization())
2876 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2877 Construct->getLocEnd(),
2878 Construct->getType());
2879
Richard Smithd59b8322012-12-19 01:39:02 +00002880 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002881 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithd59b8322012-12-19 01:39:02 +00002882 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2883 Parens.getEnd());
2884}
2885
2886template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002887bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2888 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002889 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002890 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002891 bool *ArgChanged) {
2892 for (unsigned I = 0; I != NumInputs; ++I) {
2893 // If requested, drop call arguments that need to be dropped.
2894 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2895 if (ArgChanged)
2896 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002897
Douglas Gregora3efea12011-01-03 19:04:46 +00002898 break;
2899 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002900
Douglas Gregor968f23a2011-01-03 19:31:53 +00002901 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2902 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002903
Chris Lattner01cf8db2011-07-20 06:58:45 +00002904 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002905 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2906 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002907
Douglas Gregor968f23a2011-01-03 19:31:53 +00002908 // Determine whether the set of unexpanded parameter packs can and should
2909 // be expanded.
2910 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002911 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002912 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2913 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002914 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2915 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002916 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002917 Expand, RetainExpansion,
2918 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002919 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002920
Douglas Gregor968f23a2011-01-03 19:31:53 +00002921 if (!Expand) {
2922 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002923 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002924 // expansion.
2925 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2926 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2927 if (OutPattern.isInvalid())
2928 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002929
2930 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002931 Expansion->getEllipsisLoc(),
2932 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002933 if (Out.isInvalid())
2934 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002935
Douglas Gregor968f23a2011-01-03 19:31:53 +00002936 if (ArgChanged)
2937 *ArgChanged = true;
2938 Outputs.push_back(Out.get());
2939 continue;
2940 }
John McCall542e7c62011-07-06 07:30:07 +00002941
2942 // Record right away that the argument was changed. This needs
2943 // to happen even if the array expands to nothing.
2944 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002945
Douglas Gregor968f23a2011-01-03 19:31:53 +00002946 // The transform has determined that we should perform an elementwise
2947 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002948 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002949 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2950 ExprResult Out = getDerived().TransformExpr(Pattern);
2951 if (Out.isInvalid())
2952 return true;
2953
Richard Smith9467be42014-06-06 17:33:35 +00002954 // FIXME: Can this happen? We should not try to expand the pack
2955 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002956 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00002957 Out = getDerived().RebuildPackExpansion(
2958 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002959 if (Out.isInvalid())
2960 return true;
2961 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002962
Douglas Gregor968f23a2011-01-03 19:31:53 +00002963 Outputs.push_back(Out.get());
2964 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002965
Richard Smith9467be42014-06-06 17:33:35 +00002966 // If we're supposed to retain a pack expansion, do so by temporarily
2967 // forgetting the partially-substituted parameter pack.
2968 if (RetainExpansion) {
2969 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2970
2971 ExprResult Out = getDerived().TransformExpr(Pattern);
2972 if (Out.isInvalid())
2973 return true;
2974
2975 Out = getDerived().RebuildPackExpansion(
2976 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
2977 if (Out.isInvalid())
2978 return true;
2979
2980 Outputs.push_back(Out.get());
2981 }
2982
Douglas Gregor968f23a2011-01-03 19:31:53 +00002983 continue;
2984 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002985
Richard Smithd59b8322012-12-19 01:39:02 +00002986 ExprResult Result =
2987 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2988 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00002989 if (Result.isInvalid())
2990 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002991
Douglas Gregora3efea12011-01-03 19:04:46 +00002992 if (Result.get() != Inputs[I] && ArgChanged)
2993 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002994
2995 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00002996 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002997
Douglas Gregora3efea12011-01-03 19:04:46 +00002998 return false;
2999}
3000
3001template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003002NestedNameSpecifierLoc
3003TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3004 NestedNameSpecifierLoc NNS,
3005 QualType ObjectType,
3006 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003007 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003008 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003009 Qualifier = Qualifier.getPrefix())
3010 Qualifiers.push_back(Qualifier);
3011
3012 CXXScopeSpec SS;
3013 while (!Qualifiers.empty()) {
3014 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3015 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003016
Douglas Gregor14454802011-02-25 02:25:35 +00003017 switch (QNNS->getKind()) {
3018 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003019 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003020 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003021 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003022 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003023 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003024 FirstQualifierInScope, false))
3025 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003026
Douglas Gregor14454802011-02-25 02:25:35 +00003027 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003028
Douglas Gregor14454802011-02-25 02:25:35 +00003029 case NestedNameSpecifier::Namespace: {
3030 NamespaceDecl *NS
3031 = cast_or_null<NamespaceDecl>(
3032 getDerived().TransformDecl(
3033 Q.getLocalBeginLoc(),
3034 QNNS->getAsNamespace()));
3035 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3036 break;
3037 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003038
Douglas Gregor14454802011-02-25 02:25:35 +00003039 case NestedNameSpecifier::NamespaceAlias: {
3040 NamespaceAliasDecl *Alias
3041 = cast_or_null<NamespaceAliasDecl>(
3042 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3043 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003044 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003045 Q.getLocalEndLoc());
3046 break;
3047 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003048
Douglas Gregor14454802011-02-25 02:25:35 +00003049 case NestedNameSpecifier::Global:
3050 // There is no meaningful transformation that one could perform on the
3051 // global scope.
3052 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3053 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003054
Douglas Gregor14454802011-02-25 02:25:35 +00003055 case NestedNameSpecifier::TypeSpecWithTemplate:
3056 case NestedNameSpecifier::TypeSpec: {
3057 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3058 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003059
Douglas Gregor14454802011-02-25 02:25:35 +00003060 if (!TL)
3061 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003062
Douglas Gregor14454802011-02-25 02:25:35 +00003063 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003064 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003065 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003066 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003067 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003068 if (TL.getType()->isEnumeralType())
3069 SemaRef.Diag(TL.getBeginLoc(),
3070 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003071 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3072 Q.getLocalEndLoc());
3073 break;
3074 }
Richard Trieude756fb2011-05-07 01:36:37 +00003075 // If the nested-name-specifier is an invalid type def, don't emit an
3076 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003077 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3078 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003079 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003080 << TL.getType() << SS.getRange();
3081 }
Douglas Gregor14454802011-02-25 02:25:35 +00003082 return NestedNameSpecifierLoc();
3083 }
Douglas Gregore16af532011-02-28 18:50:33 +00003084 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003085
Douglas Gregore16af532011-02-28 18:50:33 +00003086 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003087 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003088 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003089 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003090
Douglas Gregor14454802011-02-25 02:25:35 +00003091 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003092 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003093 !getDerived().AlwaysRebuild())
3094 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003095
3096 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003097 // nested-name-specifier, do so.
3098 if (SS.location_size() == NNS.getDataLength() &&
3099 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3100 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3101
3102 // Allocate new nested-name-specifier location information.
3103 return SS.getWithLocInContext(SemaRef.Context);
3104}
3105
3106template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003107DeclarationNameInfo
3108TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003109::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003110 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003111 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003112 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003113
3114 switch (Name.getNameKind()) {
3115 case DeclarationName::Identifier:
3116 case DeclarationName::ObjCZeroArgSelector:
3117 case DeclarationName::ObjCOneArgSelector:
3118 case DeclarationName::ObjCMultiArgSelector:
3119 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003120 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003121 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003122 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003123
Douglas Gregorf816bd72009-09-03 22:13:48 +00003124 case DeclarationName::CXXConstructorName:
3125 case DeclarationName::CXXDestructorName:
3126 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003127 TypeSourceInfo *NewTInfo;
3128 CanQualType NewCanTy;
3129 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003130 NewTInfo = getDerived().TransformType(OldTInfo);
3131 if (!NewTInfo)
3132 return DeclarationNameInfo();
3133 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003134 }
3135 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003136 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003137 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003138 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003139 if (NewT.isNull())
3140 return DeclarationNameInfo();
3141 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3142 }
Mike Stump11289f42009-09-09 15:08:12 +00003143
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003144 DeclarationName NewName
3145 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3146 NewCanTy);
3147 DeclarationNameInfo NewNameInfo(NameInfo);
3148 NewNameInfo.setName(NewName);
3149 NewNameInfo.setNamedTypeInfo(NewTInfo);
3150 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003151 }
Mike Stump11289f42009-09-09 15:08:12 +00003152 }
3153
David Blaikie83d382b2011-09-23 05:06:16 +00003154 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003155}
3156
3157template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003158TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003159TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3160 TemplateName Name,
3161 SourceLocation NameLoc,
3162 QualType ObjectType,
3163 NamedDecl *FirstQualifierInScope) {
3164 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3165 TemplateDecl *Template = QTN->getTemplateDecl();
3166 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003167
Douglas Gregor9db53502011-03-02 18:07:45 +00003168 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003169 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003170 Template));
3171 if (!TransTemplate)
3172 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003173
Douglas Gregor9db53502011-03-02 18:07:45 +00003174 if (!getDerived().AlwaysRebuild() &&
3175 SS.getScopeRep() == QTN->getQualifier() &&
3176 TransTemplate == Template)
3177 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003178
Douglas Gregor9db53502011-03-02 18:07:45 +00003179 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3180 TransTemplate);
3181 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003182
Douglas Gregor9db53502011-03-02 18:07:45 +00003183 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3184 if (SS.getScopeRep()) {
3185 // These apply to the scope specifier, not the template.
3186 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003187 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003188 }
3189
Douglas Gregor9db53502011-03-02 18:07:45 +00003190 if (!getDerived().AlwaysRebuild() &&
3191 SS.getScopeRep() == DTN->getQualifier() &&
3192 ObjectType.isNull())
3193 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003194
Douglas Gregor9db53502011-03-02 18:07:45 +00003195 if (DTN->isIdentifier()) {
3196 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003197 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003198 NameLoc,
3199 ObjectType,
3200 FirstQualifierInScope);
3201 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003202
Douglas Gregor9db53502011-03-02 18:07:45 +00003203 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3204 ObjectType);
3205 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003206
Douglas Gregor9db53502011-03-02 18:07:45 +00003207 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3208 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003209 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003210 Template));
3211 if (!TransTemplate)
3212 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003213
Douglas Gregor9db53502011-03-02 18:07:45 +00003214 if (!getDerived().AlwaysRebuild() &&
3215 TransTemplate == Template)
3216 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003217
Douglas Gregor9db53502011-03-02 18:07:45 +00003218 return TemplateName(TransTemplate);
3219 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003220
Douglas Gregor9db53502011-03-02 18:07:45 +00003221 if (SubstTemplateTemplateParmPackStorage *SubstPack
3222 = Name.getAsSubstTemplateTemplateParmPack()) {
3223 TemplateTemplateParmDecl *TransParam
3224 = cast_or_null<TemplateTemplateParmDecl>(
3225 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3226 if (!TransParam)
3227 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003228
Douglas Gregor9db53502011-03-02 18:07:45 +00003229 if (!getDerived().AlwaysRebuild() &&
3230 TransParam == SubstPack->getParameterPack())
3231 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003232
3233 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003234 SubstPack->getArgumentPack());
3235 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003236
Douglas Gregor9db53502011-03-02 18:07:45 +00003237 // These should be getting filtered out before they reach the AST.
3238 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003239}
3240
3241template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003242void TreeTransform<Derived>::InventTemplateArgumentLoc(
3243 const TemplateArgument &Arg,
3244 TemplateArgumentLoc &Output) {
3245 SourceLocation Loc = getDerived().getBaseLocation();
3246 switch (Arg.getKind()) {
3247 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003248 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003249 break;
3250
3251 case TemplateArgument::Type:
3252 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003253 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003254
John McCall0ad16662009-10-29 08:12:44 +00003255 break;
3256
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003257 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003258 case TemplateArgument::TemplateExpansion: {
3259 NestedNameSpecifierLocBuilder Builder;
3260 TemplateName Template = Arg.getAsTemplate();
3261 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3262 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3263 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3264 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003265
Douglas Gregor9d802122011-03-02 17:09:35 +00003266 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003267 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003268 Builder.getWithLocInContext(SemaRef.Context),
3269 Loc);
3270 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003271 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003272 Builder.getWithLocInContext(SemaRef.Context),
3273 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003274
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003275 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003276 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003277
John McCall0ad16662009-10-29 08:12:44 +00003278 case TemplateArgument::Expression:
3279 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3280 break;
3281
3282 case TemplateArgument::Declaration:
3283 case TemplateArgument::Integral:
3284 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003285 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003286 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003287 break;
3288 }
3289}
3290
3291template<typename Derived>
3292bool TreeTransform<Derived>::TransformTemplateArgument(
3293 const TemplateArgumentLoc &Input,
3294 TemplateArgumentLoc &Output) {
3295 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003296 switch (Arg.getKind()) {
3297 case TemplateArgument::Null:
3298 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003299 case TemplateArgument::Pack:
3300 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003301 case TemplateArgument::NullPtr:
3302 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003303
Douglas Gregore922c772009-08-04 22:27:00 +00003304 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003305 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003306 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003307 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003308
3309 DI = getDerived().TransformType(DI);
3310 if (!DI) return true;
3311
3312 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3313 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003314 }
Mike Stump11289f42009-09-09 15:08:12 +00003315
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003316 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003317 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3318 if (QualifierLoc) {
3319 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3320 if (!QualifierLoc)
3321 return true;
3322 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003323
Douglas Gregordf846d12011-03-02 18:46:51 +00003324 CXXScopeSpec SS;
3325 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003326 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003327 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3328 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003329 if (Template.isNull())
3330 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003331
Douglas Gregor9d802122011-03-02 17:09:35 +00003332 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003333 Input.getTemplateNameLoc());
3334 return false;
3335 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003336
3337 case TemplateArgument::TemplateExpansion:
3338 llvm_unreachable("Caller should expand pack expansions");
3339
Douglas Gregore922c772009-08-04 22:27:00 +00003340 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003341 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003342 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003343 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003344
John McCall0ad16662009-10-29 08:12:44 +00003345 Expr *InputExpr = Input.getSourceExpression();
3346 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3347
Chris Lattnercdb591a2011-04-25 20:37:58 +00003348 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003349 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003350 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003351 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003352 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003353 }
Douglas Gregore922c772009-08-04 22:27:00 +00003354 }
Mike Stump11289f42009-09-09 15:08:12 +00003355
Douglas Gregore922c772009-08-04 22:27:00 +00003356 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003357 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003358}
3359
Douglas Gregorfe921a72010-12-20 23:36:19 +00003360/// \brief Iterator adaptor that invents template argument location information
3361/// for each of the template arguments in its underlying iterator.
3362template<typename Derived, typename InputIterator>
3363class TemplateArgumentLocInventIterator {
3364 TreeTransform<Derived> &Self;
3365 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003366
Douglas Gregorfe921a72010-12-20 23:36:19 +00003367public:
3368 typedef TemplateArgumentLoc value_type;
3369 typedef TemplateArgumentLoc reference;
3370 typedef typename std::iterator_traits<InputIterator>::difference_type
3371 difference_type;
3372 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003373
Douglas Gregorfe921a72010-12-20 23:36:19 +00003374 class pointer {
3375 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003376
Douglas Gregorfe921a72010-12-20 23:36:19 +00003377 public:
3378 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003379
Douglas Gregorfe921a72010-12-20 23:36:19 +00003380 const TemplateArgumentLoc *operator->() const { return &Arg; }
3381 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003382
Douglas Gregorfe921a72010-12-20 23:36:19 +00003383 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003384
Douglas Gregorfe921a72010-12-20 23:36:19 +00003385 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3386 InputIterator Iter)
3387 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003388
Douglas Gregorfe921a72010-12-20 23:36:19 +00003389 TemplateArgumentLocInventIterator &operator++() {
3390 ++Iter;
3391 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003392 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003393
Douglas Gregorfe921a72010-12-20 23:36:19 +00003394 TemplateArgumentLocInventIterator operator++(int) {
3395 TemplateArgumentLocInventIterator Old(*this);
3396 ++(*this);
3397 return Old;
3398 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003399
Douglas Gregorfe921a72010-12-20 23:36:19 +00003400 reference operator*() const {
3401 TemplateArgumentLoc Result;
3402 Self.InventTemplateArgumentLoc(*Iter, Result);
3403 return Result;
3404 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003405
Douglas Gregorfe921a72010-12-20 23:36:19 +00003406 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003407
Douglas Gregorfe921a72010-12-20 23:36:19 +00003408 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3409 const TemplateArgumentLocInventIterator &Y) {
3410 return X.Iter == Y.Iter;
3411 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003412
Douglas Gregorfe921a72010-12-20 23:36:19 +00003413 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3414 const TemplateArgumentLocInventIterator &Y) {
3415 return X.Iter != Y.Iter;
3416 }
3417};
Chad Rosier1dcde962012-08-08 18:46:20 +00003418
Douglas Gregor42cafa82010-12-20 17:42:22 +00003419template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003420template<typename InputIterator>
3421bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3422 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003423 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003424 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003425 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003426 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003427
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003428 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3429 // Unpack argument packs, which we translate them into separate
3430 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003431 // FIXME: We could do much better if we could guarantee that the
3432 // TemplateArgumentLocInfo for the pack expansion would be usable for
3433 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003434 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003435 TemplateArgument::pack_iterator>
3436 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003437 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003438 In.getArgument().pack_begin()),
3439 PackLocIterator(*this,
3440 In.getArgument().pack_end()),
3441 Outputs))
3442 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003443
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003444 continue;
3445 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003446
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003447 if (In.getArgument().isPackExpansion()) {
3448 // We have a pack expansion, for which we will be substituting into
3449 // the pattern.
3450 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003451 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003452 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003453 = getSema().getTemplateArgumentPackExpansionPattern(
3454 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003455
Chris Lattner01cf8db2011-07-20 06:58:45 +00003456 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003457 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3458 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003459
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003460 // Determine whether the set of unexpanded parameter packs can and should
3461 // be expanded.
3462 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003463 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003464 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003465 if (getDerived().TryExpandParameterPacks(Ellipsis,
3466 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003467 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003468 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003469 RetainExpansion,
3470 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003471 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003472
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003473 if (!Expand) {
3474 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003475 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003476 // expansion.
3477 TemplateArgumentLoc OutPattern;
3478 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3479 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3480 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003481
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003482 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3483 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003484 if (Out.getArgument().isNull())
3485 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003486
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003487 Outputs.addArgument(Out);
3488 continue;
3489 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003490
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003491 // The transform has determined that we should perform an elementwise
3492 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003493 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003494 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3495
3496 if (getDerived().TransformTemplateArgument(Pattern, Out))
3497 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003498
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003499 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003500 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3501 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003502 if (Out.getArgument().isNull())
3503 return true;
3504 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003505
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003506 Outputs.addArgument(Out);
3507 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003508
Douglas Gregor48d24112011-01-10 20:53:55 +00003509 // If we're supposed to retain a pack expansion, do so by temporarily
3510 // forgetting the partially-substituted parameter pack.
3511 if (RetainExpansion) {
3512 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003513
Douglas Gregor48d24112011-01-10 20:53:55 +00003514 if (getDerived().TransformTemplateArgument(Pattern, Out))
3515 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003516
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003517 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3518 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003519 if (Out.getArgument().isNull())
3520 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003521
Douglas Gregor48d24112011-01-10 20:53:55 +00003522 Outputs.addArgument(Out);
3523 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003524
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003525 continue;
3526 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003527
3528 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003529 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003530 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003531
Douglas Gregor42cafa82010-12-20 17:42:22 +00003532 Outputs.addArgument(Out);
3533 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003534
Douglas Gregor42cafa82010-12-20 17:42:22 +00003535 return false;
3536
3537}
3538
Douglas Gregord6ff3322009-08-04 16:50:30 +00003539//===----------------------------------------------------------------------===//
3540// Type transformation
3541//===----------------------------------------------------------------------===//
3542
3543template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003544QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003545 if (getDerived().AlreadyTransformed(T))
3546 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003547
John McCall550e0c22009-10-21 00:40:46 +00003548 // Temporary workaround. All of these transformations should
3549 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003550 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3551 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003552
John McCall31f82722010-11-12 08:19:04 +00003553 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003554
John McCall550e0c22009-10-21 00:40:46 +00003555 if (!NewDI)
3556 return QualType();
3557
3558 return NewDI->getType();
3559}
3560
3561template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003562TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003563 // Refine the base location to the type's location.
3564 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3565 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003566 if (getDerived().AlreadyTransformed(DI->getType()))
3567 return DI;
3568
3569 TypeLocBuilder TLB;
3570
3571 TypeLoc TL = DI->getTypeLoc();
3572 TLB.reserve(TL.getFullDataSize());
3573
John McCall31f82722010-11-12 08:19:04 +00003574 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003575 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003576 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003577
John McCallbcd03502009-12-07 02:54:59 +00003578 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003579}
3580
3581template<typename Derived>
3582QualType
John McCall31f82722010-11-12 08:19:04 +00003583TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003584 switch (T.getTypeLocClass()) {
3585#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003586#define TYPELOC(CLASS, PARENT) \
3587 case TypeLoc::CLASS: \
3588 return getDerived().Transform##CLASS##Type(TLB, \
3589 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003590#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003591 }
Mike Stump11289f42009-09-09 15:08:12 +00003592
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003593 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003594}
3595
3596/// FIXME: By default, this routine adds type qualifiers only to types
3597/// that can have qualifiers, and silently suppresses those qualifiers
3598/// that are not permitted (e.g., qualifiers on reference or function
3599/// types). This is the right thing for template instantiation, but
3600/// probably not for other clients.
3601template<typename Derived>
3602QualType
3603TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003604 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003605 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003606
John McCall31f82722010-11-12 08:19:04 +00003607 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003608 if (Result.isNull())
3609 return QualType();
3610
3611 // Silently suppress qualifiers if the result type can't be qualified.
3612 // FIXME: this is the right thing for template instantiation, but
3613 // probably not for other clients.
3614 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003615 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003616
John McCall31168b02011-06-15 23:02:42 +00003617 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003618 // resulting type.
3619 if (Quals.hasObjCLifetime()) {
3620 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3621 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003622 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003623 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003624 // A lifetime qualifier applied to a substituted template parameter
3625 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003626 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003627 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003628 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3629 QualType Replacement = SubstTypeParam->getReplacementType();
3630 Qualifiers Qs = Replacement.getQualifiers();
3631 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003632 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003633 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3634 Qs);
3635 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003636 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003637 Replacement);
3638 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003639 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3640 // 'auto' types behave the same way as template parameters.
3641 QualType Deduced = AutoTy->getDeducedType();
3642 Qualifiers Qs = Deduced.getQualifiers();
3643 Qs.removeObjCLifetime();
3644 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3645 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003646 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3647 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003648 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003649 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003650 // Otherwise, complain about the addition of a qualifier to an
3651 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003652 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003653 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003654 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003655
Douglas Gregore46db902011-06-17 22:11:49 +00003656 Quals.removeObjCLifetime();
3657 }
3658 }
3659 }
John McCallcb0f89a2010-06-05 06:41:15 +00003660 if (!Quals.empty()) {
3661 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003662 // BuildQualifiedType might not add qualifiers if they are invalid.
3663 if (Result.hasLocalQualifiers())
3664 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003665 // No location information to preserve.
3666 }
John McCall550e0c22009-10-21 00:40:46 +00003667
3668 return Result;
3669}
3670
Douglas Gregor14454802011-02-25 02:25:35 +00003671template<typename Derived>
3672TypeLoc
3673TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3674 QualType ObjectType,
3675 NamedDecl *UnqualLookup,
3676 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003677 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003678 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003679
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003680 TypeSourceInfo *TSI =
3681 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3682 if (TSI)
3683 return TSI->getTypeLoc();
3684 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003685}
3686
Douglas Gregor579c15f2011-03-02 18:32:08 +00003687template<typename Derived>
3688TypeSourceInfo *
3689TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3690 QualType ObjectType,
3691 NamedDecl *UnqualLookup,
3692 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003693 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003694 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003695
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003696 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3697 UnqualLookup, SS);
3698}
3699
3700template <typename Derived>
3701TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3702 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3703 CXXScopeSpec &SS) {
3704 QualType T = TL.getType();
3705 assert(!getDerived().AlreadyTransformed(T));
3706
Douglas Gregor579c15f2011-03-02 18:32:08 +00003707 TypeLocBuilder TLB;
3708 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003709
Douglas Gregor579c15f2011-03-02 18:32:08 +00003710 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003711 TemplateSpecializationTypeLoc SpecTL =
3712 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003713
Douglas Gregor579c15f2011-03-02 18:32:08 +00003714 TemplateName Template
3715 = getDerived().TransformTemplateName(SS,
3716 SpecTL.getTypePtr()->getTemplateName(),
3717 SpecTL.getTemplateNameLoc(),
3718 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003719 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003720 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003721
3722 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003723 Template);
3724 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003725 DependentTemplateSpecializationTypeLoc SpecTL =
3726 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003727
Douglas Gregor579c15f2011-03-02 18:32:08 +00003728 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003729 = getDerived().RebuildTemplateName(SS,
3730 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003731 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003732 ObjectType, UnqualLookup);
3733 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003734 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003735
3736 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003737 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003738 Template,
3739 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003740 } else {
3741 // Nothing special needs to be done for these.
3742 Result = getDerived().TransformType(TLB, TL);
3743 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003744
3745 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003746 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003747
Douglas Gregor579c15f2011-03-02 18:32:08 +00003748 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3749}
3750
John McCall550e0c22009-10-21 00:40:46 +00003751template <class TyLoc> static inline
3752QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3753 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3754 NewT.setNameLoc(T.getNameLoc());
3755 return T.getType();
3756}
3757
John McCall550e0c22009-10-21 00:40:46 +00003758template<typename Derived>
3759QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003760 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003761 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3762 NewT.setBuiltinLoc(T.getBuiltinLoc());
3763 if (T.needsExtraLocalData())
3764 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3765 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003766}
Mike Stump11289f42009-09-09 15:08:12 +00003767
Douglas Gregord6ff3322009-08-04 16:50:30 +00003768template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003769QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003770 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003771 // FIXME: recurse?
3772 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003773}
Mike Stump11289f42009-09-09 15:08:12 +00003774
Reid Kleckner0503a872013-12-05 01:23:43 +00003775template <typename Derived>
3776QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3777 AdjustedTypeLoc TL) {
3778 // Adjustments applied during transformation are handled elsewhere.
3779 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3780}
3781
Douglas Gregord6ff3322009-08-04 16:50:30 +00003782template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003783QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3784 DecayedTypeLoc TL) {
3785 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3786 if (OriginalType.isNull())
3787 return QualType();
3788
3789 QualType Result = TL.getType();
3790 if (getDerived().AlwaysRebuild() ||
3791 OriginalType != TL.getOriginalLoc().getType())
3792 Result = SemaRef.Context.getDecayedType(OriginalType);
3793 TLB.push<DecayedTypeLoc>(Result);
3794 // Nothing to set for DecayedTypeLoc.
3795 return Result;
3796}
3797
3798template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003799QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003800 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003801 QualType PointeeType
3802 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003803 if (PointeeType.isNull())
3804 return QualType();
3805
3806 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003807 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003808 // A dependent pointer type 'T *' has is being transformed such
3809 // that an Objective-C class type is being replaced for 'T'. The
3810 // resulting pointer type is an ObjCObjectPointerType, not a
3811 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003812 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003813
John McCall8b07ec22010-05-15 11:32:37 +00003814 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3815 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003816 return Result;
3817 }
John McCall31f82722010-11-12 08:19:04 +00003818
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003819 if (getDerived().AlwaysRebuild() ||
3820 PointeeType != TL.getPointeeLoc().getType()) {
3821 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3822 if (Result.isNull())
3823 return QualType();
3824 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003825
John McCall31168b02011-06-15 23:02:42 +00003826 // Objective-C ARC can add lifetime qualifiers to the type that we're
3827 // pointing to.
3828 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003829
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003830 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3831 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003832 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003833}
Mike Stump11289f42009-09-09 15:08:12 +00003834
3835template<typename Derived>
3836QualType
John McCall550e0c22009-10-21 00:40:46 +00003837TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003838 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003839 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003840 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3841 if (PointeeType.isNull())
3842 return QualType();
3843
3844 QualType Result = TL.getType();
3845 if (getDerived().AlwaysRebuild() ||
3846 PointeeType != TL.getPointeeLoc().getType()) {
3847 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003848 TL.getSigilLoc());
3849 if (Result.isNull())
3850 return QualType();
3851 }
3852
Douglas Gregor049211a2010-04-22 16:50:51 +00003853 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003854 NewT.setSigilLoc(TL.getSigilLoc());
3855 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003856}
3857
John McCall70dd5f62009-10-30 00:06:24 +00003858/// Transforms a reference type. Note that somewhat paradoxically we
3859/// don't care whether the type itself is an l-value type or an r-value
3860/// type; we only care if the type was *written* as an l-value type
3861/// or an r-value type.
3862template<typename Derived>
3863QualType
3864TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003865 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003866 const ReferenceType *T = TL.getTypePtr();
3867
3868 // Note that this works with the pointee-as-written.
3869 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3870 if (PointeeType.isNull())
3871 return QualType();
3872
3873 QualType Result = TL.getType();
3874 if (getDerived().AlwaysRebuild() ||
3875 PointeeType != T->getPointeeTypeAsWritten()) {
3876 Result = getDerived().RebuildReferenceType(PointeeType,
3877 T->isSpelledAsLValue(),
3878 TL.getSigilLoc());
3879 if (Result.isNull())
3880 return QualType();
3881 }
3882
John McCall31168b02011-06-15 23:02:42 +00003883 // Objective-C ARC can add lifetime qualifiers to the type that we're
3884 // referring to.
3885 TLB.TypeWasModifiedSafely(
3886 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3887
John McCall70dd5f62009-10-30 00:06:24 +00003888 // r-value references can be rebuilt as l-value references.
3889 ReferenceTypeLoc NewTL;
3890 if (isa<LValueReferenceType>(Result))
3891 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3892 else
3893 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3894 NewTL.setSigilLoc(TL.getSigilLoc());
3895
3896 return Result;
3897}
3898
Mike Stump11289f42009-09-09 15:08:12 +00003899template<typename Derived>
3900QualType
John McCall550e0c22009-10-21 00:40:46 +00003901TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003902 LValueReferenceTypeLoc TL) {
3903 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003904}
3905
Mike Stump11289f42009-09-09 15:08:12 +00003906template<typename Derived>
3907QualType
John McCall550e0c22009-10-21 00:40:46 +00003908TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003909 RValueReferenceTypeLoc TL) {
3910 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003911}
Mike Stump11289f42009-09-09 15:08:12 +00003912
Douglas Gregord6ff3322009-08-04 16:50:30 +00003913template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003914QualType
John McCall550e0c22009-10-21 00:40:46 +00003915TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003916 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003917 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003918 if (PointeeType.isNull())
3919 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003920
Abramo Bagnara509357842011-03-05 14:42:21 +00003921 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003922 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00003923 if (OldClsTInfo) {
3924 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3925 if (!NewClsTInfo)
3926 return QualType();
3927 }
3928
3929 const MemberPointerType *T = TL.getTypePtr();
3930 QualType OldClsType = QualType(T->getClass(), 0);
3931 QualType NewClsType;
3932 if (NewClsTInfo)
3933 NewClsType = NewClsTInfo->getType();
3934 else {
3935 NewClsType = getDerived().TransformType(OldClsType);
3936 if (NewClsType.isNull())
3937 return QualType();
3938 }
Mike Stump11289f42009-09-09 15:08:12 +00003939
John McCall550e0c22009-10-21 00:40:46 +00003940 QualType Result = TL.getType();
3941 if (getDerived().AlwaysRebuild() ||
3942 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003943 NewClsType != OldClsType) {
3944 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003945 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003946 if (Result.isNull())
3947 return QualType();
3948 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003949
Reid Kleckner0503a872013-12-05 01:23:43 +00003950 // If we had to adjust the pointee type when building a member pointer, make
3951 // sure to push TypeLoc info for it.
3952 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3953 if (MPT && PointeeType != MPT->getPointeeType()) {
3954 assert(isa<AdjustedType>(MPT->getPointeeType()));
3955 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3956 }
3957
John McCall550e0c22009-10-21 00:40:46 +00003958 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3959 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003960 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003961
3962 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003963}
3964
Mike Stump11289f42009-09-09 15:08:12 +00003965template<typename Derived>
3966QualType
John McCall550e0c22009-10-21 00:40:46 +00003967TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003968 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003969 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003970 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003971 if (ElementType.isNull())
3972 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003973
John McCall550e0c22009-10-21 00:40:46 +00003974 QualType Result = TL.getType();
3975 if (getDerived().AlwaysRebuild() ||
3976 ElementType != T->getElementType()) {
3977 Result = getDerived().RebuildConstantArrayType(ElementType,
3978 T->getSizeModifier(),
3979 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003980 T->getIndexTypeCVRQualifiers(),
3981 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003982 if (Result.isNull())
3983 return QualType();
3984 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00003985
3986 // We might have either a ConstantArrayType or a VariableArrayType now:
3987 // a ConstantArrayType is allowed to have an element type which is a
3988 // VariableArrayType if the type is dependent. Fortunately, all array
3989 // types have the same location layout.
3990 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003991 NewTL.setLBracketLoc(TL.getLBracketLoc());
3992 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003993
John McCall550e0c22009-10-21 00:40:46 +00003994 Expr *Size = TL.getSizeExpr();
3995 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003996 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3997 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003998 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
3999 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004000 }
4001 NewTL.setSizeExpr(Size);
4002
4003 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004004}
Mike Stump11289f42009-09-09 15:08:12 +00004005
Douglas Gregord6ff3322009-08-04 16:50:30 +00004006template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004007QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004008 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004009 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004010 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004011 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004012 if (ElementType.isNull())
4013 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004014
John McCall550e0c22009-10-21 00:40:46 +00004015 QualType Result = TL.getType();
4016 if (getDerived().AlwaysRebuild() ||
4017 ElementType != T->getElementType()) {
4018 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004019 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004020 T->getIndexTypeCVRQualifiers(),
4021 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004022 if (Result.isNull())
4023 return QualType();
4024 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004025
John McCall550e0c22009-10-21 00:40:46 +00004026 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4027 NewTL.setLBracketLoc(TL.getLBracketLoc());
4028 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004029 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004030
4031 return Result;
4032}
4033
4034template<typename Derived>
4035QualType
4036TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004037 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004038 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004039 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4040 if (ElementType.isNull())
4041 return QualType();
4042
John McCalldadc5752010-08-24 06:29:42 +00004043 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004044 = getDerived().TransformExpr(T->getSizeExpr());
4045 if (SizeResult.isInvalid())
4046 return QualType();
4047
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004048 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004049
4050 QualType Result = TL.getType();
4051 if (getDerived().AlwaysRebuild() ||
4052 ElementType != T->getElementType() ||
4053 Size != T->getSizeExpr()) {
4054 Result = getDerived().RebuildVariableArrayType(ElementType,
4055 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004056 Size,
John McCall550e0c22009-10-21 00:40:46 +00004057 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004058 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004059 if (Result.isNull())
4060 return QualType();
4061 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004062
Serge Pavlov774c6d02014-02-06 03:49:11 +00004063 // We might have constant size array now, but fortunately it has the same
4064 // location layout.
4065 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004066 NewTL.setLBracketLoc(TL.getLBracketLoc());
4067 NewTL.setRBracketLoc(TL.getRBracketLoc());
4068 NewTL.setSizeExpr(Size);
4069
4070 return Result;
4071}
4072
4073template<typename Derived>
4074QualType
4075TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004076 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004077 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004078 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4079 if (ElementType.isNull())
4080 return QualType();
4081
Richard Smith764d2fe2011-12-20 02:08:33 +00004082 // Array bounds are constant expressions.
4083 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4084 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004085
John McCall33ddac02011-01-19 10:06:00 +00004086 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4087 Expr *origSize = TL.getSizeExpr();
4088 if (!origSize) origSize = T->getSizeExpr();
4089
4090 ExprResult sizeResult
4091 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004092 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004093 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004094 return QualType();
4095
John McCall33ddac02011-01-19 10:06:00 +00004096 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004097
4098 QualType Result = TL.getType();
4099 if (getDerived().AlwaysRebuild() ||
4100 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004101 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004102 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4103 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004104 size,
John McCall550e0c22009-10-21 00:40:46 +00004105 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004106 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004107 if (Result.isNull())
4108 return QualType();
4109 }
John McCall550e0c22009-10-21 00:40:46 +00004110
4111 // We might have any sort of array type now, but fortunately they
4112 // all have the same location layout.
4113 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4114 NewTL.setLBracketLoc(TL.getLBracketLoc());
4115 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004116 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004117
4118 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004119}
Mike Stump11289f42009-09-09 15:08:12 +00004120
4121template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004122QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004123 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004124 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004125 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004126
4127 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004128 QualType ElementType = getDerived().TransformType(T->getElementType());
4129 if (ElementType.isNull())
4130 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004131
Richard Smith764d2fe2011-12-20 02:08:33 +00004132 // Vector sizes are constant expressions.
4133 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4134 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004135
John McCalldadc5752010-08-24 06:29:42 +00004136 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004137 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004138 if (Size.isInvalid())
4139 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004140
John McCall550e0c22009-10-21 00:40:46 +00004141 QualType Result = TL.getType();
4142 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004143 ElementType != T->getElementType() ||
4144 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004145 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004146 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004147 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004148 if (Result.isNull())
4149 return QualType();
4150 }
John McCall550e0c22009-10-21 00:40:46 +00004151
4152 // Result might be dependent or not.
4153 if (isa<DependentSizedExtVectorType>(Result)) {
4154 DependentSizedExtVectorTypeLoc NewTL
4155 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4156 NewTL.setNameLoc(TL.getNameLoc());
4157 } else {
4158 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4159 NewTL.setNameLoc(TL.getNameLoc());
4160 }
4161
4162 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004163}
Mike Stump11289f42009-09-09 15:08:12 +00004164
4165template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004166QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004167 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004168 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004169 QualType ElementType = getDerived().TransformType(T->getElementType());
4170 if (ElementType.isNull())
4171 return QualType();
4172
John McCall550e0c22009-10-21 00:40:46 +00004173 QualType Result = TL.getType();
4174 if (getDerived().AlwaysRebuild() ||
4175 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004176 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004177 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004178 if (Result.isNull())
4179 return QualType();
4180 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004181
John McCall550e0c22009-10-21 00:40:46 +00004182 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4183 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004184
John McCall550e0c22009-10-21 00:40:46 +00004185 return Result;
4186}
4187
4188template<typename Derived>
4189QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004190 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004191 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004192 QualType ElementType = getDerived().TransformType(T->getElementType());
4193 if (ElementType.isNull())
4194 return QualType();
4195
4196 QualType Result = TL.getType();
4197 if (getDerived().AlwaysRebuild() ||
4198 ElementType != T->getElementType()) {
4199 Result = getDerived().RebuildExtVectorType(ElementType,
4200 T->getNumElements(),
4201 /*FIXME*/ SourceLocation());
4202 if (Result.isNull())
4203 return QualType();
4204 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004205
John McCall550e0c22009-10-21 00:40:46 +00004206 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4207 NewTL.setNameLoc(TL.getNameLoc());
4208
4209 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004210}
Mike Stump11289f42009-09-09 15:08:12 +00004211
David Blaikie05785d12013-02-20 22:23:23 +00004212template <typename Derived>
4213ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4214 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4215 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004216 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004217 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004218
Douglas Gregor715e4612011-01-14 22:40:04 +00004219 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004220 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004221 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004222 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004223 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004224
Douglas Gregor715e4612011-01-14 22:40:04 +00004225 TypeLocBuilder TLB;
4226 TypeLoc NewTL = OldDI->getTypeLoc();
4227 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004228
4229 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004230 OldExpansionTL.getPatternLoc());
4231 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004232 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004233
4234 Result = RebuildPackExpansionType(Result,
4235 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004236 OldExpansionTL.getEllipsisLoc(),
4237 NumExpansions);
4238 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004239 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004240
Douglas Gregor715e4612011-01-14 22:40:04 +00004241 PackExpansionTypeLoc NewExpansionTL
4242 = TLB.push<PackExpansionTypeLoc>(Result);
4243 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4244 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4245 } else
4246 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004247 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004248 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004249
John McCall8fb0d9d2011-05-01 22:35:37 +00004250 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004251 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004252
4253 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4254 OldParm->getDeclContext(),
4255 OldParm->getInnerLocStart(),
4256 OldParm->getLocation(),
4257 OldParm->getIdentifier(),
4258 NewDI->getType(),
4259 NewDI,
4260 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004261 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004262 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4263 OldParm->getFunctionScopeIndex() + indexAdjustment);
4264 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004265}
4266
4267template<typename Derived>
4268bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004269 TransformFunctionTypeParams(SourceLocation Loc,
4270 ParmVarDecl **Params, unsigned NumParams,
4271 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004272 SmallVectorImpl<QualType> &OutParamTypes,
4273 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004274 int indexAdjustment = 0;
4275
Douglas Gregordd472162011-01-07 00:20:55 +00004276 for (unsigned i = 0; i != NumParams; ++i) {
4277 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004278 assert(OldParm->getFunctionScopeIndex() == i);
4279
David Blaikie05785d12013-02-20 22:23:23 +00004280 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004281 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004282 if (OldParm->isParameterPack()) {
4283 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004284 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004285
Douglas Gregor5499af42011-01-05 23:12:31 +00004286 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004287 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004288 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004289 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4290 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004291 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4292
Douglas Gregor5499af42011-01-05 23:12:31 +00004293 // Determine whether we should expand the parameter packs.
4294 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004295 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004296 Optional<unsigned> OrigNumExpansions =
4297 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004298 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004299 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4300 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004301 Unexpanded,
4302 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004303 RetainExpansion,
4304 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004305 return true;
4306 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004307
Douglas Gregor5499af42011-01-05 23:12:31 +00004308 if (ShouldExpand) {
4309 // Expand the function parameter pack into multiple, separate
4310 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004311 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004312 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004313 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004314 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004315 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004316 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004317 OrigNumExpansions,
4318 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004319 if (!NewParm)
4320 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004321
Douglas Gregordd472162011-01-07 00:20:55 +00004322 OutParamTypes.push_back(NewParm->getType());
4323 if (PVars)
4324 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004325 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004326
4327 // If we're supposed to retain a pack expansion, do so by temporarily
4328 // forgetting the partially-substituted parameter pack.
4329 if (RetainExpansion) {
4330 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004331 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004332 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004333 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004334 OrigNumExpansions,
4335 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004336 if (!NewParm)
4337 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004338
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004339 OutParamTypes.push_back(NewParm->getType());
4340 if (PVars)
4341 PVars->push_back(NewParm);
4342 }
4343
John McCall8fb0d9d2011-05-01 22:35:37 +00004344 // The next parameter should have the same adjustment as the
4345 // last thing we pushed, but we post-incremented indexAdjustment
4346 // on every push. Also, if we push nothing, the adjustment should
4347 // go down by one.
4348 indexAdjustment--;
4349
Douglas Gregor5499af42011-01-05 23:12:31 +00004350 // We're done with the pack expansion.
4351 continue;
4352 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004353
4354 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004355 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004356 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4357 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004358 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004359 NumExpansions,
4360 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004361 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004362 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004363 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004364 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004365
John McCall58f10c32010-03-11 09:03:00 +00004366 if (!NewParm)
4367 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004368
Douglas Gregordd472162011-01-07 00:20:55 +00004369 OutParamTypes.push_back(NewParm->getType());
4370 if (PVars)
4371 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004372 continue;
4373 }
John McCall58f10c32010-03-11 09:03:00 +00004374
4375 // Deal with the possibility that we don't have a parameter
4376 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004377 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004378 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004379 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004380 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004381 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004382 = dyn_cast<PackExpansionType>(OldType)) {
4383 // We have a function parameter pack that may need to be expanded.
4384 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004385 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004386 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004387
Douglas Gregor5499af42011-01-05 23:12:31 +00004388 // Determine whether we should expand the parameter packs.
4389 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004390 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004391 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004392 Unexpanded,
4393 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004394 RetainExpansion,
4395 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004396 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004397 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004398
Douglas Gregor5499af42011-01-05 23:12:31 +00004399 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004400 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004401 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004402 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004403 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4404 QualType NewType = getDerived().TransformType(Pattern);
4405 if (NewType.isNull())
4406 return true;
John McCall58f10c32010-03-11 09:03:00 +00004407
Douglas Gregordd472162011-01-07 00:20:55 +00004408 OutParamTypes.push_back(NewType);
4409 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004410 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004411 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004412
Douglas Gregor5499af42011-01-05 23:12:31 +00004413 // We're done with the pack expansion.
4414 continue;
4415 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004416
Douglas Gregor48d24112011-01-10 20:53:55 +00004417 // If we're supposed to retain a pack expansion, do so by temporarily
4418 // forgetting the partially-substituted parameter pack.
4419 if (RetainExpansion) {
4420 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4421 QualType NewType = getDerived().TransformType(Pattern);
4422 if (NewType.isNull())
4423 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004424
Douglas Gregor48d24112011-01-10 20:53:55 +00004425 OutParamTypes.push_back(NewType);
4426 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004427 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004428 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004429
Chad Rosier1dcde962012-08-08 18:46:20 +00004430 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004431 // expansion.
4432 OldType = Expansion->getPattern();
4433 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004434 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4435 NewType = getDerived().TransformType(OldType);
4436 } else {
4437 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004438 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004439
Douglas Gregor5499af42011-01-05 23:12:31 +00004440 if (NewType.isNull())
4441 return true;
4442
4443 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004444 NewType = getSema().Context.getPackExpansionType(NewType,
4445 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004446
Douglas Gregordd472162011-01-07 00:20:55 +00004447 OutParamTypes.push_back(NewType);
4448 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004449 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004450 }
4451
John McCall8fb0d9d2011-05-01 22:35:37 +00004452#ifndef NDEBUG
4453 if (PVars) {
4454 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4455 if (ParmVarDecl *parm = (*PVars)[i])
4456 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004457 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004458#endif
4459
4460 return false;
4461}
John McCall58f10c32010-03-11 09:03:00 +00004462
4463template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004464QualType
John McCall550e0c22009-10-21 00:40:46 +00004465TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004466 FunctionProtoTypeLoc TL) {
Craig Topperc3ec1492014-05-26 06:22:03 +00004467 return getDerived().TransformFunctionProtoType(TLB, TL, nullptr, 0);
Douglas Gregor3024f072012-04-16 07:05:22 +00004468}
4469
4470template<typename Derived>
4471QualType
4472TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4473 FunctionProtoTypeLoc TL,
4474 CXXRecordDecl *ThisContext,
4475 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004476 // Transform the parameters and return type.
4477 //
Richard Smithf623c962012-04-17 00:58:00 +00004478 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004479 // When the function has a trailing return type, we instantiate the
4480 // parameters before the return type, since the return type can then refer
4481 // to the parameters themselves (via decltype, sizeof, etc.).
4482 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004483 SmallVector<QualType, 4> ParamTypes;
4484 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004485 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004486
Douglas Gregor7fb25412010-10-01 18:44:50 +00004487 QualType ResultType;
4488
Richard Smith1226c602012-08-14 22:51:13 +00004489 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004490 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004491 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004492 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004493 return QualType();
4494
Douglas Gregor3024f072012-04-16 07:05:22 +00004495 {
4496 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004497 // If a declaration declares a member function or member function
4498 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004499 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004500 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004501 // declarator.
4502 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004503
Alp Toker42a16a62014-01-25 23:51:36 +00004504 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004505 if (ResultType.isNull())
4506 return QualType();
4507 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004508 }
4509 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004510 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004511 if (ResultType.isNull())
4512 return QualType();
4513
Alp Toker9cacbab2014-01-20 20:26:09 +00004514 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004515 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004516 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004517 return QualType();
4518 }
4519
Richard Smithf623c962012-04-17 00:58:00 +00004520 // FIXME: Need to transform the exception-specification too.
4521
John McCall550e0c22009-10-21 00:40:46 +00004522 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004523 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004524 T->getNumParams() != ParamTypes.size() ||
4525 !std::equal(T->param_type_begin(), T->param_type_end(),
4526 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004527 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004528 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004529 if (Result.isNull())
4530 return QualType();
4531 }
Mike Stump11289f42009-09-09 15:08:12 +00004532
John McCall550e0c22009-10-21 00:40:46 +00004533 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004534 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004535 NewTL.setLParenLoc(TL.getLParenLoc());
4536 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004537 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004538 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4539 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004540
4541 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004542}
Mike Stump11289f42009-09-09 15:08:12 +00004543
Douglas Gregord6ff3322009-08-04 16:50:30 +00004544template<typename Derived>
4545QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004546 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004547 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004548 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004549 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004550 if (ResultType.isNull())
4551 return QualType();
4552
4553 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004554 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004555 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4556
4557 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004558 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004559 NewTL.setLParenLoc(TL.getLParenLoc());
4560 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004561 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004562
4563 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004564}
Mike Stump11289f42009-09-09 15:08:12 +00004565
John McCallb96ec562009-12-04 22:46:56 +00004566template<typename Derived> QualType
4567TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004568 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004569 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004570 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004571 if (!D)
4572 return QualType();
4573
4574 QualType Result = TL.getType();
4575 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4576 Result = getDerived().RebuildUnresolvedUsingType(D);
4577 if (Result.isNull())
4578 return QualType();
4579 }
4580
4581 // We might get an arbitrary type spec type back. We should at
4582 // least always get a type spec type, though.
4583 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4584 NewTL.setNameLoc(TL.getNameLoc());
4585
4586 return Result;
4587}
4588
Douglas Gregord6ff3322009-08-04 16:50:30 +00004589template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004590QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004591 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004592 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004593 TypedefNameDecl *Typedef
4594 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4595 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004596 if (!Typedef)
4597 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004598
John McCall550e0c22009-10-21 00:40:46 +00004599 QualType Result = TL.getType();
4600 if (getDerived().AlwaysRebuild() ||
4601 Typedef != T->getDecl()) {
4602 Result = getDerived().RebuildTypedefType(Typedef);
4603 if (Result.isNull())
4604 return QualType();
4605 }
Mike Stump11289f42009-09-09 15:08:12 +00004606
John McCall550e0c22009-10-21 00:40:46 +00004607 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4608 NewTL.setNameLoc(TL.getNameLoc());
4609
4610 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004611}
Mike Stump11289f42009-09-09 15:08:12 +00004612
Douglas Gregord6ff3322009-08-04 16:50:30 +00004613template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004614QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004615 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004616 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004617 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4618 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004619
John McCalldadc5752010-08-24 06:29:42 +00004620 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004621 if (E.isInvalid())
4622 return QualType();
4623
Eli Friedmane4f22df2012-02-29 04:03:55 +00004624 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4625 if (E.isInvalid())
4626 return QualType();
4627
John McCall550e0c22009-10-21 00:40:46 +00004628 QualType Result = TL.getType();
4629 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004630 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004631 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004632 if (Result.isNull())
4633 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004634 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004635 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004636
John McCall550e0c22009-10-21 00:40:46 +00004637 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004638 NewTL.setTypeofLoc(TL.getTypeofLoc());
4639 NewTL.setLParenLoc(TL.getLParenLoc());
4640 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004641
4642 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004643}
Mike Stump11289f42009-09-09 15:08:12 +00004644
4645template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004646QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004647 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004648 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4649 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4650 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004651 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004652
John McCall550e0c22009-10-21 00:40:46 +00004653 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004654 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4655 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004656 if (Result.isNull())
4657 return QualType();
4658 }
Mike Stump11289f42009-09-09 15:08:12 +00004659
John McCall550e0c22009-10-21 00:40:46 +00004660 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004661 NewTL.setTypeofLoc(TL.getTypeofLoc());
4662 NewTL.setLParenLoc(TL.getLParenLoc());
4663 NewTL.setRParenLoc(TL.getRParenLoc());
4664 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004665
4666 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004667}
Mike Stump11289f42009-09-09 15:08:12 +00004668
4669template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004670QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004671 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004672 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004673
Douglas Gregore922c772009-08-04 22:27:00 +00004674 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004675 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4676 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004677
John McCalldadc5752010-08-24 06:29:42 +00004678 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004679 if (E.isInvalid())
4680 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004681
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004682 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004683 if (E.isInvalid())
4684 return QualType();
4685
John McCall550e0c22009-10-21 00:40:46 +00004686 QualType Result = TL.getType();
4687 if (getDerived().AlwaysRebuild() ||
4688 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004689 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004690 if (Result.isNull())
4691 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004692 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004693 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004694
John McCall550e0c22009-10-21 00:40:46 +00004695 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4696 NewTL.setNameLoc(TL.getNameLoc());
4697
4698 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004699}
4700
4701template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004702QualType TreeTransform<Derived>::TransformUnaryTransformType(
4703 TypeLocBuilder &TLB,
4704 UnaryTransformTypeLoc TL) {
4705 QualType Result = TL.getType();
4706 if (Result->isDependentType()) {
4707 const UnaryTransformType *T = TL.getTypePtr();
4708 QualType NewBase =
4709 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4710 Result = getDerived().RebuildUnaryTransformType(NewBase,
4711 T->getUTTKind(),
4712 TL.getKWLoc());
4713 if (Result.isNull())
4714 return QualType();
4715 }
4716
4717 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4718 NewTL.setKWLoc(TL.getKWLoc());
4719 NewTL.setParensRange(TL.getParensRange());
4720 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4721 return Result;
4722}
4723
4724template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004725QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4726 AutoTypeLoc TL) {
4727 const AutoType *T = TL.getTypePtr();
4728 QualType OldDeduced = T->getDeducedType();
4729 QualType NewDeduced;
4730 if (!OldDeduced.isNull()) {
4731 NewDeduced = getDerived().TransformType(OldDeduced);
4732 if (NewDeduced.isNull())
4733 return QualType();
4734 }
4735
4736 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004737 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4738 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004739 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004740 if (Result.isNull())
4741 return QualType();
4742 }
4743
4744 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4745 NewTL.setNameLoc(TL.getNameLoc());
4746
4747 return Result;
4748}
4749
4750template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004751QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004752 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004753 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004754 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004755 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4756 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004757 if (!Record)
4758 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004759
John McCall550e0c22009-10-21 00:40:46 +00004760 QualType Result = TL.getType();
4761 if (getDerived().AlwaysRebuild() ||
4762 Record != T->getDecl()) {
4763 Result = getDerived().RebuildRecordType(Record);
4764 if (Result.isNull())
4765 return QualType();
4766 }
Mike Stump11289f42009-09-09 15:08:12 +00004767
John McCall550e0c22009-10-21 00:40:46 +00004768 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4769 NewTL.setNameLoc(TL.getNameLoc());
4770
4771 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004772}
Mike Stump11289f42009-09-09 15:08:12 +00004773
4774template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004775QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004776 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004777 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004778 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004779 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4780 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004781 if (!Enum)
4782 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004783
John McCall550e0c22009-10-21 00:40:46 +00004784 QualType Result = TL.getType();
4785 if (getDerived().AlwaysRebuild() ||
4786 Enum != T->getDecl()) {
4787 Result = getDerived().RebuildEnumType(Enum);
4788 if (Result.isNull())
4789 return QualType();
4790 }
Mike Stump11289f42009-09-09 15:08:12 +00004791
John McCall550e0c22009-10-21 00:40:46 +00004792 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4793 NewTL.setNameLoc(TL.getNameLoc());
4794
4795 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004796}
John McCallfcc33b02009-09-05 00:15:47 +00004797
John McCalle78aac42010-03-10 03:28:59 +00004798template<typename Derived>
4799QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4800 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004801 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004802 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4803 TL.getTypePtr()->getDecl());
4804 if (!D) return QualType();
4805
4806 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4807 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4808 return T;
4809}
4810
Douglas Gregord6ff3322009-08-04 16:50:30 +00004811template<typename Derived>
4812QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004813 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004814 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004815 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004816}
4817
Mike Stump11289f42009-09-09 15:08:12 +00004818template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004819QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004820 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004821 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004822 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004823
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004824 // Substitute into the replacement type, which itself might involve something
4825 // that needs to be transformed. This only tends to occur with default
4826 // template arguments of template template parameters.
4827 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4828 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4829 if (Replacement.isNull())
4830 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004831
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004832 // Always canonicalize the replacement type.
4833 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4834 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004835 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004836 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004837
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004838 // Propagate type-source information.
4839 SubstTemplateTypeParmTypeLoc NewTL
4840 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4841 NewTL.setNameLoc(TL.getNameLoc());
4842 return Result;
4843
John McCallcebee162009-10-18 09:09:24 +00004844}
4845
4846template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004847QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4848 TypeLocBuilder &TLB,
4849 SubstTemplateTypeParmPackTypeLoc TL) {
4850 return TransformTypeSpecType(TLB, TL);
4851}
4852
4853template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004854QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004855 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004856 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004857 const TemplateSpecializationType *T = TL.getTypePtr();
4858
Douglas Gregordf846d12011-03-02 18:46:51 +00004859 // The nested-name-specifier never matters in a TemplateSpecializationType,
4860 // because we can't have a dependent nested-name-specifier anyway.
4861 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004862 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004863 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4864 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004865 if (Template.isNull())
4866 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004867
John McCall31f82722010-11-12 08:19:04 +00004868 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4869}
4870
Eli Friedman0dfb8892011-10-06 23:00:33 +00004871template<typename Derived>
4872QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4873 AtomicTypeLoc TL) {
4874 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4875 if (ValueType.isNull())
4876 return QualType();
4877
4878 QualType Result = TL.getType();
4879 if (getDerived().AlwaysRebuild() ||
4880 ValueType != TL.getValueLoc().getType()) {
4881 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4882 if (Result.isNull())
4883 return QualType();
4884 }
4885
4886 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4887 NewTL.setKWLoc(TL.getKWLoc());
4888 NewTL.setLParenLoc(TL.getLParenLoc());
4889 NewTL.setRParenLoc(TL.getRParenLoc());
4890
4891 return Result;
4892}
4893
Chad Rosier1dcde962012-08-08 18:46:20 +00004894 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004895 /// container that provides a \c getArgLoc() member function.
4896 ///
4897 /// This iterator is intended to be used with the iterator form of
4898 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4899 template<typename ArgLocContainer>
4900 class TemplateArgumentLocContainerIterator {
4901 ArgLocContainer *Container;
4902 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004903
Douglas Gregorfe921a72010-12-20 23:36:19 +00004904 public:
4905 typedef TemplateArgumentLoc value_type;
4906 typedef TemplateArgumentLoc reference;
4907 typedef int difference_type;
4908 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004909
Douglas Gregorfe921a72010-12-20 23:36:19 +00004910 class pointer {
4911 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004912
Douglas Gregorfe921a72010-12-20 23:36:19 +00004913 public:
4914 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004915
Douglas Gregorfe921a72010-12-20 23:36:19 +00004916 const TemplateArgumentLoc *operator->() const {
4917 return &Arg;
4918 }
4919 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004920
4921
Douglas Gregorfe921a72010-12-20 23:36:19 +00004922 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004923
Douglas Gregorfe921a72010-12-20 23:36:19 +00004924 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4925 unsigned Index)
4926 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004927
Douglas Gregorfe921a72010-12-20 23:36:19 +00004928 TemplateArgumentLocContainerIterator &operator++() {
4929 ++Index;
4930 return *this;
4931 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004932
Douglas Gregorfe921a72010-12-20 23:36:19 +00004933 TemplateArgumentLocContainerIterator operator++(int) {
4934 TemplateArgumentLocContainerIterator Old(*this);
4935 ++(*this);
4936 return Old;
4937 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004938
Douglas Gregorfe921a72010-12-20 23:36:19 +00004939 TemplateArgumentLoc operator*() const {
4940 return Container->getArgLoc(Index);
4941 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004942
Douglas Gregorfe921a72010-12-20 23:36:19 +00004943 pointer operator->() const {
4944 return pointer(Container->getArgLoc(Index));
4945 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004946
Douglas Gregorfe921a72010-12-20 23:36:19 +00004947 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004948 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004949 return X.Container == Y.Container && X.Index == Y.Index;
4950 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004951
Douglas Gregorfe921a72010-12-20 23:36:19 +00004952 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004953 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004954 return !(X == Y);
4955 }
4956 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004957
4958
John McCall31f82722010-11-12 08:19:04 +00004959template <typename Derived>
4960QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4961 TypeLocBuilder &TLB,
4962 TemplateSpecializationTypeLoc TL,
4963 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004964 TemplateArgumentListInfo NewTemplateArgs;
4965 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4966 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004967 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4968 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004969 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004970 ArgIterator(TL, TL.getNumArgs()),
4971 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004972 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004973
John McCall0ad16662009-10-29 08:12:44 +00004974 // FIXME: maybe don't rebuild if all the template arguments are the same.
4975
4976 QualType Result =
4977 getDerived().RebuildTemplateSpecializationType(Template,
4978 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004979 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004980
4981 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004982 // Specializations of template template parameters are represented as
4983 // TemplateSpecializationTypes, and substitution of type alias templates
4984 // within a dependent context can transform them into
4985 // DependentTemplateSpecializationTypes.
4986 if (isa<DependentTemplateSpecializationType>(Result)) {
4987 DependentTemplateSpecializationTypeLoc NewTL
4988 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004989 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004990 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004991 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004992 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +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 return Result;
4998 }
4999
John McCall0ad16662009-10-29 08:12:44 +00005000 TemplateSpecializationTypeLoc NewTL
5001 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005002 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005003 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5004 NewTL.setLAngleLoc(TL.getLAngleLoc());
5005 NewTL.setRAngleLoc(TL.getRAngleLoc());
5006 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5007 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005008 }
Mike Stump11289f42009-09-09 15:08:12 +00005009
John McCall0ad16662009-10-29 08:12:44 +00005010 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005011}
Mike Stump11289f42009-09-09 15:08:12 +00005012
Douglas Gregor5a064722011-02-28 17:23:35 +00005013template <typename Derived>
5014QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5015 TypeLocBuilder &TLB,
5016 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005017 TemplateName Template,
5018 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005019 TemplateArgumentListInfo NewTemplateArgs;
5020 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5021 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5022 typedef TemplateArgumentLocContainerIterator<
5023 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005024 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005025 ArgIterator(TL, TL.getNumArgs()),
5026 NewTemplateArgs))
5027 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005028
Douglas Gregor5a064722011-02-28 17:23:35 +00005029 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005030
Douglas Gregor5a064722011-02-28 17:23:35 +00005031 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5032 QualType Result
5033 = getSema().Context.getDependentTemplateSpecializationType(
5034 TL.getTypePtr()->getKeyword(),
5035 DTN->getQualifier(),
5036 DTN->getIdentifier(),
5037 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005038
Douglas Gregor5a064722011-02-28 17:23:35 +00005039 DependentTemplateSpecializationTypeLoc NewTL
5040 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005041 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005042 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005043 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005044 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005045 NewTL.setLAngleLoc(TL.getLAngleLoc());
5046 NewTL.setRAngleLoc(TL.getRAngleLoc());
5047 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5048 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5049 return Result;
5050 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005051
5052 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005053 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005054 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005055 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005056
Douglas Gregor5a064722011-02-28 17:23:35 +00005057 if (!Result.isNull()) {
5058 /// FIXME: Wrap this in an elaborated-type-specifier?
5059 TemplateSpecializationTypeLoc NewTL
5060 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005061 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005062 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005063 NewTL.setLAngleLoc(TL.getLAngleLoc());
5064 NewTL.setRAngleLoc(TL.getRAngleLoc());
5065 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5066 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5067 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005068
Douglas Gregor5a064722011-02-28 17:23:35 +00005069 return Result;
5070}
5071
Mike Stump11289f42009-09-09 15:08:12 +00005072template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005073QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005074TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005075 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005076 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005077
Douglas Gregor844cb502011-03-01 18:12:44 +00005078 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005079 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005080 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005081 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005082 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5083 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005084 return QualType();
5085 }
Mike Stump11289f42009-09-09 15:08:12 +00005086
John McCall31f82722010-11-12 08:19:04 +00005087 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5088 if (NamedT.isNull())
5089 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005090
Richard Smith3f1b5d02011-05-05 21:57:07 +00005091 // C++0x [dcl.type.elab]p2:
5092 // If the identifier resolves to a typedef-name or the simple-template-id
5093 // resolves to an alias template specialization, the
5094 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005095 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5096 if (const TemplateSpecializationType *TST =
5097 NamedT->getAs<TemplateSpecializationType>()) {
5098 TemplateName Template = TST->getTemplateName();
5099 if (TypeAliasTemplateDecl *TAT =
5100 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5101 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5102 diag::err_tag_reference_non_tag) << 4;
5103 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5104 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005105 }
5106 }
5107
John McCall550e0c22009-10-21 00:40:46 +00005108 QualType Result = TL.getType();
5109 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005110 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005111 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005112 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005113 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005114 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005115 if (Result.isNull())
5116 return QualType();
5117 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005118
Abramo Bagnara6150c882010-05-11 21:36:43 +00005119 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005120 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005121 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005122 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005123}
Mike Stump11289f42009-09-09 15:08:12 +00005124
5125template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005126QualType TreeTransform<Derived>::TransformAttributedType(
5127 TypeLocBuilder &TLB,
5128 AttributedTypeLoc TL) {
5129 const AttributedType *oldType = TL.getTypePtr();
5130 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5131 if (modifiedType.isNull())
5132 return QualType();
5133
5134 QualType result = TL.getType();
5135
5136 // FIXME: dependent operand expressions?
5137 if (getDerived().AlwaysRebuild() ||
5138 modifiedType != oldType->getModifiedType()) {
5139 // TODO: this is really lame; we should really be rebuilding the
5140 // equivalent type from first principles.
5141 QualType equivalentType
5142 = getDerived().TransformType(oldType->getEquivalentType());
5143 if (equivalentType.isNull())
5144 return QualType();
5145 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5146 modifiedType,
5147 equivalentType);
5148 }
5149
5150 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5151 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5152 if (TL.hasAttrOperand())
5153 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5154 if (TL.hasAttrExprOperand())
5155 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5156 else if (TL.hasAttrEnumOperand())
5157 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5158
5159 return result;
5160}
5161
5162template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005163QualType
5164TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5165 ParenTypeLoc TL) {
5166 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5167 if (Inner.isNull())
5168 return QualType();
5169
5170 QualType Result = TL.getType();
5171 if (getDerived().AlwaysRebuild() ||
5172 Inner != TL.getInnerLoc().getType()) {
5173 Result = getDerived().RebuildParenType(Inner);
5174 if (Result.isNull())
5175 return QualType();
5176 }
5177
5178 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5179 NewTL.setLParenLoc(TL.getLParenLoc());
5180 NewTL.setRParenLoc(TL.getRParenLoc());
5181 return Result;
5182}
5183
5184template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005185QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005186 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005187 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005188
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005189 NestedNameSpecifierLoc QualifierLoc
5190 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5191 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005192 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005193
John McCallc392f372010-06-11 00:33:02 +00005194 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005195 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005196 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005197 QualifierLoc,
5198 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005199 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005200 if (Result.isNull())
5201 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005202
Abramo Bagnarad7548482010-05-19 21:37:53 +00005203 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5204 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005205 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5206
Abramo Bagnarad7548482010-05-19 21:37:53 +00005207 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005208 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005209 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005210 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005211 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005212 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005213 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005214 NewTL.setNameLoc(TL.getNameLoc());
5215 }
John McCall550e0c22009-10-21 00:40:46 +00005216 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005217}
Mike Stump11289f42009-09-09 15:08:12 +00005218
Douglas Gregord6ff3322009-08-04 16:50:30 +00005219template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005220QualType TreeTransform<Derived>::
5221 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005222 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005223 NestedNameSpecifierLoc QualifierLoc;
5224 if (TL.getQualifierLoc()) {
5225 QualifierLoc
5226 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5227 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005228 return QualType();
5229 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005230
John McCall31f82722010-11-12 08:19:04 +00005231 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005232 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005233}
5234
5235template<typename Derived>
5236QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005237TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5238 DependentTemplateSpecializationTypeLoc TL,
5239 NestedNameSpecifierLoc QualifierLoc) {
5240 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005241
Douglas Gregora7a795b2011-03-01 20:11:18 +00005242 TemplateArgumentListInfo NewTemplateArgs;
5243 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5244 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005245
Douglas Gregora7a795b2011-03-01 20:11:18 +00005246 typedef TemplateArgumentLocContainerIterator<
5247 DependentTemplateSpecializationTypeLoc> ArgIterator;
5248 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5249 ArgIterator(TL, TL.getNumArgs()),
5250 NewTemplateArgs))
5251 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005252
Douglas Gregora7a795b2011-03-01 20:11:18 +00005253 QualType Result
5254 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5255 QualifierLoc,
5256 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005257 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005258 NewTemplateArgs);
5259 if (Result.isNull())
5260 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005261
Douglas Gregora7a795b2011-03-01 20:11:18 +00005262 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5263 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005264
Douglas Gregora7a795b2011-03-01 20:11:18 +00005265 // Copy information relevant to the template specialization.
5266 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005267 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005268 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005269 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005270 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5271 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005272 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005273 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005274
Douglas Gregora7a795b2011-03-01 20:11:18 +00005275 // Copy information relevant to the elaborated type.
5276 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005277 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005278 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005279 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5280 DependentTemplateSpecializationTypeLoc SpecTL
5281 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005282 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005283 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005284 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005285 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005286 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5287 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005288 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005289 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005290 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005291 TemplateSpecializationTypeLoc SpecTL
5292 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005293 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005294 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005295 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5296 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005297 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005298 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005299 }
5300 return Result;
5301}
5302
5303template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005304QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5305 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005306 QualType Pattern
5307 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005308 if (Pattern.isNull())
5309 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005310
5311 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005312 if (getDerived().AlwaysRebuild() ||
5313 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005314 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005315 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005316 TL.getEllipsisLoc(),
5317 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005318 if (Result.isNull())
5319 return QualType();
5320 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005321
Douglas Gregor822d0302011-01-12 17:07:58 +00005322 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5323 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5324 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005325}
5326
5327template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005328QualType
5329TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005330 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005331 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005332 TLB.pushFullCopy(TL);
5333 return TL.getType();
5334}
5335
5336template<typename Derived>
5337QualType
5338TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005339 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005340 // ObjCObjectType is never dependent.
5341 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005342 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005343}
Mike Stump11289f42009-09-09 15:08:12 +00005344
5345template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005346QualType
5347TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005348 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005349 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005350 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005351 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005352}
5353
Douglas Gregord6ff3322009-08-04 16:50:30 +00005354//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005355// Statement transformation
5356//===----------------------------------------------------------------------===//
5357template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005358StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005359TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005360 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005361}
5362
5363template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005364StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005365TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5366 return getDerived().TransformCompoundStmt(S, false);
5367}
5368
5369template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005370StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005371TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005372 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005373 Sema::CompoundScopeRAII CompoundScope(getSema());
5374
John McCall1ababa62010-08-27 19:56:05 +00005375 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005376 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005377 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005378 for (auto *B : S->body()) {
5379 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005380 if (Result.isInvalid()) {
5381 // Immediately fail if this was a DeclStmt, since it's very
5382 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005383 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005384 return StmtError();
5385
5386 // Otherwise, just keep processing substatements and fail later.
5387 SubStmtInvalid = true;
5388 continue;
5389 }
Mike Stump11289f42009-09-09 15:08:12 +00005390
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005391 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005392 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005393 }
Mike Stump11289f42009-09-09 15:08:12 +00005394
John McCall1ababa62010-08-27 19:56:05 +00005395 if (SubStmtInvalid)
5396 return StmtError();
5397
Douglas Gregorebe10102009-08-20 07:17:43 +00005398 if (!getDerived().AlwaysRebuild() &&
5399 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005400 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005401
5402 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005403 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005404 S->getRBracLoc(),
5405 IsStmtExpr);
5406}
Mike Stump11289f42009-09-09 15:08:12 +00005407
Douglas Gregorebe10102009-08-20 07:17:43 +00005408template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005409StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005410TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005411 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005412 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005413 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5414 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005415
Eli Friedman06577382009-11-19 03:14:00 +00005416 // Transform the left-hand case value.
5417 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005418 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005419 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005420 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005421
Eli Friedman06577382009-11-19 03:14:00 +00005422 // Transform the right-hand case value (for the GNU case-range extension).
5423 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005424 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005425 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005426 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005427 }
Mike Stump11289f42009-09-09 15:08:12 +00005428
Douglas Gregorebe10102009-08-20 07:17:43 +00005429 // Build the case statement.
5430 // Case statements are always rebuilt so that they will attached to their
5431 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005432 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005433 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005434 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005435 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005436 S->getColonLoc());
5437 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005438 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005439
Douglas Gregorebe10102009-08-20 07:17:43 +00005440 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005441 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005442 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005443 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005444
Douglas Gregorebe10102009-08-20 07:17:43 +00005445 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005446 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005447}
5448
5449template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005450StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005451TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005452 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005453 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005454 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005455 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005456
Douglas Gregorebe10102009-08-20 07:17:43 +00005457 // Default statements are always rebuilt
5458 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005459 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005460}
Mike Stump11289f42009-09-09 15:08:12 +00005461
Douglas Gregorebe10102009-08-20 07:17:43 +00005462template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005463StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005464TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005465 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005466 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005467 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005468
Chris Lattnercab02a62011-02-17 20:34:02 +00005469 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5470 S->getDecl());
5471 if (!LD)
5472 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005473
5474
Douglas Gregorebe10102009-08-20 07:17:43 +00005475 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005476 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005477 cast<LabelDecl>(LD), SourceLocation(),
5478 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005479}
Mike Stump11289f42009-09-09 15:08:12 +00005480
Douglas Gregorebe10102009-08-20 07:17:43 +00005481template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005482StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005483TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5484 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5485 if (SubStmt.isInvalid())
5486 return StmtError();
5487
5488 // TODO: transform attributes
5489 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5490 return S;
5491
5492 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5493 S->getAttrs(),
5494 SubStmt.get());
5495}
5496
5497template<typename Derived>
5498StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005499TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005500 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005501 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005502 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005503 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005504 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005505 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005506 getDerived().TransformDefinition(
5507 S->getConditionVariable()->getLocation(),
5508 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005509 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005510 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005511 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005512 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005513
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005514 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005515 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005516
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005517 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005518 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005519 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005520 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005521 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005522 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005523
John McCallb268a282010-08-23 23:25:46 +00005524 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005525 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005526 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005527
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005528 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005529 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005530 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005531
Douglas Gregorebe10102009-08-20 07:17:43 +00005532 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005533 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005534 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005535 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005536
Douglas Gregorebe10102009-08-20 07:17:43 +00005537 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005538 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005539 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005540 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005541
Douglas Gregorebe10102009-08-20 07:17:43 +00005542 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005543 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005544 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005545 Then.get() == S->getThen() &&
5546 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005547 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005548
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005549 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005550 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005551 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005552}
5553
5554template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005555StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005556TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005557 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005558 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005559 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00005560 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005561 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005562 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005563 getDerived().TransformDefinition(
5564 S->getConditionVariable()->getLocation(),
5565 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005566 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005567 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005568 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005569 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005570
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005571 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005572 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005573 }
Mike Stump11289f42009-09-09 15:08:12 +00005574
Douglas Gregorebe10102009-08-20 07:17:43 +00005575 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005576 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005577 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005578 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005579 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005580 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005581
Douglas Gregorebe10102009-08-20 07:17:43 +00005582 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005583 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005584 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005585 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005586
Douglas Gregorebe10102009-08-20 07:17:43 +00005587 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005588 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5589 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005590}
Mike Stump11289f42009-09-09 15:08:12 +00005591
Douglas Gregorebe10102009-08-20 07:17:43 +00005592template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005593StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005594TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005595 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005596 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005597 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00005598 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005599 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005600 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005601 getDerived().TransformDefinition(
5602 S->getConditionVariable()->getLocation(),
5603 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005604 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005605 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005606 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005607 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005608
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005609 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005610 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005611
5612 if (S->getCond()) {
5613 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005614 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5615 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005616 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005617 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005618 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005619 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005620 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005621 }
Mike Stump11289f42009-09-09 15:08:12 +00005622
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005623 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005624 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005625 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005626
Douglas Gregorebe10102009-08-20 07:17:43 +00005627 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005628 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005629 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005630 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005631
Douglas Gregorebe10102009-08-20 07:17:43 +00005632 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005633 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005634 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005635 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005636 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005637
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005638 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005639 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005640}
Mike Stump11289f42009-09-09 15:08:12 +00005641
Douglas Gregorebe10102009-08-20 07:17:43 +00005642template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005643StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005644TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
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 Gregorff73a9e2010-05-08 22:20:28 +00005650 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005651 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005652 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005653 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005654
Douglas Gregorebe10102009-08-20 07:17:43 +00005655 if (!getDerived().AlwaysRebuild() &&
5656 Cond.get() == S->getCond() &&
5657 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005658 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005659
John McCallb268a282010-08-23 23:25:46 +00005660 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5661 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005662 S->getRParenLoc());
5663}
Mike Stump11289f42009-09-09 15:08:12 +00005664
Douglas Gregorebe10102009-08-20 07:17:43 +00005665template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005666StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005667TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005668 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005669 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005670 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005671 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005672
Douglas Gregorebe10102009-08-20 07:17:43 +00005673 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005674 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005675 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005676 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005677 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005678 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005679 getDerived().TransformDefinition(
5680 S->getConditionVariable()->getLocation(),
5681 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005682 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005683 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005684 } else {
5685 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005686
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005687 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005688 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005689
5690 if (S->getCond()) {
5691 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00005692 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
5693 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005694 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005695 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005696 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005697
John McCallb268a282010-08-23 23:25:46 +00005698 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005699 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005700 }
Mike Stump11289f42009-09-09 15:08:12 +00005701
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005702 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005703 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005704 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005705
Douglas Gregorebe10102009-08-20 07:17:43 +00005706 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005707 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005708 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005709 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005710
Richard Smith945f8d32013-01-14 22:39:08 +00005711 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005712 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005713 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005714
Douglas Gregorebe10102009-08-20 07:17:43 +00005715 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005716 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005717 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005718 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005719
Douglas Gregorebe10102009-08-20 07:17:43 +00005720 if (!getDerived().AlwaysRebuild() &&
5721 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005722 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005723 Inc.get() == S->getInc() &&
5724 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005725 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005726
Douglas Gregorebe10102009-08-20 07:17:43 +00005727 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005728 Init.get(), FullCond, ConditionVar,
5729 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005730}
5731
5732template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005733StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005734TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005735 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5736 S->getLabel());
5737 if (!LD)
5738 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005739
Douglas Gregorebe10102009-08-20 07:17:43 +00005740 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005741 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005742 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005743}
5744
5745template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005746StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005747TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005748 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005749 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005750 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005751 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00005752
Douglas Gregorebe10102009-08-20 07:17:43 +00005753 if (!getDerived().AlwaysRebuild() &&
5754 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005755 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005756
5757 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005758 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005759}
5760
5761template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005762StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005763TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005764 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005765}
Mike Stump11289f42009-09-09 15:08:12 +00005766
Douglas Gregorebe10102009-08-20 07:17:43 +00005767template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005768StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005769TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005770 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005771}
Mike Stump11289f42009-09-09 15:08:12 +00005772
Douglas Gregorebe10102009-08-20 07:17:43 +00005773template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005774StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005775TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005776 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005777 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005778 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005779
Mike Stump11289f42009-09-09 15:08:12 +00005780 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005781 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005782 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005783}
Mike Stump11289f42009-09-09 15:08:12 +00005784
Douglas Gregorebe10102009-08-20 07:17:43 +00005785template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005786StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005787TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005788 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005789 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005790 for (auto *D : S->decls()) {
5791 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005792 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005793 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005794
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005795 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005796 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005797
Douglas Gregorebe10102009-08-20 07:17:43 +00005798 Decls.push_back(Transformed);
5799 }
Mike Stump11289f42009-09-09 15:08:12 +00005800
Douglas Gregorebe10102009-08-20 07:17:43 +00005801 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005802 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005803
Rafael Espindolaab417692013-07-09 12:05:01 +00005804 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005805}
Mike Stump11289f42009-09-09 15:08:12 +00005806
Douglas Gregorebe10102009-08-20 07:17:43 +00005807template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005808StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005809TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005810
Benjamin Kramerf0623432012-08-23 22:51:59 +00005811 SmallVector<Expr*, 8> Constraints;
5812 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005813 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005814
John McCalldadc5752010-08-24 06:29:42 +00005815 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005816 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005817
5818 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005819
Anders Carlssonaaeef072010-01-24 05:50:09 +00005820 // Go through the outputs.
5821 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005822 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005823
Anders Carlssonaaeef072010-01-24 05:50:09 +00005824 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005825 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005826
Anders Carlssonaaeef072010-01-24 05:50:09 +00005827 // Transform the output expr.
5828 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005829 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005830 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005831 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005832
Anders Carlssonaaeef072010-01-24 05:50:09 +00005833 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005834
John McCallb268a282010-08-23 23:25:46 +00005835 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005836 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005837
Anders Carlssonaaeef072010-01-24 05:50:09 +00005838 // Go through the inputs.
5839 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005840 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005841
Anders Carlssonaaeef072010-01-24 05:50:09 +00005842 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005843 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005844
Anders Carlssonaaeef072010-01-24 05:50:09 +00005845 // Transform the input expr.
5846 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005847 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005848 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005849 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005850
Anders Carlssonaaeef072010-01-24 05:50:09 +00005851 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005852
John McCallb268a282010-08-23 23:25:46 +00005853 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005854 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005855
Anders Carlssonaaeef072010-01-24 05:50:09 +00005856 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005857 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005858
5859 // Go through the clobbers.
5860 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005861 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005862
5863 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005864 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00005865 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5866 S->isVolatile(), S->getNumOutputs(),
5867 S->getNumInputs(), Names.data(),
5868 Constraints, Exprs, AsmString.get(),
5869 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005870}
5871
Chad Rosier32503022012-06-11 20:47:18 +00005872template<typename Derived>
5873StmtResult
5874TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005875 ArrayRef<Token> AsmToks =
5876 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005877
John McCallf413f5e2013-05-03 00:10:13 +00005878 bool HadError = false, HadChange = false;
5879
5880 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5881 SmallVector<Expr*, 8> TransformedExprs;
5882 TransformedExprs.reserve(SrcExprs.size());
5883 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5884 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5885 if (!Result.isUsable()) {
5886 HadError = true;
5887 } else {
5888 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005889 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00005890 }
5891 }
5892
5893 if (HadError) return StmtError();
5894 if (!HadChange && !getDerived().AlwaysRebuild())
5895 return Owned(S);
5896
Chad Rosierb6f46c12012-08-15 16:53:30 +00005897 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005898 AsmToks, S->getAsmString(),
5899 S->getNumOutputs(), S->getNumInputs(),
5900 S->getAllConstraints(), S->getClobbers(),
5901 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005902}
Douglas Gregorebe10102009-08-20 07:17:43 +00005903
5904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005905StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005906TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005907 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005908 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005909 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005910 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005911
Douglas Gregor96c79492010-04-23 22:50:49 +00005912 // Transform the @catch statements (if present).
5913 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005914 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005915 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005916 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005917 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005918 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005919 if (Catch.get() != S->getCatchStmt(I))
5920 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005921 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005922 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005923
Douglas Gregor306de2f2010-04-22 23:59:56 +00005924 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005925 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005926 if (S->getFinallyStmt()) {
5927 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5928 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005929 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005930 }
5931
5932 // If nothing changed, just retain this statement.
5933 if (!getDerived().AlwaysRebuild() &&
5934 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005935 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005936 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005937 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00005938
Douglas Gregor306de2f2010-04-22 23:59:56 +00005939 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005940 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005941 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005942}
Mike Stump11289f42009-09-09 15:08:12 +00005943
Douglas Gregorebe10102009-08-20 07:17:43 +00005944template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005945StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005946TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005947 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00005948 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005949 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005950 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005951 if (FromVar->getTypeSourceInfo()) {
5952 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5953 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005954 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005955 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005956
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005957 QualType T;
5958 if (TSInfo)
5959 T = TSInfo->getType();
5960 else {
5961 T = getDerived().TransformType(FromVar->getType());
5962 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005963 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005964 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005965
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005966 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5967 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005968 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005969 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005970
John McCalldadc5752010-08-24 06:29:42 +00005971 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005972 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005973 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005974
5975 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005976 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005977 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005978}
Mike Stump11289f42009-09-09 15:08:12 +00005979
Douglas Gregorebe10102009-08-20 07:17:43 +00005980template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005981StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005982TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005983 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005984 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005985 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005986 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005987
Douglas Gregor306de2f2010-04-22 23:59:56 +00005988 // If nothing changed, just retain this statement.
5989 if (!getDerived().AlwaysRebuild() &&
5990 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005991 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005992
5993 // Build a new statement.
5994 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005995 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005996}
Mike Stump11289f42009-09-09 15:08:12 +00005997
Douglas Gregorebe10102009-08-20 07:17:43 +00005998template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005999StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006000TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006001 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006002 if (S->getThrowExpr()) {
6003 Operand = getDerived().TransformExpr(S->getThrowExpr());
6004 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006005 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006006 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006007
Douglas Gregor2900c162010-04-22 21:44:01 +00006008 if (!getDerived().AlwaysRebuild() &&
6009 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006010 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006011
John McCallb268a282010-08-23 23:25:46 +00006012 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006013}
Mike Stump11289f42009-09-09 15:08:12 +00006014
Douglas Gregorebe10102009-08-20 07:17:43 +00006015template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006016StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006017TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006018 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006019 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006020 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006021 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006022 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006023 Object =
6024 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6025 Object.get());
6026 if (Object.isInvalid())
6027 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006028
Douglas Gregor6148de72010-04-22 22:01:21 +00006029 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006030 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006031 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006032 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006033
Douglas Gregor6148de72010-04-22 22:01:21 +00006034 // If nothing change, just retain the current statement.
6035 if (!getDerived().AlwaysRebuild() &&
6036 Object.get() == S->getSynchExpr() &&
6037 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006038 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006039
6040 // Build a new statement.
6041 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006042 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006043}
6044
6045template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006046StmtResult
John McCall31168b02011-06-15 23:02:42 +00006047TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6048 ObjCAutoreleasePoolStmt *S) {
6049 // Transform the body.
6050 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6051 if (Body.isInvalid())
6052 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006053
John McCall31168b02011-06-15 23:02:42 +00006054 // If nothing changed, just retain this statement.
6055 if (!getDerived().AlwaysRebuild() &&
6056 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006057 return S;
John McCall31168b02011-06-15 23:02:42 +00006058
6059 // Build a new statement.
6060 return getDerived().RebuildObjCAutoreleasePoolStmt(
6061 S->getAtLoc(), Body.get());
6062}
6063
6064template<typename Derived>
6065StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006066TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006067 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006068 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006069 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006070 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006071 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006072
Douglas Gregorf68a5082010-04-22 23:10:45 +00006073 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006074 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006075 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006076 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006077
Douglas Gregorf68a5082010-04-22 23:10:45 +00006078 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006079 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006080 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006081 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006082
Douglas Gregorf68a5082010-04-22 23:10:45 +00006083 // If nothing changed, just retain this statement.
6084 if (!getDerived().AlwaysRebuild() &&
6085 Element.get() == S->getElement() &&
6086 Collection.get() == S->getCollection() &&
6087 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006088 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006089
Douglas Gregorf68a5082010-04-22 23:10:45 +00006090 // Build a new statement.
6091 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006092 Element.get(),
6093 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006094 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006095 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006096}
6097
David Majnemer5f7efef2013-10-15 09:50:08 +00006098template <typename Derived>
6099StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006100 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006101 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006102 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6103 TypeSourceInfo *T =
6104 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006105 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006106 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006107
David Majnemer5f7efef2013-10-15 09:50:08 +00006108 Var = getDerived().RebuildExceptionDecl(
6109 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6110 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006111 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006112 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006113 }
Mike Stump11289f42009-09-09 15:08:12 +00006114
Douglas Gregorebe10102009-08-20 07:17:43 +00006115 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006116 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006117 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006118 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006119
David Majnemer5f7efef2013-10-15 09:50:08 +00006120 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006121 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006122 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006123
David Majnemer5f7efef2013-10-15 09:50:08 +00006124 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006125}
Mike Stump11289f42009-09-09 15:08:12 +00006126
David Majnemer5f7efef2013-10-15 09:50:08 +00006127template <typename Derived>
6128StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006129 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006130 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006131 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006132 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006133
Douglas Gregorebe10102009-08-20 07:17:43 +00006134 // Transform the handlers.
6135 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006136 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006137 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006138 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006139 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006140 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006141
Douglas Gregorebe10102009-08-20 07:17:43 +00006142 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006143 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006144 }
Mike Stump11289f42009-09-09 15:08:12 +00006145
David Majnemer5f7efef2013-10-15 09:50:08 +00006146 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006147 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006148 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006149
John McCallb268a282010-08-23 23:25:46 +00006150 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006151 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006152}
Mike Stump11289f42009-09-09 15:08:12 +00006153
Richard Smith02e85f32011-04-14 22:09:26 +00006154template<typename Derived>
6155StmtResult
6156TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6157 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6158 if (Range.isInvalid())
6159 return StmtError();
6160
6161 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6162 if (BeginEnd.isInvalid())
6163 return StmtError();
6164
6165 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6166 if (Cond.isInvalid())
6167 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006168 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006169 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006170 if (Cond.isInvalid())
6171 return StmtError();
6172 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006173 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006174
6175 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6176 if (Inc.isInvalid())
6177 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006178 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006179 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006180
6181 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6182 if (LoopVar.isInvalid())
6183 return StmtError();
6184
6185 StmtResult NewStmt = S;
6186 if (getDerived().AlwaysRebuild() ||
6187 Range.get() != S->getRangeStmt() ||
6188 BeginEnd.get() != S->getBeginEndStmt() ||
6189 Cond.get() != S->getCond() ||
6190 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006191 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006192 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6193 S->getColonLoc(), Range.get(),
6194 BeginEnd.get(), Cond.get(),
6195 Inc.get(), LoopVar.get(),
6196 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006197 if (NewStmt.isInvalid())
6198 return StmtError();
6199 }
Richard Smith02e85f32011-04-14 22:09:26 +00006200
6201 StmtResult Body = getDerived().TransformStmt(S->getBody());
6202 if (Body.isInvalid())
6203 return StmtError();
6204
6205 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6206 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006207 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006208 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6209 S->getColonLoc(), Range.get(),
6210 BeginEnd.get(), Cond.get(),
6211 Inc.get(), LoopVar.get(),
6212 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006213 if (NewStmt.isInvalid())
6214 return StmtError();
6215 }
Richard Smith02e85f32011-04-14 22:09:26 +00006216
6217 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006218 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006219
6220 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6221}
6222
John Wiegley1c0675e2011-04-28 01:08:34 +00006223template<typename Derived>
6224StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006225TreeTransform<Derived>::TransformMSDependentExistsStmt(
6226 MSDependentExistsStmt *S) {
6227 // Transform the nested-name-specifier, if any.
6228 NestedNameSpecifierLoc QualifierLoc;
6229 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006230 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006231 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6232 if (!QualifierLoc)
6233 return StmtError();
6234 }
6235
6236 // Transform the declaration name.
6237 DeclarationNameInfo NameInfo = S->getNameInfo();
6238 if (NameInfo.getName()) {
6239 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6240 if (!NameInfo.getName())
6241 return StmtError();
6242 }
6243
6244 // Check whether anything changed.
6245 if (!getDerived().AlwaysRebuild() &&
6246 QualifierLoc == S->getQualifierLoc() &&
6247 NameInfo.getName() == S->getNameInfo().getName())
6248 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006249
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006250 // Determine whether this name exists, if we can.
6251 CXXScopeSpec SS;
6252 SS.Adopt(QualifierLoc);
6253 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006254 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006255 case Sema::IER_Exists:
6256 if (S->isIfExists())
6257 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006258
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006259 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6260
6261 case Sema::IER_DoesNotExist:
6262 if (S->isIfNotExists())
6263 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006264
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006265 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006266
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006267 case Sema::IER_Dependent:
6268 Dependent = true;
6269 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006270
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006271 case Sema::IER_Error:
6272 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006273 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006274
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006275 // We need to continue with the instantiation, so do so now.
6276 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6277 if (SubStmt.isInvalid())
6278 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006279
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006280 // If we have resolved the name, just transform to the substatement.
6281 if (!Dependent)
6282 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006283
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006284 // The name is still dependent, so build a dependent expression again.
6285 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6286 S->isIfExists(),
6287 QualifierLoc,
6288 NameInfo,
6289 SubStmt.get());
6290}
6291
6292template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006293ExprResult
6294TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6295 NestedNameSpecifierLoc QualifierLoc;
6296 if (E->getQualifierLoc()) {
6297 QualifierLoc
6298 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6299 if (!QualifierLoc)
6300 return ExprError();
6301 }
6302
6303 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6304 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6305 if (!PD)
6306 return ExprError();
6307
6308 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6309 if (Base.isInvalid())
6310 return ExprError();
6311
6312 return new (SemaRef.getASTContext())
6313 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6314 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6315 QualifierLoc, E->getMemberLoc());
6316}
6317
David Majnemerfad8f482013-10-15 09:33:02 +00006318template <typename Derived>
6319StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006320 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006321 if (TryBlock.isInvalid())
6322 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006323
6324 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006325 if (Handler.isInvalid())
6326 return StmtError();
6327
David Majnemerfad8f482013-10-15 09:33:02 +00006328 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6329 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006330 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006331
David Majnemerfad8f482013-10-15 09:33:02 +00006332 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006333 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006334}
6335
David Majnemerfad8f482013-10-15 09:33:02 +00006336template <typename Derived>
6337StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006338 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006339 if (Block.isInvalid())
6340 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006341
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006342 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006343}
6344
David Majnemerfad8f482013-10-15 09:33:02 +00006345template <typename Derived>
6346StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006347 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006348 if (FilterExpr.isInvalid())
6349 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006350
David Majnemer7e755502013-10-15 09:30:14 +00006351 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006352 if (Block.isInvalid())
6353 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006354
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006355 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6356 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006357}
6358
David Majnemerfad8f482013-10-15 09:33:02 +00006359template <typename Derived>
6360StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6361 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006362 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6363 else
6364 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6365}
6366
Alexander Musman64d33f12014-06-04 07:53:32 +00006367//===----------------------------------------------------------------------===//
6368// OpenMP directive transformation
6369//===----------------------------------------------------------------------===//
6370template <typename Derived>
6371StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6372 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006373
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006374 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006375 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006376 ArrayRef<OMPClause *> Clauses = D->clauses();
6377 TClauses.reserve(Clauses.size());
6378 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6379 I != E; ++I) {
6380 if (*I) {
6381 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevc5e02582014-06-16 07:08:35 +00006382 if (Clause)
6383 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006384 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006385 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006386 }
6387 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006388 if (!D->getAssociatedStmt()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006389 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006390 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006391 StmtResult AssociatedStmt =
Alexander Musman64d33f12014-06-04 07:53:32 +00006392 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataevc5e02582014-06-16 07:08:35 +00006393 if (AssociatedStmt.isInvalid() || TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006394 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006395 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006396
Alexander Musman64d33f12014-06-04 07:53:32 +00006397 return getDerived().RebuildOMPExecutableDirective(
6398 D->getDirectiveKind(), TClauses, AssociatedStmt.get(), D->getLocStart(),
6399 D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006400}
6401
Alexander Musman64d33f12014-06-04 07:53:32 +00006402template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006403StmtResult
6404TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6405 DeclarationNameInfo DirName;
Craig Topperc3ec1492014-05-26 06:22:03 +00006406 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006407 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6408 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6409 return Res;
6410}
6411
Alexander Musman64d33f12014-06-04 07:53:32 +00006412template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006413StmtResult
6414TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6415 DeclarationNameInfo DirName;
Craig Topperc3ec1492014-05-26 06:22:03 +00006416 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006417 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6418 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006419 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006420}
6421
Alexey Bataevf29276e2014-06-18 04:14:57 +00006422template <typename Derived>
6423StmtResult
6424TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6425 DeclarationNameInfo DirName;
6426 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr);
6427 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6428 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6429 return Res;
6430}
6431
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006432template <typename Derived>
6433StmtResult
6434TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6435 DeclarationNameInfo DirName;
6436 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr);
6437 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6438 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6439 return Res;
6440}
6441
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006442template <typename Derived>
6443StmtResult
6444TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6445 DeclarationNameInfo DirName;
6446 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr);
6447 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6448 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6449 return Res;
6450}
6451
Alexander Musman64d33f12014-06-04 07:53:32 +00006452//===----------------------------------------------------------------------===//
6453// OpenMP clause transformation
6454//===----------------------------------------------------------------------===//
6455template <typename Derived>
6456OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006457 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6458 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006459 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006460 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006461 C->getLParenLoc(), C->getLocEnd());
6462}
6463
Alexander Musman64d33f12014-06-04 07:53:32 +00006464template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006465OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006466TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6467 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6468 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006469 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006470 return getDerived().RebuildOMPNumThreadsClause(
6471 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00006472}
6473
Alexey Bataev62c87d22014-03-21 04:51:18 +00006474template <typename Derived>
6475OMPClause *
6476TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6477 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6478 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006479 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00006480 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006481 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00006482}
6483
Alexander Musman8bd31e62014-05-27 15:12:19 +00006484template <typename Derived>
6485OMPClause *
6486TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
6487 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
6488 if (E.isInvalid())
6489 return 0;
6490 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006491 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00006492}
6493
Alexander Musman64d33f12014-06-04 07:53:32 +00006494template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00006495OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006496TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006497 return getDerived().RebuildOMPDefaultClause(
6498 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
6499 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006500}
6501
Alexander Musman64d33f12014-06-04 07:53:32 +00006502template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006503OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006504TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00006505 return getDerived().RebuildOMPProcBindClause(
6506 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
6507 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006508}
6509
Alexander Musman64d33f12014-06-04 07:53:32 +00006510template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006511OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00006512TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
6513 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
6514 if (E.isInvalid())
6515 return nullptr;
6516 return getDerived().RebuildOMPScheduleClause(
6517 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
6518 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
6519}
6520
6521template <typename Derived>
6522OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00006523TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
6524 // No need to rebuild this clause, no template-dependent parameters.
6525 return C;
6526}
6527
6528template <typename Derived>
6529OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00006530TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
6531 // No need to rebuild this clause, no template-dependent parameters.
6532 return C;
6533}
6534
6535template <typename Derived>
6536OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006537TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006538 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006539 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006540 for (auto *VE : C->varlists()) {
6541 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006542 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006543 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006544 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006545 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006546 return getDerived().RebuildOMPPrivateClause(
6547 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006548}
6549
Alexander Musman64d33f12014-06-04 07:53:32 +00006550template <typename Derived>
6551OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
6552 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006553 llvm::SmallVector<Expr *, 16> Vars;
6554 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006555 for (auto *VE : C->varlists()) {
6556 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006557 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006558 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006559 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006560 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006561 return getDerived().RebuildOMPFirstprivateClause(
6562 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006563}
6564
Alexander Musman64d33f12014-06-04 07:53:32 +00006565template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006566OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00006567TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
6568 llvm::SmallVector<Expr *, 16> Vars;
6569 Vars.reserve(C->varlist_size());
6570 for (auto *VE : C->varlists()) {
6571 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6572 if (EVar.isInvalid())
6573 return nullptr;
6574 Vars.push_back(EVar.get());
6575 }
6576 return getDerived().RebuildOMPLastprivateClause(
6577 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6578}
6579
6580template <typename Derived>
6581OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006582TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6583 llvm::SmallVector<Expr *, 16> Vars;
6584 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006585 for (auto *VE : C->varlists()) {
6586 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006587 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006588 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006589 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006590 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006591 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
6592 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006593}
6594
Alexander Musman64d33f12014-06-04 07:53:32 +00006595template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006596OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00006597TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
6598 llvm::SmallVector<Expr *, 16> Vars;
6599 Vars.reserve(C->varlist_size());
6600 for (auto *VE : C->varlists()) {
6601 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6602 if (EVar.isInvalid())
6603 return nullptr;
6604 Vars.push_back(EVar.get());
6605 }
6606 CXXScopeSpec ReductionIdScopeSpec;
6607 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
6608
6609 DeclarationNameInfo NameInfo = C->getNameInfo();
6610 if (NameInfo.getName()) {
6611 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6612 if (!NameInfo.getName())
6613 return nullptr;
6614 }
6615 return getDerived().RebuildOMPReductionClause(
6616 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
6617 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
6618}
6619
6620template <typename Derived>
6621OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006622TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6623 llvm::SmallVector<Expr *, 16> Vars;
6624 Vars.reserve(C->varlist_size());
6625 for (auto *VE : C->varlists()) {
6626 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6627 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006628 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006629 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00006630 }
6631 ExprResult Step = getDerived().TransformExpr(C->getStep());
6632 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006633 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00006634 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
6635 C->getLParenLoc(),
6636 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00006637}
6638
Alexander Musman64d33f12014-06-04 07:53:32 +00006639template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00006640OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006641TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
6642 llvm::SmallVector<Expr *, 16> Vars;
6643 Vars.reserve(C->varlist_size());
6644 for (auto *VE : C->varlists()) {
6645 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6646 if (EVar.isInvalid())
6647 return nullptr;
6648 Vars.push_back(EVar.get());
6649 }
6650 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
6651 if (Alignment.isInvalid())
6652 return nullptr;
6653 return getDerived().RebuildOMPAlignedClause(
6654 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
6655 C->getColonLoc(), C->getLocEnd());
6656}
6657
Alexander Musman64d33f12014-06-04 07:53:32 +00006658template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00006659OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006660TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6661 llvm::SmallVector<Expr *, 16> Vars;
6662 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006663 for (auto *VE : C->varlists()) {
6664 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006665 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00006666 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006667 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006668 }
Alexander Musman64d33f12014-06-04 07:53:32 +00006669 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
6670 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006671}
6672
Douglas Gregorebe10102009-08-20 07:17:43 +00006673//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006674// Expression transformation
6675//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006676template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006677ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006678TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006679 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006680}
Mike Stump11289f42009-09-09 15:08:12 +00006681
6682template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006683ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006684TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006685 NestedNameSpecifierLoc QualifierLoc;
6686 if (E->getQualifierLoc()) {
6687 QualifierLoc
6688 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6689 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006690 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006691 }
John McCallce546572009-12-08 09:08:17 +00006692
6693 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006694 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6695 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006696 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006697 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006698
John McCall815039a2010-08-17 21:27:17 +00006699 DeclarationNameInfo NameInfo = E->getNameInfo();
6700 if (NameInfo.getName()) {
6701 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6702 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006703 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006704 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006705
6706 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006707 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006708 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006709 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006710 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006711
6712 // Mark it referenced in the new context regardless.
6713 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006714 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006715
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006716 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006717 }
John McCallce546572009-12-08 09:08:17 +00006718
Craig Topperc3ec1492014-05-26 06:22:03 +00006719 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00006720 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006721 TemplateArgs = &TransArgs;
6722 TransArgs.setLAngleLoc(E->getLAngleLoc());
6723 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006724 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6725 E->getNumTemplateArgs(),
6726 TransArgs))
6727 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006728 }
6729
Chad Rosier1dcde962012-08-08 18:46:20 +00006730 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006731 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006732}
Mike Stump11289f42009-09-09 15:08:12 +00006733
Douglas Gregora16548e2009-08-11 05:31:07 +00006734template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006735ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006736TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006737 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006738}
Mike Stump11289f42009-09-09 15:08:12 +00006739
Douglas Gregora16548e2009-08-11 05:31:07 +00006740template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006741ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006742TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006743 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006744}
Mike Stump11289f42009-09-09 15:08:12 +00006745
Douglas Gregora16548e2009-08-11 05:31:07 +00006746template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006747ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006748TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006749 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006750}
Mike Stump11289f42009-09-09 15:08:12 +00006751
Douglas Gregora16548e2009-08-11 05:31:07 +00006752template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006753ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006754TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006755 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00006756}
Mike Stump11289f42009-09-09 15:08:12 +00006757
Douglas Gregora16548e2009-08-11 05:31:07 +00006758template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006759ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006760TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006761 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006762}
6763
6764template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006765ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006766TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006767 if (FunctionDecl *FD = E->getDirectCallee())
6768 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006769 return SemaRef.MaybeBindToTemporary(E);
6770}
6771
6772template<typename Derived>
6773ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006774TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6775 ExprResult ControllingExpr =
6776 getDerived().TransformExpr(E->getControllingExpr());
6777 if (ControllingExpr.isInvalid())
6778 return ExprError();
6779
Chris Lattner01cf8db2011-07-20 06:58:45 +00006780 SmallVector<Expr *, 4> AssocExprs;
6781 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006782 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6783 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6784 if (TS) {
6785 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6786 if (!AssocType)
6787 return ExprError();
6788 AssocTypes.push_back(AssocType);
6789 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00006790 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00006791 }
6792
6793 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6794 if (AssocExpr.isInvalid())
6795 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006796 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00006797 }
6798
6799 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6800 E->getDefaultLoc(),
6801 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006802 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006803 AssocTypes,
6804 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006805}
6806
6807template<typename Derived>
6808ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006809TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006810 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006811 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006812 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006813
Douglas Gregora16548e2009-08-11 05:31:07 +00006814 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006815 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006816
John McCallb268a282010-08-23 23:25:46 +00006817 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006818 E->getRParen());
6819}
6820
Richard Smithdb2630f2012-10-21 03:28:35 +00006821/// \brief The operand of a unary address-of operator has special rules: it's
6822/// allowed to refer to a non-static member of a class even if there's no 'this'
6823/// object available.
6824template<typename Derived>
6825ExprResult
6826TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6827 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00006828 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00006829 else
6830 return getDerived().TransformExpr(E);
6831}
6832
Mike Stump11289f42009-09-09 15:08:12 +00006833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006834ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006835TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006836 ExprResult SubExpr;
6837 if (E->getOpcode() == UO_AddrOf)
6838 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6839 else
6840 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006841 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006842 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006843
Douglas Gregora16548e2009-08-11 05:31:07 +00006844 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006845 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006846
Douglas Gregora16548e2009-08-11 05:31:07 +00006847 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6848 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006849 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006850}
Mike Stump11289f42009-09-09 15:08:12 +00006851
Douglas Gregora16548e2009-08-11 05:31:07 +00006852template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006853ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006854TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6855 // Transform the type.
6856 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6857 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006858 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006859
Douglas Gregor882211c2010-04-28 22:16:22 +00006860 // Transform all of the components into components similar to what the
6861 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006862 // FIXME: It would be slightly more efficient in the non-dependent case to
6863 // just map FieldDecls, rather than requiring the rebuilder to look for
6864 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006865 // template code that we don't care.
6866 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006867 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006868 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006869 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006870 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6871 const Node &ON = E->getComponent(I);
6872 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006873 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006874 Comp.LocStart = ON.getSourceRange().getBegin();
6875 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006876 switch (ON.getKind()) {
6877 case Node::Array: {
6878 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006879 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006880 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006881 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006882
Douglas Gregor882211c2010-04-28 22:16:22 +00006883 ExprChanged = ExprChanged || Index.get() != FromIndex;
6884 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006885 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006886 break;
6887 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006888
Douglas Gregor882211c2010-04-28 22:16:22 +00006889 case Node::Field:
6890 case Node::Identifier:
6891 Comp.isBrackets = false;
6892 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006893 if (!Comp.U.IdentInfo)
6894 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006895
Douglas Gregor882211c2010-04-28 22:16:22 +00006896 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006897
Douglas Gregord1702062010-04-29 00:18:15 +00006898 case Node::Base:
6899 // Will be recomputed during the rebuild.
6900 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006901 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006902
Douglas Gregor882211c2010-04-28 22:16:22 +00006903 Components.push_back(Comp);
6904 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006905
Douglas Gregor882211c2010-04-28 22:16:22 +00006906 // If nothing changed, retain the existing expression.
6907 if (!getDerived().AlwaysRebuild() &&
6908 Type == E->getTypeSourceInfo() &&
6909 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006910 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00006911
Douglas Gregor882211c2010-04-28 22:16:22 +00006912 // Build a new offsetof expression.
6913 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6914 Components.data(), Components.size(),
6915 E->getRParenLoc());
6916}
6917
6918template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006919ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006920TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6921 assert(getDerived().AlreadyTransformed(E->getType()) &&
6922 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006923 return E;
John McCall8d69a212010-11-15 23:31:06 +00006924}
6925
6926template<typename Derived>
6927ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006928TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006929 // Rebuild the syntactic form. The original syntactic form has
6930 // opaque-value expressions in it, so strip those away and rebuild
6931 // the result. This is a really awful way of doing this, but the
6932 // better solution (rebuilding the semantic expressions and
6933 // rebinding OVEs as necessary) doesn't work; we'd need
6934 // TreeTransform to not strip away implicit conversions.
6935 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6936 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006937 if (result.isInvalid()) return ExprError();
6938
6939 // If that gives us a pseudo-object result back, the pseudo-object
6940 // expression must have been an lvalue-to-rvalue conversion which we
6941 // should reapply.
6942 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006943 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00006944
6945 return result;
6946}
6947
6948template<typename Derived>
6949ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006950TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6951 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006952 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006953 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006954
John McCallbcd03502009-12-07 02:54:59 +00006955 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006956 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006957 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006958
John McCall4c98fd82009-11-04 07:28:41 +00006959 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006960 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006961
Peter Collingbournee190dee2011-03-11 19:24:49 +00006962 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6963 E->getKind(),
6964 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006965 }
Mike Stump11289f42009-09-09 15:08:12 +00006966
Eli Friedmane4f22df2012-02-29 04:03:55 +00006967 // C++0x [expr.sizeof]p1:
6968 // The operand is either an expression, which is an unevaluated operand
6969 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006970 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6971 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006972
Reid Kleckner32506ed2014-06-12 23:03:48 +00006973 // Try to recover if we have something like sizeof(T::X) where X is a type.
6974 // Notably, there must be *exactly* one set of parens if X is a type.
6975 TypeSourceInfo *RecoveryTSI = nullptr;
6976 ExprResult SubExpr;
6977 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
6978 if (auto *DRE =
6979 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
6980 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
6981 PE, DRE, false, &RecoveryTSI);
6982 else
6983 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6984
6985 if (RecoveryTSI) {
6986 return getDerived().RebuildUnaryExprOrTypeTrait(
6987 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
6988 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00006989 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006990
Eli Friedmane4f22df2012-02-29 04:03:55 +00006991 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006992 return E;
Mike Stump11289f42009-09-09 15:08:12 +00006993
Peter Collingbournee190dee2011-03-11 19:24:49 +00006994 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6995 E->getOperatorLoc(),
6996 E->getKind(),
6997 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006998}
Mike Stump11289f42009-09-09 15:08:12 +00006999
Douglas Gregora16548e2009-08-11 05:31:07 +00007000template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007001ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007002TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007003 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007004 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007005 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007006
John McCalldadc5752010-08-24 06:29:42 +00007007 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007008 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007009 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007010
7011
Douglas Gregora16548e2009-08-11 05:31:07 +00007012 if (!getDerived().AlwaysRebuild() &&
7013 LHS.get() == E->getLHS() &&
7014 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007015 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007016
John McCallb268a282010-08-23 23:25:46 +00007017 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007018 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007019 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007020 E->getRBracketLoc());
7021}
Mike Stump11289f42009-09-09 15:08:12 +00007022
7023template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007024ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007025TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007026 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007027 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007028 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007029 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007030
7031 // Transform arguments.
7032 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007033 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007034 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007035 &ArgChanged))
7036 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007037
Douglas Gregora16548e2009-08-11 05:31:07 +00007038 if (!getDerived().AlwaysRebuild() &&
7039 Callee.get() == E->getCallee() &&
7040 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007041 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007042
Douglas Gregora16548e2009-08-11 05:31:07 +00007043 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007044 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007045 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007046 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007047 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007048 E->getRParenLoc());
7049}
Mike Stump11289f42009-09-09 15:08:12 +00007050
7051template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007052ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007053TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007054 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007055 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007056 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007057
Douglas Gregorea972d32011-02-28 21:54:11 +00007058 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007059 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007060 QualifierLoc
7061 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007062
Douglas Gregorea972d32011-02-28 21:54:11 +00007063 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007064 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007065 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007066 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007067
Eli Friedman2cfcef62009-12-04 06:40:45 +00007068 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007069 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7070 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007071 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007072 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007073
John McCall16df1e52010-03-30 21:47:33 +00007074 NamedDecl *FoundDecl = E->getFoundDecl();
7075 if (FoundDecl == E->getMemberDecl()) {
7076 FoundDecl = Member;
7077 } else {
7078 FoundDecl = cast_or_null<NamedDecl>(
7079 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7080 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007081 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007082 }
7083
Douglas Gregora16548e2009-08-11 05:31:07 +00007084 if (!getDerived().AlwaysRebuild() &&
7085 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007086 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007087 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007088 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007089 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007090
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007091 // Mark it referenced in the new context regardless.
7092 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007093 SemaRef.MarkMemberReferenced(E);
7094
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007095 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007096 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007097
John McCall6b51f282009-11-23 01:53:49 +00007098 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007099 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007100 TransArgs.setLAngleLoc(E->getLAngleLoc());
7101 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007102 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7103 E->getNumTemplateArgs(),
7104 TransArgs))
7105 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007106 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007107
Douglas Gregora16548e2009-08-11 05:31:07 +00007108 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007109 SourceLocation FakeOperatorLoc =
7110 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007111
John McCall38836f02010-01-15 08:34:02 +00007112 // FIXME: to do this check properly, we will need to preserve the
7113 // first-qualifier-in-scope here, just in case we had a dependent
7114 // base (and therefore couldn't do the check) and a
7115 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007116 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007117
John McCallb268a282010-08-23 23:25:46 +00007118 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007119 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007120 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007121 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007122 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007123 Member,
John McCall16df1e52010-03-30 21:47:33 +00007124 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007125 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007126 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007127 FirstQualifierInScope);
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>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007133 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007134 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007135 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007136
John McCalldadc5752010-08-24 06:29:42 +00007137 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007138 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007139 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007140
Douglas Gregora16548e2009-08-11 05:31:07 +00007141 if (!getDerived().AlwaysRebuild() &&
7142 LHS.get() == E->getLHS() &&
7143 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007144 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007145
Lang Hames5de91cc2012-10-02 04:45:10 +00007146 Sema::FPContractStateRAII FPContractState(getSema());
7147 getSema().FPFeatures.fp_contract = E->isFPContractable();
7148
Douglas Gregora16548e2009-08-11 05:31:07 +00007149 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007150 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007151}
7152
Mike Stump11289f42009-09-09 15:08:12 +00007153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007154ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007155TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007156 CompoundAssignOperator *E) {
7157 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007158}
Mike Stump11289f42009-09-09 15:08:12 +00007159
Douglas Gregora16548e2009-08-11 05:31:07 +00007160template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007161ExprResult TreeTransform<Derived>::
7162TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7163 // Just rebuild the common and RHS expressions and see whether we
7164 // get any changes.
7165
7166 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7167 if (commonExpr.isInvalid())
7168 return ExprError();
7169
7170 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7171 if (rhs.isInvalid())
7172 return ExprError();
7173
7174 if (!getDerived().AlwaysRebuild() &&
7175 commonExpr.get() == e->getCommon() &&
7176 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007177 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007178
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007179 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00007180 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00007181 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00007182 e->getColonLoc(),
7183 rhs.get());
7184}
7185
7186template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007187ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007188TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007189 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007190 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007191 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007192
John McCalldadc5752010-08-24 06:29:42 +00007193 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007194 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007195 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007196
John McCalldadc5752010-08-24 06:29:42 +00007197 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007198 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007199 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007200
Douglas Gregora16548e2009-08-11 05:31:07 +00007201 if (!getDerived().AlwaysRebuild() &&
7202 Cond.get() == E->getCond() &&
7203 LHS.get() == E->getLHS() &&
7204 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007205 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007206
John McCallb268a282010-08-23 23:25:46 +00007207 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007208 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007209 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007210 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007211 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007212}
Mike Stump11289f42009-09-09 15:08:12 +00007213
7214template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007215ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007216TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007217 // Implicit casts are eliminated during transformation, since they
7218 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007219 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007220}
Mike Stump11289f42009-09-09 15:08:12 +00007221
Douglas Gregora16548e2009-08-11 05:31:07 +00007222template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007223ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007224TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007225 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7226 if (!Type)
7227 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007228
John McCalldadc5752010-08-24 06:29:42 +00007229 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007230 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007231 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007232 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007233
Douglas Gregora16548e2009-08-11 05:31:07 +00007234 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007235 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007236 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007237 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007238
John McCall97513962010-01-15 18:39:57 +00007239 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007240 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007241 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007242 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007243}
Mike Stump11289f42009-09-09 15:08:12 +00007244
Douglas Gregora16548e2009-08-11 05:31:07 +00007245template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007246ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007247TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007248 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7249 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7250 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007251 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007252
John McCalldadc5752010-08-24 06:29:42 +00007253 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007254 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007255 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007256
Douglas Gregora16548e2009-08-11 05:31:07 +00007257 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007258 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007259 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007260 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007261
John McCall5d7aa7f2010-01-19 22:33:45 +00007262 // Note: the expression type doesn't necessarily match the
7263 // type-as-written, but that's okay, because it should always be
7264 // derivable from the initializer.
7265
John McCalle15bbff2010-01-18 19:35:47 +00007266 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007267 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007268 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007269}
Mike Stump11289f42009-09-09 15:08:12 +00007270
Douglas Gregora16548e2009-08-11 05:31:07 +00007271template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007272ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007273TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007274 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007275 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007276 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007277
Douglas Gregora16548e2009-08-11 05:31:07 +00007278 if (!getDerived().AlwaysRebuild() &&
7279 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007280 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007281
Douglas Gregora16548e2009-08-11 05:31:07 +00007282 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007283 SourceLocation FakeOperatorLoc =
7284 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007285 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007286 E->getAccessorLoc(),
7287 E->getAccessor());
7288}
Mike Stump11289f42009-09-09 15:08:12 +00007289
Douglas Gregora16548e2009-08-11 05:31:07 +00007290template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007291ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007292TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007293 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007294
Benjamin Kramerf0623432012-08-23 22:51:59 +00007295 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007296 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007297 Inits, &InitChanged))
7298 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007299
Douglas Gregora16548e2009-08-11 05:31:07 +00007300 if (!getDerived().AlwaysRebuild() && !InitChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007301 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007302
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007303 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007304 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007305}
Mike Stump11289f42009-09-09 15:08:12 +00007306
Douglas Gregora16548e2009-08-11 05:31:07 +00007307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007308ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007309TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007310 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007311
Douglas Gregorebe10102009-08-20 07:17:43 +00007312 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007313 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007314 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007315 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007316
Douglas Gregorebe10102009-08-20 07:17:43 +00007317 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007318 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007319 bool ExprChanged = false;
7320 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7321 DEnd = E->designators_end();
7322 D != DEnd; ++D) {
7323 if (D->isFieldDesignator()) {
7324 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7325 D->getDotLoc(),
7326 D->getFieldLoc()));
7327 continue;
7328 }
Mike Stump11289f42009-09-09 15:08:12 +00007329
Douglas Gregora16548e2009-08-11 05:31:07 +00007330 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007331 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007332 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007333 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007334
7335 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007336 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007337
Douglas Gregora16548e2009-08-11 05:31:07 +00007338 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007339 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007340 continue;
7341 }
Mike Stump11289f42009-09-09 15:08:12 +00007342
Douglas Gregora16548e2009-08-11 05:31:07 +00007343 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007344 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007345 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7346 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007347 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007348
John McCalldadc5752010-08-24 06:29:42 +00007349 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007350 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007351 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007352
7353 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007354 End.get(),
7355 D->getLBracketLoc(),
7356 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007357
Douglas Gregora16548e2009-08-11 05:31:07 +00007358 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7359 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007360
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007361 ArrayExprs.push_back(Start.get());
7362 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007363 }
Mike Stump11289f42009-09-09 15:08:12 +00007364
Douglas Gregora16548e2009-08-11 05:31:07 +00007365 if (!getDerived().AlwaysRebuild() &&
7366 Init.get() == E->getInit() &&
7367 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007368 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007369
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007370 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007371 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007372 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007373}
Mike Stump11289f42009-09-09 15:08:12 +00007374
Douglas Gregora16548e2009-08-11 05:31:07 +00007375template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007376ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007377TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007378 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007379 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007380
Douglas Gregor3da3c062009-10-28 00:29:27 +00007381 // FIXME: Will we ever have proper type location here? Will we actually
7382 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007383 QualType T = getDerived().TransformType(E->getType());
7384 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007385 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007386
Douglas Gregora16548e2009-08-11 05:31:07 +00007387 if (!getDerived().AlwaysRebuild() &&
7388 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007389 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007390
Douglas Gregora16548e2009-08-11 05:31:07 +00007391 return getDerived().RebuildImplicitValueInitExpr(T);
7392}
Mike Stump11289f42009-09-09 15:08:12 +00007393
Douglas Gregora16548e2009-08-11 05:31:07 +00007394template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007395ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007396TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007397 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7398 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007399 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007400
John McCalldadc5752010-08-24 06:29:42 +00007401 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007402 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007403 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007404
Douglas Gregora16548e2009-08-11 05:31:07 +00007405 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007406 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007407 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007408 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007409
John McCallb268a282010-08-23 23:25:46 +00007410 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007411 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007412}
7413
7414template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007415ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007416TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007417 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007418 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007419 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7420 &ArgumentChanged))
7421 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007422
Douglas Gregora16548e2009-08-11 05:31:07 +00007423 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007424 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007425 E->getRParenLoc());
7426}
Mike Stump11289f42009-09-09 15:08:12 +00007427
Douglas Gregora16548e2009-08-11 05:31:07 +00007428/// \brief Transform an address-of-label expression.
7429///
7430/// By default, the transformation of an address-of-label expression always
7431/// rebuilds the expression, so that the label identifier can be resolved to
7432/// the corresponding label statement by semantic analysis.
7433template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007434ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007435TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007436 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7437 E->getLabel());
7438 if (!LD)
7439 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007440
Douglas Gregora16548e2009-08-11 05:31:07 +00007441 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007442 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007443}
Mike Stump11289f42009-09-09 15:08:12 +00007444
7445template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007446ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007447TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007448 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007449 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007450 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007451 if (SubStmt.isInvalid()) {
7452 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007453 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007454 }
Mike Stump11289f42009-09-09 15:08:12 +00007455
Douglas Gregora16548e2009-08-11 05:31:07 +00007456 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007457 SubStmt.get() == E->getSubStmt()) {
7458 // Calling this an 'error' is unintuitive, but it does the right thing.
7459 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007460 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007461 }
Mike Stump11289f42009-09-09 15:08:12 +00007462
7463 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007464 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007465 E->getRParenLoc());
7466}
Mike Stump11289f42009-09-09 15:08:12 +00007467
Douglas Gregora16548e2009-08-11 05:31:07 +00007468template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007469ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007470TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007471 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007472 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007473 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007474
John McCalldadc5752010-08-24 06:29:42 +00007475 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007476 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007477 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007478
John McCalldadc5752010-08-24 06:29:42 +00007479 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007480 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007481 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007482
Douglas Gregora16548e2009-08-11 05:31:07 +00007483 if (!getDerived().AlwaysRebuild() &&
7484 Cond.get() == E->getCond() &&
7485 LHS.get() == E->getLHS() &&
7486 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007487 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007488
Douglas Gregora16548e2009-08-11 05:31:07 +00007489 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007490 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007491 E->getRParenLoc());
7492}
Mike Stump11289f42009-09-09 15:08:12 +00007493
Douglas Gregora16548e2009-08-11 05:31:07 +00007494template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007495ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007496TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007497 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007498}
7499
7500template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007501ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007502TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007503 switch (E->getOperator()) {
7504 case OO_New:
7505 case OO_Delete:
7506 case OO_Array_New:
7507 case OO_Array_Delete:
7508 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007509
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007510 case OO_Call: {
7511 // This is a call to an object's operator().
7512 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7513
7514 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007515 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007516 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007517 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007518
7519 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007520 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7521 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007522
7523 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007524 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007525 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007526 Args))
7527 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007528
John McCallb268a282010-08-23 23:25:46 +00007529 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007530 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007531 E->getLocEnd());
7532 }
7533
7534#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7535 case OO_##Name:
7536#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7537#include "clang/Basic/OperatorKinds.def"
7538 case OO_Subscript:
7539 // Handled below.
7540 break;
7541
7542 case OO_Conditional:
7543 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007544
7545 case OO_None:
7546 case NUM_OVERLOADED_OPERATORS:
7547 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007548 }
7549
John McCalldadc5752010-08-24 06:29:42 +00007550 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007551 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007552 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007553
Richard Smithdb2630f2012-10-21 03:28:35 +00007554 ExprResult First;
7555 if (E->getOperator() == OO_Amp)
7556 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7557 else
7558 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007559 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007560 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007561
John McCalldadc5752010-08-24 06:29:42 +00007562 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007563 if (E->getNumArgs() == 2) {
7564 Second = getDerived().TransformExpr(E->getArg(1));
7565 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007566 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007567 }
Mike Stump11289f42009-09-09 15:08:12 +00007568
Douglas Gregora16548e2009-08-11 05:31:07 +00007569 if (!getDerived().AlwaysRebuild() &&
7570 Callee.get() == E->getCallee() &&
7571 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007572 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007573 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007574
Lang Hames5de91cc2012-10-02 04:45:10 +00007575 Sema::FPContractStateRAII FPContractState(getSema());
7576 getSema().FPFeatures.fp_contract = E->isFPContractable();
7577
Douglas Gregora16548e2009-08-11 05:31:07 +00007578 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7579 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007580 Callee.get(),
7581 First.get(),
7582 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007583}
Mike Stump11289f42009-09-09 15:08:12 +00007584
Douglas Gregora16548e2009-08-11 05:31:07 +00007585template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007586ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007587TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7588 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007589}
Mike Stump11289f42009-09-09 15:08:12 +00007590
Douglas Gregora16548e2009-08-11 05:31:07 +00007591template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007592ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007593TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7594 // Transform the callee.
7595 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7596 if (Callee.isInvalid())
7597 return ExprError();
7598
7599 // Transform exec config.
7600 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7601 if (EC.isInvalid())
7602 return ExprError();
7603
7604 // Transform arguments.
7605 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007606 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007607 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007608 &ArgChanged))
7609 return ExprError();
7610
7611 if (!getDerived().AlwaysRebuild() &&
7612 Callee.get() == E->getCallee() &&
7613 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007614 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007615
7616 // FIXME: Wrong source location information for the '('.
7617 SourceLocation FakeLParenLoc
7618 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7619 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007620 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007621 E->getRParenLoc(), EC.get());
7622}
7623
7624template<typename Derived>
7625ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007626TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007627 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7628 if (!Type)
7629 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007630
John McCalldadc5752010-08-24 06:29:42 +00007631 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007632 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007633 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007634 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007635
Douglas Gregora16548e2009-08-11 05:31:07 +00007636 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007637 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007638 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007639 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007640 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007641 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007642 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007643 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007644 E->getAngleBrackets().getEnd(),
7645 // FIXME. this should be '(' location
7646 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007647 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007648 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007649}
Mike Stump11289f42009-09-09 15:08:12 +00007650
Douglas Gregora16548e2009-08-11 05:31:07 +00007651template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007652ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007653TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7654 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007655}
Mike Stump11289f42009-09-09 15:08:12 +00007656
7657template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007658ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007659TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7660 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007661}
7662
Douglas Gregora16548e2009-08-11 05:31:07 +00007663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007664ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007665TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007666 CXXReinterpretCastExpr *E) {
7667 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007668}
Mike Stump11289f42009-09-09 15:08:12 +00007669
Douglas Gregora16548e2009-08-11 05:31:07 +00007670template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007671ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007672TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7673 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007674}
Mike Stump11289f42009-09-09 15:08:12 +00007675
Douglas Gregora16548e2009-08-11 05:31:07 +00007676template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007677ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007678TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007679 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007680 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7681 if (!Type)
7682 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007683
John McCalldadc5752010-08-24 06:29:42 +00007684 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007685 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007686 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007687 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007688
Douglas Gregora16548e2009-08-11 05:31:07 +00007689 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007690 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007691 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007692 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007693
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007694 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007695 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007696 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007697 E->getRParenLoc());
7698}
Mike Stump11289f42009-09-09 15:08:12 +00007699
Douglas Gregora16548e2009-08-11 05:31:07 +00007700template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007701ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007702TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007703 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007704 TypeSourceInfo *TInfo
7705 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7706 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007707 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007708
Douglas Gregora16548e2009-08-11 05:31:07 +00007709 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007710 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007711 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007712
Douglas Gregor9da64192010-04-26 22:37:10 +00007713 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7714 E->getLocStart(),
7715 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007716 E->getLocEnd());
7717 }
Mike Stump11289f42009-09-09 15:08:12 +00007718
Eli Friedman456f0182012-01-20 01:26:23 +00007719 // We don't know whether the subexpression is potentially evaluated until
7720 // after we perform semantic analysis. We speculatively assume it is
7721 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007722 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007723 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7724 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007725
John McCalldadc5752010-08-24 06:29:42 +00007726 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007727 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007728 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007729
Douglas Gregora16548e2009-08-11 05:31:07 +00007730 if (!getDerived().AlwaysRebuild() &&
7731 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007732 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007733
Douglas Gregor9da64192010-04-26 22:37:10 +00007734 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7735 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007736 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007737 E->getLocEnd());
7738}
7739
7740template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007741ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007742TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7743 if (E->isTypeOperand()) {
7744 TypeSourceInfo *TInfo
7745 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7746 if (!TInfo)
7747 return ExprError();
7748
7749 if (!getDerived().AlwaysRebuild() &&
7750 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007751 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007752
Douglas Gregor69735112011-03-06 17:40:41 +00007753 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007754 E->getLocStart(),
7755 TInfo,
7756 E->getLocEnd());
7757 }
7758
Francois Pichet9f4f2072010-09-08 12:20:18 +00007759 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7760
7761 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7762 if (SubExpr.isInvalid())
7763 return ExprError();
7764
7765 if (!getDerived().AlwaysRebuild() &&
7766 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007767 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00007768
7769 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7770 E->getLocStart(),
7771 SubExpr.get(),
7772 E->getLocEnd());
7773}
7774
7775template<typename Derived>
7776ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007777TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007778 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007779}
Mike Stump11289f42009-09-09 15:08:12 +00007780
Douglas Gregora16548e2009-08-11 05:31:07 +00007781template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007782ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007783TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007784 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007785 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007786}
Mike Stump11289f42009-09-09 15:08:12 +00007787
Douglas Gregora16548e2009-08-11 05:31:07 +00007788template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007789ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007790TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007791 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007792
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007793 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7794 // Make sure that we capture 'this'.
7795 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007796 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007797 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007798
Douglas Gregorb15af892010-01-07 23:12:05 +00007799 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007800}
Mike Stump11289f42009-09-09 15:08:12 +00007801
Douglas Gregora16548e2009-08-11 05:31:07 +00007802template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007803ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007804TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007805 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007806 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007807 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007808
Douglas Gregora16548e2009-08-11 05:31:07 +00007809 if (!getDerived().AlwaysRebuild() &&
7810 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007811 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007812
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007813 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7814 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007815}
Mike Stump11289f42009-09-09 15:08:12 +00007816
Douglas Gregora16548e2009-08-11 05:31:07 +00007817template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007818ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007819TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007820 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007821 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7822 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007823 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007824 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007825
Chandler Carruth794da4c2010-02-08 06:42:49 +00007826 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007827 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007828 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007829
Douglas Gregor033f6752009-12-23 23:03:06 +00007830 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007831}
Mike Stump11289f42009-09-09 15:08:12 +00007832
Douglas Gregora16548e2009-08-11 05:31:07 +00007833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007834ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007835TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7836 FieldDecl *Field
7837 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7838 E->getField()));
7839 if (!Field)
7840 return ExprError();
7841
7842 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007843 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00007844
7845 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7846}
7847
7848template<typename Derived>
7849ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007850TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7851 CXXScalarValueInitExpr *E) {
7852 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7853 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007854 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007855
Douglas Gregora16548e2009-08-11 05:31:07 +00007856 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007857 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007858 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007859
Chad Rosier1dcde962012-08-08 18:46:20 +00007860 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007861 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007862 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007863}
Mike Stump11289f42009-09-09 15:08:12 +00007864
Douglas Gregora16548e2009-08-11 05:31:07 +00007865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007866ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007867TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007868 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007869 TypeSourceInfo *AllocTypeInfo
7870 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7871 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007872 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007873
Douglas Gregora16548e2009-08-11 05:31:07 +00007874 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007875 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007876 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007877 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007878
Douglas Gregora16548e2009-08-11 05:31:07 +00007879 // Transform the placement arguments (if any).
7880 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007881 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007882 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007883 E->getNumPlacementArgs(), true,
7884 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007885 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007886
Sebastian Redl6047f072012-02-16 12:22:20 +00007887 // Transform the initializer (if any).
7888 Expr *OldInit = E->getInitializer();
7889 ExprResult NewInit;
7890 if (OldInit)
7891 NewInit = getDerived().TransformExpr(OldInit);
7892 if (NewInit.isInvalid())
7893 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007894
Sebastian Redl6047f072012-02-16 12:22:20 +00007895 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00007896 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007897 if (E->getOperatorNew()) {
7898 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007899 getDerived().TransformDecl(E->getLocStart(),
7900 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007901 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007902 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007903 }
7904
Craig Topperc3ec1492014-05-26 06:22:03 +00007905 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007906 if (E->getOperatorDelete()) {
7907 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007908 getDerived().TransformDecl(E->getLocStart(),
7909 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007910 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007911 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007912 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007913
Douglas Gregora16548e2009-08-11 05:31:07 +00007914 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007915 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007916 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007917 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007918 OperatorNew == E->getOperatorNew() &&
7919 OperatorDelete == E->getOperatorDelete() &&
7920 !ArgumentChanged) {
7921 // Mark any declarations we need as referenced.
7922 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007923 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007924 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007925 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007926 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007927
Sebastian Redl6047f072012-02-16 12:22:20 +00007928 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007929 QualType ElementType
7930 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7931 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7932 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7933 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007934 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007935 }
7936 }
7937 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007938
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007939 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007940 }
Mike Stump11289f42009-09-09 15:08:12 +00007941
Douglas Gregor0744ef62010-09-07 21:49:58 +00007942 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007943 if (!ArraySize.get()) {
7944 // If no array size was specified, but the new expression was
7945 // instantiated with an array type (e.g., "new T" where T is
7946 // instantiated with "int[4]"), extract the outer bound from the
7947 // array type as our array size. We do this with constant and
7948 // dependently-sized array types.
7949 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7950 if (!ArrayT) {
7951 // Do nothing
7952 } else if (const ConstantArrayType *ConsArrayT
7953 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007954 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
7955 SemaRef.Context.getSizeType(),
7956 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007957 AllocType = ConsArrayT->getElementType();
7958 } else if (const DependentSizedArrayType *DepArrayT
7959 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7960 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007961 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007962 AllocType = DepArrayT->getElementType();
7963 }
7964 }
7965 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007966
Douglas Gregora16548e2009-08-11 05:31:07 +00007967 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7968 E->isGlobalNew(),
7969 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007970 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007971 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007972 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007973 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007974 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007975 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007976 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007977 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007978}
Mike Stump11289f42009-09-09 15:08:12 +00007979
Douglas Gregora16548e2009-08-11 05:31:07 +00007980template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007981ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007982TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007983 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007984 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007985 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007986
Douglas Gregord2d9da02010-02-26 00:38:10 +00007987 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00007988 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00007989 if (E->getOperatorDelete()) {
7990 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007991 getDerived().TransformDecl(E->getLocStart(),
7992 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007993 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007994 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007995 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007996
Douglas Gregora16548e2009-08-11 05:31:07 +00007997 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007998 Operand.get() == E->getArgument() &&
7999 OperatorDelete == E->getOperatorDelete()) {
8000 // Mark any declarations we need as referenced.
8001 // FIXME: instantiation-specific.
8002 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008003 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008004
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008005 if (!E->getArgument()->isTypeDependent()) {
8006 QualType Destroyed = SemaRef.Context.getBaseElementType(
8007 E->getDestroyedType());
8008 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8009 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008010 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008011 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008012 }
8013 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008014
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008015 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008016 }
Mike Stump11289f42009-09-09 15:08:12 +00008017
Douglas Gregora16548e2009-08-11 05:31:07 +00008018 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8019 E->isGlobalDelete(),
8020 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008021 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008022}
Mike Stump11289f42009-09-09 15:08:12 +00008023
Douglas Gregora16548e2009-08-11 05:31:07 +00008024template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008025ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008026TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008027 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008028 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008029 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008030 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008031
John McCallba7bf592010-08-24 05:47:05 +00008032 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008033 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008034 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008035 E->getOperatorLoc(),
8036 E->isArrow()? tok::arrow : tok::period,
8037 ObjectTypePtr,
8038 MayBePseudoDestructor);
8039 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008040 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008041
John McCallba7bf592010-08-24 05:47:05 +00008042 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008043 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8044 if (QualifierLoc) {
8045 QualifierLoc
8046 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8047 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008048 return ExprError();
8049 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008050 CXXScopeSpec SS;
8051 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008052
Douglas Gregor678f90d2010-02-25 01:56:36 +00008053 PseudoDestructorTypeStorage Destroyed;
8054 if (E->getDestroyedTypeInfo()) {
8055 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008056 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008057 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008058 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008059 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008060 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008061 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008062 // We aren't likely to be able to resolve the identifier down to a type
8063 // now anyway, so just retain the identifier.
8064 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8065 E->getDestroyedTypeLoc());
8066 } else {
8067 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008068 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008069 *E->getDestroyedTypeIdentifier(),
8070 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008071 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008072 SS, ObjectTypePtr,
8073 false);
8074 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008075 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008076
Douglas Gregor678f90d2010-02-25 01:56:36 +00008077 Destroyed
8078 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8079 E->getDestroyedTypeLoc());
8080 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008081
Craig Topperc3ec1492014-05-26 06:22:03 +00008082 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008083 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008084 CXXScopeSpec EmptySS;
8085 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008086 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008087 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008088 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008089 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008090
John McCallb268a282010-08-23 23:25:46 +00008091 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008092 E->getOperatorLoc(),
8093 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008094 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008095 ScopeTypeInfo,
8096 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008097 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008098 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008099}
Mike Stump11289f42009-09-09 15:08:12 +00008100
Douglas Gregorad8a3362009-09-04 17:36:40 +00008101template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008102ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008103TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008104 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008105 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8106 Sema::LookupOrdinaryName);
8107
8108 // Transform all the decls.
8109 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8110 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008111 NamedDecl *InstD = static_cast<NamedDecl*>(
8112 getDerived().TransformDecl(Old->getNameLoc(),
8113 *I));
John McCall84d87672009-12-10 09:41:52 +00008114 if (!InstD) {
8115 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8116 // This can happen because of dependent hiding.
8117 if (isa<UsingShadowDecl>(*I))
8118 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008119 else {
8120 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008121 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008122 }
John McCall84d87672009-12-10 09:41:52 +00008123 }
John McCalle66edc12009-11-24 19:00:30 +00008124
8125 // Expand using declarations.
8126 if (isa<UsingDecl>(InstD)) {
8127 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008128 for (auto *I : UD->shadows())
8129 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008130 continue;
8131 }
8132
8133 R.addDecl(InstD);
8134 }
8135
8136 // Resolve a kind, but don't do any further analysis. If it's
8137 // ambiguous, the callee needs to deal with it.
8138 R.resolveKind();
8139
8140 // Rebuild the nested-name qualifier, if present.
8141 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008142 if (Old->getQualifierLoc()) {
8143 NestedNameSpecifierLoc QualifierLoc
8144 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8145 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008146 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008147
Douglas Gregor0da1d432011-02-28 20:01:57 +00008148 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008149 }
8150
Douglas Gregor9262f472010-04-27 18:19:34 +00008151 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008152 CXXRecordDecl *NamingClass
8153 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8154 Old->getNameLoc(),
8155 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008156 if (!NamingClass) {
8157 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008158 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008159 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008160
Douglas Gregorda7be082010-04-27 16:10:10 +00008161 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00008162 }
8163
Abramo Bagnara7945c982012-01-27 09:46:47 +00008164 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8165
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008166 // If we have neither explicit template arguments, nor the template keyword,
8167 // it's a normal declaration name.
8168 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00008169 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
8170
8171 // If we have template arguments, rebuild them, then rebuild the
8172 // templateid expression.
8173 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00008174 if (Old->hasExplicitTemplateArgs() &&
8175 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00008176 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008177 TransArgs)) {
8178 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008179 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008180 }
John McCalle66edc12009-11-24 19:00:30 +00008181
Abramo Bagnara7945c982012-01-27 09:46:47 +00008182 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008183 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008184}
Mike Stump11289f42009-09-09 15:08:12 +00008185
Douglas Gregora16548e2009-08-11 05:31:07 +00008186template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008187ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008188TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8189 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008190 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008191 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8192 TypeSourceInfo *From = E->getArg(I);
8193 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008194 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008195 TypeLocBuilder TLB;
8196 TLB.reserve(FromTL.getFullDataSize());
8197 QualType To = getDerived().TransformType(TLB, FromTL);
8198 if (To.isNull())
8199 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008200
Douglas Gregor29c42f22012-02-24 07:38:34 +00008201 if (To == From->getType())
8202 Args.push_back(From);
8203 else {
8204 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8205 ArgChanged = true;
8206 }
8207 continue;
8208 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008209
Douglas Gregor29c42f22012-02-24 07:38:34 +00008210 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008211
Douglas Gregor29c42f22012-02-24 07:38:34 +00008212 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008213 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008214 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8215 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8216 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008217
Douglas Gregor29c42f22012-02-24 07:38:34 +00008218 // Determine whether the set of unexpanded parameter packs can and should
8219 // be expanded.
8220 bool Expand = true;
8221 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008222 Optional<unsigned> OrigNumExpansions =
8223 ExpansionTL.getTypePtr()->getNumExpansions();
8224 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008225 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8226 PatternTL.getSourceRange(),
8227 Unexpanded,
8228 Expand, RetainExpansion,
8229 NumExpansions))
8230 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008231
Douglas Gregor29c42f22012-02-24 07:38:34 +00008232 if (!Expand) {
8233 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008234 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008235 // expansion.
8236 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008237
Douglas Gregor29c42f22012-02-24 07:38:34 +00008238 TypeLocBuilder TLB;
8239 TLB.reserve(From->getTypeLoc().getFullDataSize());
8240
8241 QualType To = getDerived().TransformType(TLB, PatternTL);
8242 if (To.isNull())
8243 return ExprError();
8244
Chad Rosier1dcde962012-08-08 18:46:20 +00008245 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008246 PatternTL.getSourceRange(),
8247 ExpansionTL.getEllipsisLoc(),
8248 NumExpansions);
8249 if (To.isNull())
8250 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008251
Douglas Gregor29c42f22012-02-24 07:38:34 +00008252 PackExpansionTypeLoc ToExpansionTL
8253 = TLB.push<PackExpansionTypeLoc>(To);
8254 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8255 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8256 continue;
8257 }
8258
8259 // Expand the pack expansion by substituting for each argument in the
8260 // pack(s).
8261 for (unsigned I = 0; I != *NumExpansions; ++I) {
8262 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8263 TypeLocBuilder TLB;
8264 TLB.reserve(PatternTL.getFullDataSize());
8265 QualType To = getDerived().TransformType(TLB, PatternTL);
8266 if (To.isNull())
8267 return ExprError();
8268
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008269 if (To->containsUnexpandedParameterPack()) {
8270 To = getDerived().RebuildPackExpansionType(To,
8271 PatternTL.getSourceRange(),
8272 ExpansionTL.getEllipsisLoc(),
8273 NumExpansions);
8274 if (To.isNull())
8275 return ExprError();
8276
8277 PackExpansionTypeLoc ToExpansionTL
8278 = TLB.push<PackExpansionTypeLoc>(To);
8279 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8280 }
8281
Douglas Gregor29c42f22012-02-24 07:38:34 +00008282 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8283 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008284
Douglas Gregor29c42f22012-02-24 07:38:34 +00008285 if (!RetainExpansion)
8286 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008287
Douglas Gregor29c42f22012-02-24 07:38:34 +00008288 // If we're supposed to retain a pack expansion, do so by temporarily
8289 // forgetting the partially-substituted parameter pack.
8290 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8291
8292 TypeLocBuilder TLB;
8293 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008294
Douglas Gregor29c42f22012-02-24 07:38:34 +00008295 QualType To = getDerived().TransformType(TLB, PatternTL);
8296 if (To.isNull())
8297 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008298
8299 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008300 PatternTL.getSourceRange(),
8301 ExpansionTL.getEllipsisLoc(),
8302 NumExpansions);
8303 if (To.isNull())
8304 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008305
Douglas Gregor29c42f22012-02-24 07:38:34 +00008306 PackExpansionTypeLoc ToExpansionTL
8307 = TLB.push<PackExpansionTypeLoc>(To);
8308 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8309 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8310 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008311
Douglas Gregor29c42f22012-02-24 07:38:34 +00008312 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008313 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008314
8315 return getDerived().RebuildTypeTrait(E->getTrait(),
8316 E->getLocStart(),
8317 Args,
8318 E->getLocEnd());
8319}
8320
8321template<typename Derived>
8322ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008323TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8324 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8325 if (!T)
8326 return ExprError();
8327
8328 if (!getDerived().AlwaysRebuild() &&
8329 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008330 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008331
8332 ExprResult SubExpr;
8333 {
8334 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8335 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8336 if (SubExpr.isInvalid())
8337 return ExprError();
8338
8339 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008340 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00008341 }
8342
8343 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8344 E->getLocStart(),
8345 T,
8346 SubExpr.get(),
8347 E->getLocEnd());
8348}
8349
8350template<typename Derived>
8351ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008352TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8353 ExprResult SubExpr;
8354 {
8355 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8356 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8357 if (SubExpr.isInvalid())
8358 return ExprError();
8359
8360 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008361 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00008362 }
8363
8364 return getDerived().RebuildExpressionTrait(
8365 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8366}
8367
Reid Kleckner32506ed2014-06-12 23:03:48 +00008368template <typename Derived>
8369ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
8370 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
8371 TypeSourceInfo **RecoveryTSI) {
8372 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
8373 DRE, AddrTaken, RecoveryTSI);
8374
8375 // Propagate both errors and recovered types, which return ExprEmpty.
8376 if (!NewDRE.isUsable())
8377 return NewDRE;
8378
8379 // We got an expr, wrap it up in parens.
8380 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
8381 return PE;
8382 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
8383 PE->getRParen());
8384}
8385
8386template <typename Derived>
8387ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8388 DependentScopeDeclRefExpr *E) {
8389 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
8390 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008391}
8392
8393template<typename Derived>
8394ExprResult
8395TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8396 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00008397 bool IsAddressOfOperand,
8398 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008399 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008400 NestedNameSpecifierLoc QualifierLoc
8401 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8402 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008403 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008404 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008405
John McCall31f82722010-11-12 08:19:04 +00008406 // TODO: If this is a conversion-function-id, verify that the
8407 // destination type name (if present) resolves the same way after
8408 // instantiation as it did in the local scope.
8409
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008410 DeclarationNameInfo NameInfo
8411 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8412 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008413 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008414
John McCalle66edc12009-11-24 19:00:30 +00008415 if (!E->hasExplicitTemplateArgs()) {
8416 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008417 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008418 // Note: it is sufficient to compare the Name component of NameInfo:
8419 // if name has not changed, DNLoc has not changed either.
8420 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008421 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008422
Reid Kleckner32506ed2014-06-12 23:03:48 +00008423 return getDerived().RebuildDependentScopeDeclRefExpr(
8424 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
8425 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00008426 }
John McCall6b51f282009-11-23 01:53:49 +00008427
8428 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008429 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8430 E->getNumTemplateArgs(),
8431 TransArgs))
8432 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008433
Reid Kleckner32506ed2014-06-12 23:03:48 +00008434 return getDerived().RebuildDependentScopeDeclRefExpr(
8435 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
8436 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00008437}
8438
8439template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008440ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008441TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008442 // CXXConstructExprs other than for list-initialization and
8443 // CXXTemporaryObjectExpr are always implicit, so when we have
8444 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008445 if ((E->getNumArgs() == 1 ||
8446 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008447 (!getDerived().DropCallArgument(E->getArg(0))) &&
8448 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008449 return getDerived().TransformExpr(E->getArg(0));
8450
Douglas Gregora16548e2009-08-11 05:31:07 +00008451 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8452
8453 QualType T = getDerived().TransformType(E->getType());
8454 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008455 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008456
8457 CXXConstructorDecl *Constructor
8458 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008459 getDerived().TransformDecl(E->getLocStart(),
8460 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008461 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008462 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008463
Douglas Gregora16548e2009-08-11 05:31:07 +00008464 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008465 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008466 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008467 &ArgumentChanged))
8468 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008469
Douglas Gregora16548e2009-08-11 05:31:07 +00008470 if (!getDerived().AlwaysRebuild() &&
8471 T == E->getType() &&
8472 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008473 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008474 // Mark the constructor as referenced.
8475 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008476 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008477 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00008478 }
Mike Stump11289f42009-09-09 15:08:12 +00008479
Douglas Gregordb121ba2009-12-14 16:27:04 +00008480 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8481 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008482 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008483 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008484 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008485 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008486 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008487 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008488}
Mike Stump11289f42009-09-09 15:08:12 +00008489
Douglas Gregora16548e2009-08-11 05:31:07 +00008490/// \brief Transform a C++ temporary-binding expression.
8491///
Douglas Gregor363b1512009-12-24 18:51:59 +00008492/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8493/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008494template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008495ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008496TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008497 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008498}
Mike Stump11289f42009-09-09 15:08:12 +00008499
John McCall5d413782010-12-06 08:20:24 +00008500/// \brief Transform a C++ expression that contains cleanups that should
8501/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008502///
John McCall5d413782010-12-06 08:20:24 +00008503/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008504/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008505template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008506ExprResult
John McCall5d413782010-12-06 08:20:24 +00008507TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008508 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008509}
Mike Stump11289f42009-09-09 15:08:12 +00008510
Douglas Gregora16548e2009-08-11 05:31:07 +00008511template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008512ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008513TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008514 CXXTemporaryObjectExpr *E) {
8515 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8516 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008517 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008518
Douglas Gregora16548e2009-08-11 05:31:07 +00008519 CXXConstructorDecl *Constructor
8520 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008521 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008522 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008523 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008524 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008525
Douglas Gregora16548e2009-08-11 05:31:07 +00008526 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008527 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008528 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008529 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008530 &ArgumentChanged))
8531 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008532
Douglas Gregora16548e2009-08-11 05:31:07 +00008533 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008534 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008535 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008536 !ArgumentChanged) {
8537 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008538 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008539 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008540 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008541
Richard Smithd59b8322012-12-19 01:39:02 +00008542 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008543 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8544 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008545 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008546 E->getLocEnd());
8547}
Mike Stump11289f42009-09-09 15:08:12 +00008548
Douglas Gregora16548e2009-08-11 05:31:07 +00008549template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008550ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008551TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008552
8553 // Transform any init-capture expressions before entering the scope of the
8554 // lambda body, because they are not semantically within that scope.
8555 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8556 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8557 E->explicit_capture_begin());
8558
8559 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8560 CEnd = E->capture_end();
8561 C != CEnd; ++C) {
8562 if (!C->isInitCapture())
8563 continue;
8564 EnterExpressionEvaluationContext EEEC(getSema(),
8565 Sema::PotentiallyEvaluated);
8566 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8567 C->getCapturedVar()->getInit(),
8568 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8569
8570 if (NewExprInitResult.isInvalid())
8571 return ExprError();
8572 Expr *NewExprInit = NewExprInitResult.get();
8573
8574 VarDecl *OldVD = C->getCapturedVar();
8575 QualType NewInitCaptureType =
8576 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8577 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8578 NewExprInit);
8579 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008580 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8581 std::make_pair(NewExprInitResult, NewInitCaptureType);
8582
8583 }
8584
Faisal Vali524ca282013-11-12 01:40:44 +00008585 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008586 // Transform the template parameters, and add them to the current
8587 // instantiation scope. The null case is handled correctly.
8588 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8589 E->getTemplateParameterList());
8590
8591 // Check to see if the TypeSourceInfo of the call operator needs to
8592 // be transformed, and if so do the transformation in the
8593 // CurrentInstantiationScope.
8594
8595 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8596 FunctionProtoTypeLoc OldCallOpFPTL =
8597 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Craig Topperc3ec1492014-05-26 06:22:03 +00008598 TypeSourceInfo *NewCallOpTSI = nullptr;
8599
Faisal Vali2cba1332013-10-23 06:44:28 +00008600 const bool CallOpWasAlreadyTransformed =
8601 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8602
8603 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8604 if (CallOpWasAlreadyTransformed)
8605 NewCallOpTSI = OldCallOpTSI;
8606 else {
8607 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8608 // The transformation MUST be done in the CurrentInstantiationScope since
8609 // it introduces a mapping of the original to the newly created
8610 // transformed parameters.
8611
8612 TypeLocBuilder NewCallOpTLBuilder;
8613 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8614 OldCallOpFPTL,
Craig Topperc3ec1492014-05-26 06:22:03 +00008615 nullptr, 0);
Faisal Vali2cba1332013-10-23 06:44:28 +00008616 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8617 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008618 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008619 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8620 // the vector below - this will be used to synthesize the
8621 // NewCallOperator. Additionally, add the parameters of the untransformed
8622 // lambda call operator to the CurrentInstantiationScope.
8623 SmallVector<ParmVarDecl *, 4> Params;
8624 {
8625 FunctionProtoTypeLoc NewCallOpFPTL =
8626 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8627 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008628 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008629
8630 for (unsigned I = 0; I < NewNumArgs; ++I) {
8631 // If this call operator's type does not require transformation,
8632 // the parameters do not get added to the current instantiation scope,
8633 // - so ADD them! This allows the following to compile when the enclosing
8634 // template is specialized and the entire lambda expression has to be
8635 // transformed.
8636 // template<class T> void foo(T t) {
8637 // auto L = [](auto a) {
8638 // auto M = [](char b) { <-- note: non-generic lambda
8639 // auto N = [](auto c) {
8640 // int x = sizeof(a);
8641 // x = sizeof(b); <-- specifically this line
8642 // x = sizeof(c);
8643 // };
8644 // };
8645 // };
8646 // }
8647 // foo('a')
8648 if (CallOpWasAlreadyTransformed)
8649 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8650 NewParamDeclArray[I]);
8651 // Add to Params array, so these parameters can be used to create
8652 // the newly transformed call operator.
8653 Params.push_back(NewParamDeclArray[I]);
8654 }
8655 }
8656
8657 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008658 return ExprError();
8659
Eli Friedmand564afb2012-09-19 01:18:11 +00008660 // Create the local class that will describe the lambda.
8661 CXXRecordDecl *Class
8662 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008663 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008664 /*KnownDependent=*/false,
8665 E->getCaptureDefault());
8666
Eli Friedmand564afb2012-09-19 01:18:11 +00008667 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8668
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008669 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008670 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008671 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008672 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008673 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008674 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008675 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008676
Faisal Vali2cba1332013-10-23 06:44:28 +00008677 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8678
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008679 return getDerived().TransformLambdaScope(E, NewCallOperator,
8680 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008681}
8682
8683template<typename Derived>
8684ExprResult
8685TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008686 CXXMethodDecl *CallOperator,
8687 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008688 bool Invalid = false;
8689
Douglas Gregorb4328232012-02-14 00:00:48 +00008690 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008691 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8692 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008693
Faisal Vali2b391ab2013-09-26 19:54:12 +00008694 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008695 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008696 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008697 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008698 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008699 E->hasExplicitParameters(),
8700 E->hasExplicitResultType(),
8701 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008702
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008703 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008704 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008705 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008706 CEnd = E->capture_end();
8707 C != CEnd; ++C) {
8708 // When we hit the first implicit capture, tell Sema that we've finished
8709 // the list of explicit captures.
8710 if (!FinishedExplicitCaptures && C->isImplicit()) {
8711 getSema().finishLambdaExplicitCaptures(LSI);
8712 FinishedExplicitCaptures = true;
8713 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008714
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008715 // Capturing 'this' is trivial.
8716 if (C->capturesThis()) {
8717 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8718 continue;
8719 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008720
Richard Smithba71c082013-05-16 06:20:58 +00008721 // Rebuild init-captures, including the implied field declaration.
8722 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008723
8724 InitCaptureInfoTy InitExprTypePair =
8725 InitCaptureExprsAndTypes[C - E->capture_begin()];
8726 ExprResult Init = InitExprTypePair.first;
8727 QualType InitQualType = InitExprTypePair.second;
8728 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008729 Invalid = true;
8730 continue;
8731 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008732 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008733 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8734 OldVD->getLocation(), InitExprTypePair.second,
8735 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008736 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008737 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008738 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008739 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008740 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008741 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008742 continue;
8743 }
8744
8745 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8746
Douglas Gregor3e308b12012-02-14 19:27:52 +00008747 // Determine the capture kind for Sema.
8748 Sema::TryCaptureKind Kind
8749 = C->isImplicit()? Sema::TryCapture_Implicit
8750 : C->getCaptureKind() == LCK_ByCopy
8751 ? Sema::TryCapture_ExplicitByVal
8752 : Sema::TryCapture_ExplicitByRef;
8753 SourceLocation EllipsisLoc;
8754 if (C->isPackExpansion()) {
8755 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8756 bool ShouldExpand = false;
8757 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008758 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008759 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8760 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008761 Unexpanded,
8762 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008763 NumExpansions)) {
8764 Invalid = true;
8765 continue;
8766 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008767
Douglas Gregor3e308b12012-02-14 19:27:52 +00008768 if (ShouldExpand) {
8769 // The transform has determined that we should perform an expansion;
8770 // transform and capture each of the arguments.
8771 // expansion of the pattern. Do so.
8772 VarDecl *Pack = C->getCapturedVar();
8773 for (unsigned I = 0; I != *NumExpansions; ++I) {
8774 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8775 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008776 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008777 Pack));
8778 if (!CapturedVar) {
8779 Invalid = true;
8780 continue;
8781 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008782
Douglas Gregor3e308b12012-02-14 19:27:52 +00008783 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008784 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8785 }
Richard Smith9467be42014-06-06 17:33:35 +00008786
8787 // FIXME: Retain a pack expansion if RetainExpansion is true.
8788
Douglas Gregor3e308b12012-02-14 19:27:52 +00008789 continue;
8790 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008791
Douglas Gregor3e308b12012-02-14 19:27:52 +00008792 EllipsisLoc = C->getEllipsisLoc();
8793 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008794
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008795 // Transform the captured variable.
8796 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008797 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008798 C->getCapturedVar()));
8799 if (!CapturedVar) {
8800 Invalid = true;
8801 continue;
8802 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008803
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008804 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008805 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008806 }
8807 if (!FinishedExplicitCaptures)
8808 getSema().finishLambdaExplicitCaptures(LSI);
8809
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008810
8811 // Enter a new evaluation context to insulate the lambda from any
8812 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008813 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008814
8815 if (Invalid) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008816 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008817 /*IsInstantiation=*/true);
8818 return ExprError();
8819 }
8820
8821 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008822 StmtResult Body = getDerived().TransformStmt(E->getBody());
8823 if (Body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00008824 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00008825 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008826 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008827 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008828
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008829 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008830 /*CurScope=*/nullptr,
8831 /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008832}
8833
8834template<typename Derived>
8835ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008836TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008837 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008838 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8839 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008840 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008841
Douglas Gregora16548e2009-08-11 05:31:07 +00008842 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008843 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008844 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008845 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008846 &ArgumentChanged))
8847 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008848
Douglas Gregora16548e2009-08-11 05:31:07 +00008849 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008850 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008851 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008852 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008853
Douglas Gregora16548e2009-08-11 05:31:07 +00008854 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008855 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008856 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008857 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008858 E->getRParenLoc());
8859}
Mike Stump11289f42009-09-09 15:08:12 +00008860
Douglas Gregora16548e2009-08-11 05:31:07 +00008861template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008862ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008863TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008864 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008865 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00008866 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00008867 Expr *OldBase;
8868 QualType BaseType;
8869 QualType ObjectType;
8870 if (!E->isImplicitAccess()) {
8871 OldBase = E->getBase();
8872 Base = getDerived().TransformExpr(OldBase);
8873 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008874 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008875
John McCall2d74de92009-12-01 22:10:20 +00008876 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008877 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008878 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008879 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008880 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008881 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008882 ObjectTy,
8883 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008884 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008885 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008886
John McCallba7bf592010-08-24 05:47:05 +00008887 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008888 BaseType = ((Expr*) Base.get())->getType();
8889 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008890 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00008891 BaseType = getDerived().TransformType(E->getBaseType());
8892 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8893 }
Mike Stump11289f42009-09-09 15:08:12 +00008894
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008895 // Transform the first part of the nested-name-specifier that qualifies
8896 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008897 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008898 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008899 E->getFirstQualifierFoundInScope(),
8900 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008901
Douglas Gregore16af532011-02-28 18:50:33 +00008902 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008903 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008904 QualifierLoc
8905 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8906 ObjectType,
8907 FirstQualifierInScope);
8908 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008909 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008910 }
Mike Stump11289f42009-09-09 15:08:12 +00008911
Abramo Bagnara7945c982012-01-27 09:46:47 +00008912 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8913
John McCall31f82722010-11-12 08:19:04 +00008914 // TODO: If this is a conversion-function-id, verify that the
8915 // destination type name (if present) resolves the same way after
8916 // instantiation as it did in the local scope.
8917
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008918 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008919 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008920 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008921 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008922
John McCall2d74de92009-12-01 22:10:20 +00008923 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008924 // This is a reference to a member without an explicitly-specified
8925 // template argument list. Optimize for this common case.
8926 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008927 Base.get() == OldBase &&
8928 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008929 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008930 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008931 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008932 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008933
John McCallb268a282010-08-23 23:25:46 +00008934 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008935 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008936 E->isArrow(),
8937 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008938 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008939 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008940 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008941 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00008942 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00008943 }
8944
John McCall6b51f282009-11-23 01:53:49 +00008945 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008946 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8947 E->getNumTemplateArgs(),
8948 TransArgs))
8949 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008950
John McCallb268a282010-08-23 23:25:46 +00008951 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008952 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008953 E->isArrow(),
8954 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008955 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008956 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008957 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008958 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008959 &TransArgs);
8960}
8961
8962template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008963ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008964TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008965 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00008966 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00008967 QualType BaseType;
8968 if (!Old->isImplicitAccess()) {
8969 Base = getDerived().TransformExpr(Old->getBase());
8970 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008971 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008972 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00008973 Old->isArrow());
8974 if (Base.isInvalid())
8975 return ExprError();
8976 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008977 } else {
8978 BaseType = getDerived().TransformType(Old->getBaseType());
8979 }
John McCall10eae182009-11-30 22:42:35 +00008980
Douglas Gregor0da1d432011-02-28 20:01:57 +00008981 NestedNameSpecifierLoc QualifierLoc;
8982 if (Old->getQualifierLoc()) {
8983 QualifierLoc
8984 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8985 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008986 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008987 }
8988
Abramo Bagnara7945c982012-01-27 09:46:47 +00008989 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8990
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008991 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008992 Sema::LookupOrdinaryName);
8993
8994 // Transform all the decls.
8995 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8996 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008997 NamedDecl *InstD = static_cast<NamedDecl*>(
8998 getDerived().TransformDecl(Old->getMemberLoc(),
8999 *I));
John McCall84d87672009-12-10 09:41:52 +00009000 if (!InstD) {
9001 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9002 // This can happen because of dependent hiding.
9003 if (isa<UsingShadowDecl>(*I))
9004 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009005 else {
9006 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009007 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009008 }
John McCall84d87672009-12-10 09:41:52 +00009009 }
John McCall10eae182009-11-30 22:42:35 +00009010
9011 // Expand using declarations.
9012 if (isa<UsingDecl>(InstD)) {
9013 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009014 for (auto *I : UD->shadows())
9015 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009016 continue;
9017 }
9018
9019 R.addDecl(InstD);
9020 }
9021
9022 R.resolveKind();
9023
Douglas Gregor9262f472010-04-27 18:19:34 +00009024 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009025 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009026 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009027 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009028 Old->getMemberLoc(),
9029 Old->getNamingClass()));
9030 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009031 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009032
Douglas Gregorda7be082010-04-27 16:10:10 +00009033 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009034 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009035
John McCall10eae182009-11-30 22:42:35 +00009036 TemplateArgumentListInfo TransArgs;
9037 if (Old->hasExplicitTemplateArgs()) {
9038 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9039 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009040 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9041 Old->getNumTemplateArgs(),
9042 TransArgs))
9043 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009044 }
John McCall38836f02010-01-15 08:34:02 +00009045
9046 // FIXME: to do this check properly, we will need to preserve the
9047 // first-qualifier-in-scope here, just in case we had a dependent
9048 // base (and therefore couldn't do the check) and a
9049 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009050 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009051
John McCallb268a282010-08-23 23:25:46 +00009052 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009053 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009054 Old->getOperatorLoc(),
9055 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009056 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009057 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009058 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009059 R,
9060 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009061 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009062}
9063
9064template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009065ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009066TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009067 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009068 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9069 if (SubExpr.isInvalid())
9070 return ExprError();
9071
9072 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009073 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009074
9075 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9076}
9077
9078template<typename Derived>
9079ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009080TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009081 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9082 if (Pattern.isInvalid())
9083 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009084
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009085 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009086 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009087
Douglas Gregorb8840002011-01-14 21:20:45 +00009088 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9089 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009090}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009091
9092template<typename Derived>
9093ExprResult
9094TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9095 // If E is not value-dependent, then nothing will change when we transform it.
9096 // Note: This is an instantiation-centric view.
9097 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009098 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009099
9100 // Note: None of the implementations of TryExpandParameterPacks can ever
9101 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009102 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009103 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9104 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009105 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009106 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009107 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009108 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009109 ShouldExpand, RetainExpansion,
9110 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009111 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009112
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009113 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009114 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009115
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009116 NamedDecl *Pack = E->getPack();
9117 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009118 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009119 Pack));
9120 if (!Pack)
9121 return ExprError();
9122 }
9123
Chad Rosier1dcde962012-08-08 18:46:20 +00009124
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009125 // We now know the length of the parameter pack, so build a new expression
9126 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009127 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9128 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009129 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009130}
9131
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009132template<typename Derived>
9133ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009134TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9135 SubstNonTypeTemplateParmPackExpr *E) {
9136 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009137 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009138}
9139
9140template<typename Derived>
9141ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009142TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9143 SubstNonTypeTemplateParmExpr *E) {
9144 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009145 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009146}
9147
9148template<typename Derived>
9149ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009150TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9151 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009152 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009153}
9154
9155template<typename Derived>
9156ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009157TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9158 MaterializeTemporaryExpr *E) {
9159 return getDerived().TransformExpr(E->GetTemporaryExpr());
9160}
Chad Rosier1dcde962012-08-08 18:46:20 +00009161
Douglas Gregorfe314812011-06-21 17:03:29 +00009162template<typename Derived>
9163ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00009164TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
9165 CXXStdInitializerListExpr *E) {
9166 return getDerived().TransformExpr(E->getSubExpr());
9167}
9168
9169template<typename Derived>
9170ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009171TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009172 return SemaRef.MaybeBindToTemporary(E);
9173}
9174
9175template<typename Derived>
9176ExprResult
9177TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009178 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009179}
9180
9181template<typename Derived>
9182ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00009183TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
9184 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
9185 if (SubExpr.isInvalid())
9186 return ExprError();
9187
9188 if (!getDerived().AlwaysRebuild() &&
9189 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009190 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +00009191
9192 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00009193}
9194
9195template<typename Derived>
9196ExprResult
9197TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9198 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009199 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009200 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009201 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009202 /*IsCall=*/false, Elements, &ArgChanged))
9203 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009204
Ted Kremeneke65b0862012-03-06 20:05:56 +00009205 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9206 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009207
Ted Kremeneke65b0862012-03-06 20:05:56 +00009208 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9209 Elements.data(),
9210 Elements.size());
9211}
9212
9213template<typename Derived>
9214ExprResult
9215TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009216 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009217 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009218 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009219 bool ArgChanged = false;
9220 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9221 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009222
Ted Kremeneke65b0862012-03-06 20:05:56 +00009223 if (OrigElement.isPackExpansion()) {
9224 // This key/value element is a pack expansion.
9225 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9226 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9227 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9228 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9229
9230 // Determine whether the set of unexpanded parameter packs can
9231 // and should be expanded.
9232 bool Expand = true;
9233 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009234 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9235 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009236 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9237 OrigElement.Value->getLocEnd());
9238 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9239 PatternRange,
9240 Unexpanded,
9241 Expand, RetainExpansion,
9242 NumExpansions))
9243 return ExprError();
9244
9245 if (!Expand) {
9246 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009247 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009248 // expansion.
9249 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9250 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9251 if (Key.isInvalid())
9252 return ExprError();
9253
9254 if (Key.get() != OrigElement.Key)
9255 ArgChanged = true;
9256
9257 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9258 if (Value.isInvalid())
9259 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009260
Ted Kremeneke65b0862012-03-06 20:05:56 +00009261 if (Value.get() != OrigElement.Value)
9262 ArgChanged = true;
9263
Chad Rosier1dcde962012-08-08 18:46:20 +00009264 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009265 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9266 };
9267 Elements.push_back(Expansion);
9268 continue;
9269 }
9270
9271 // Record right away that the argument was changed. This needs
9272 // to happen even if the array expands to nothing.
9273 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009274
Ted Kremeneke65b0862012-03-06 20:05:56 +00009275 // The transform has determined that we should perform an elementwise
9276 // expansion of the pattern. Do so.
9277 for (unsigned I = 0; I != *NumExpansions; ++I) {
9278 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9279 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9280 if (Key.isInvalid())
9281 return ExprError();
9282
9283 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9284 if (Value.isInvalid())
9285 return ExprError();
9286
Chad Rosier1dcde962012-08-08 18:46:20 +00009287 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009288 Key.get(), Value.get(), SourceLocation(), NumExpansions
9289 };
9290
9291 // If any unexpanded parameter packs remain, we still have a
9292 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +00009293 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +00009294 if (Key.get()->containsUnexpandedParameterPack() ||
9295 Value.get()->containsUnexpandedParameterPack())
9296 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009297
Ted Kremeneke65b0862012-03-06 20:05:56 +00009298 Elements.push_back(Element);
9299 }
9300
Richard Smith9467be42014-06-06 17:33:35 +00009301 // FIXME: Retain a pack expansion if RetainExpansion is true.
9302
Ted Kremeneke65b0862012-03-06 20:05:56 +00009303 // We've finished with this pack expansion.
9304 continue;
9305 }
9306
9307 // Transform and check key.
9308 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9309 if (Key.isInvalid())
9310 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009311
Ted Kremeneke65b0862012-03-06 20:05:56 +00009312 if (Key.get() != OrigElement.Key)
9313 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009314
Ted Kremeneke65b0862012-03-06 20:05:56 +00009315 // Transform and check value.
9316 ExprResult Value
9317 = getDerived().TransformExpr(OrigElement.Value);
9318 if (Value.isInvalid())
9319 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009320
Ted Kremeneke65b0862012-03-06 20:05:56 +00009321 if (Value.get() != OrigElement.Value)
9322 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009323
9324 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009325 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009326 };
9327 Elements.push_back(Element);
9328 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009329
Ted Kremeneke65b0862012-03-06 20:05:56 +00009330 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9331 return SemaRef.MaybeBindToTemporary(E);
9332
9333 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9334 Elements.data(),
9335 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009336}
9337
Mike Stump11289f42009-09-09 15:08:12 +00009338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009339ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009340TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009341 TypeSourceInfo *EncodedTypeInfo
9342 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9343 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009344 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009345
Douglas Gregora16548e2009-08-11 05:31:07 +00009346 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009347 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009348 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009349
9350 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009351 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009352 E->getRParenLoc());
9353}
Mike Stump11289f42009-09-09 15:08:12 +00009354
Douglas Gregora16548e2009-08-11 05:31:07 +00009355template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009356ExprResult TreeTransform<Derived>::
9357TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009358 // This is a kind of implicit conversion, and it needs to get dropped
9359 // and recomputed for the same general reasons that ImplicitCastExprs
9360 // do, as well a more specific one: this expression is only valid when
9361 // it appears *immediately* as an argument expression.
9362 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009363}
9364
9365template<typename Derived>
9366ExprResult TreeTransform<Derived>::
9367TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009368 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009369 = getDerived().TransformType(E->getTypeInfoAsWritten());
9370 if (!TSInfo)
9371 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009372
John McCall31168b02011-06-15 23:02:42 +00009373 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009374 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009375 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009376
John McCall31168b02011-06-15 23:02:42 +00009377 if (!getDerived().AlwaysRebuild() &&
9378 TSInfo == E->getTypeInfoAsWritten() &&
9379 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009380 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009381
John McCall31168b02011-06-15 23:02:42 +00009382 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009383 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009384 Result.get());
9385}
9386
9387template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009388ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009389TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009390 // Transform arguments.
9391 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009392 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009393 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009394 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009395 &ArgChanged))
9396 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009397
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009398 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9399 // Class message: transform the receiver type.
9400 TypeSourceInfo *ReceiverTypeInfo
9401 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9402 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009403 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009404
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009405 // If nothing changed, just retain the existing message send.
9406 if (!getDerived().AlwaysRebuild() &&
9407 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009408 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009409
9410 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009411 SmallVector<SourceLocation, 16> SelLocs;
9412 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009413 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9414 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009415 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009416 E->getMethodDecl(),
9417 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009418 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009419 E->getRightLoc());
9420 }
9421
9422 // Instance message: transform the receiver
9423 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9424 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009425 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009426 = getDerived().TransformExpr(E->getInstanceReceiver());
9427 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009428 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009429
9430 // If nothing changed, just retain the existing message send.
9431 if (!getDerived().AlwaysRebuild() &&
9432 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009433 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009434
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009435 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009436 SmallVector<SourceLocation, 16> SelLocs;
9437 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009438 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009439 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009440 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009441 E->getMethodDecl(),
9442 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009443 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009444 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009445}
9446
Mike Stump11289f42009-09-09 15:08:12 +00009447template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009448ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009449TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009450 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009451}
9452
Mike Stump11289f42009-09-09 15:08:12 +00009453template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009454ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009455TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009456 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009457}
9458
Mike Stump11289f42009-09-09 15:08:12 +00009459template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009460ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009461TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009462 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009463 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009464 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009465 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009466
9467 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009468
Douglas Gregord51d90d2010-04-26 20:11:03 +00009469 // If nothing changed, just retain the existing expression.
9470 if (!getDerived().AlwaysRebuild() &&
9471 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009472 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009473
John McCallb268a282010-08-23 23:25:46 +00009474 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009475 E->getLocation(),
9476 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009477}
9478
Mike Stump11289f42009-09-09 15:08:12 +00009479template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009480ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009481TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009482 // 'super' and types never change. Property never changes. Just
9483 // retain the existing expression.
9484 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009485 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009486
Douglas Gregor9faee212010-04-26 20:47:02 +00009487 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009488 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009489 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009490 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009491
Douglas Gregor9faee212010-04-26 20:47:02 +00009492 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009493
Douglas Gregor9faee212010-04-26 20:47:02 +00009494 // If nothing changed, just retain the existing expression.
9495 if (!getDerived().AlwaysRebuild() &&
9496 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009497 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009498
John McCallb7bd14f2010-12-02 01:19:52 +00009499 if (E->isExplicitProperty())
9500 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9501 E->getExplicitProperty(),
9502 E->getLocation());
9503
9504 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009505 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009506 E->getImplicitPropertyGetter(),
9507 E->getImplicitPropertySetter(),
9508 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009509}
9510
Mike Stump11289f42009-09-09 15:08:12 +00009511template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009512ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009513TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9514 // Transform the base expression.
9515 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9516 if (Base.isInvalid())
9517 return ExprError();
9518
9519 // Transform the key expression.
9520 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9521 if (Key.isInvalid())
9522 return ExprError();
9523
9524 // If nothing changed, just retain the existing expression.
9525 if (!getDerived().AlwaysRebuild() &&
9526 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009527 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009528
Chad Rosier1dcde962012-08-08 18:46:20 +00009529 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009530 Base.get(), Key.get(),
9531 E->getAtIndexMethodDecl(),
9532 E->setAtIndexMethodDecl());
9533}
9534
9535template<typename Derived>
9536ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009537TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009538 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009539 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009540 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009541 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009542
Douglas Gregord51d90d2010-04-26 20:11:03 +00009543 // If nothing changed, just retain the existing expression.
9544 if (!getDerived().AlwaysRebuild() &&
9545 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009546 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009547
John McCallb268a282010-08-23 23:25:46 +00009548 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009549 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009550 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009551}
9552
Mike Stump11289f42009-09-09 15:08:12 +00009553template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009554ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009555TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009556 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009557 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009558 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009559 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009560 SubExprs, &ArgumentChanged))
9561 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009562
Douglas Gregora16548e2009-08-11 05:31:07 +00009563 if (!getDerived().AlwaysRebuild() &&
9564 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009565 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009566
Douglas Gregora16548e2009-08-11 05:31:07 +00009567 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009568 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009569 E->getRParenLoc());
9570}
9571
Mike Stump11289f42009-09-09 15:08:12 +00009572template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009573ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009574TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9575 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9576 if (SrcExpr.isInvalid())
9577 return ExprError();
9578
9579 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9580 if (!Type)
9581 return ExprError();
9582
9583 if (!getDerived().AlwaysRebuild() &&
9584 Type == E->getTypeSourceInfo() &&
9585 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009586 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +00009587
9588 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9589 SrcExpr.get(), Type,
9590 E->getRParenLoc());
9591}
9592
9593template<typename Derived>
9594ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009595TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009596 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009597
Craig Topperc3ec1492014-05-26 06:22:03 +00009598 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +00009599 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9600
9601 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009602 blockScope->TheDecl->setBlockMissingReturnType(
9603 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009604
Chris Lattner01cf8db2011-07-20 06:58:45 +00009605 SmallVector<ParmVarDecl*, 4> params;
9606 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009607
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009608 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009609 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9610 oldBlock->param_begin(),
9611 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009612 nullptr, paramTypes, &params)) {
9613 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009614 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009615 }
John McCall490112f2011-02-04 18:33:18 +00009616
Jordan Rosea0a86be2013-03-08 22:25:36 +00009617 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009618 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009619 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009620
Jordan Rose5c382722013-03-08 21:51:21 +00009621 QualType functionType =
9622 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009623 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009624 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009625
9626 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009627 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009628 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009629
9630 if (!oldBlock->blockMissingReturnType()) {
9631 blockScope->HasImplicitReturnType = false;
9632 blockScope->ReturnType = exprResultType;
9633 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009634
John McCall3882ace2011-01-05 12:14:39 +00009635 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009636 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009637 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009638 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +00009639 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009640 }
John McCall3882ace2011-01-05 12:14:39 +00009641
John McCall490112f2011-02-04 18:33:18 +00009642#ifndef NDEBUG
9643 // In builds with assertions, make sure that we captured everything we
9644 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009645 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009646 for (const auto &I : oldBlock->captures()) {
9647 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009648
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009649 // Ignore parameter packs.
9650 if (isa<ParmVarDecl>(oldCapture) &&
9651 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9652 continue;
John McCall490112f2011-02-04 18:33:18 +00009653
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009654 VarDecl *newCapture =
9655 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9656 oldCapture));
9657 assert(blockScope->CaptureMap.count(newCapture));
9658 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009659 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009660 }
9661#endif
9662
9663 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009664 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00009665}
9666
Mike Stump11289f42009-09-09 15:08:12 +00009667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009668ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009669TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009670 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009671}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009672
9673template<typename Derived>
9674ExprResult
9675TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009676 QualType RetTy = getDerived().TransformType(E->getType());
9677 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009678 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009679 SubExprs.reserve(E->getNumSubExprs());
9680 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9681 SubExprs, &ArgumentChanged))
9682 return ExprError();
9683
9684 if (!getDerived().AlwaysRebuild() &&
9685 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009686 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009687
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009688 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009689 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009690}
Chad Rosier1dcde962012-08-08 18:46:20 +00009691
Douglas Gregora16548e2009-08-11 05:31:07 +00009692//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009693// Type reconstruction
9694//===----------------------------------------------------------------------===//
9695
Mike Stump11289f42009-09-09 15:08:12 +00009696template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009697QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9698 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009699 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009700 getDerived().getBaseEntity());
9701}
9702
Mike Stump11289f42009-09-09 15:08:12 +00009703template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009704QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9705 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009706 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009707 getDerived().getBaseEntity());
9708}
9709
Mike Stump11289f42009-09-09 15:08:12 +00009710template<typename Derived>
9711QualType
John McCall70dd5f62009-10-30 00:06:24 +00009712TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9713 bool WrittenAsLValue,
9714 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009715 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009716 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009717}
9718
9719template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009720QualType
John McCall70dd5f62009-10-30 00:06:24 +00009721TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9722 QualType ClassType,
9723 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009724 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9725 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009726}
9727
9728template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009729QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009730TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9731 ArrayType::ArraySizeModifier SizeMod,
9732 const llvm::APInt *Size,
9733 Expr *SizeExpr,
9734 unsigned IndexTypeQuals,
9735 SourceRange BracketsRange) {
9736 if (SizeExpr || !Size)
9737 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9738 IndexTypeQuals, BracketsRange,
9739 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009740
9741 QualType Types[] = {
9742 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9743 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9744 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009745 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009746 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009747 QualType SizeType;
9748 for (unsigned I = 0; I != NumTypes; ++I)
9749 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9750 SizeType = Types[I];
9751 break;
9752 }
Mike Stump11289f42009-09-09 15:08:12 +00009753
Eli Friedman9562f392012-01-25 23:20:27 +00009754 // Note that we can return a VariableArrayType here in the case where
9755 // the element type was a dependent VariableArrayType.
9756 IntegerLiteral *ArraySize
9757 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9758 /*FIXME*/BracketsRange.getBegin());
9759 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009760 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009761 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009762}
Mike Stump11289f42009-09-09 15:08:12 +00009763
Douglas Gregord6ff3322009-08-04 16:50:30 +00009764template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009765QualType
9766TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009767 ArrayType::ArraySizeModifier SizeMod,
9768 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009769 unsigned IndexTypeQuals,
9770 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009771 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009772 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009773}
9774
9775template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009776QualType
Mike Stump11289f42009-09-09 15:08:12 +00009777TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009778 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009779 unsigned IndexTypeQuals,
9780 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009781 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +00009782 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009783}
Mike Stump11289f42009-09-09 15:08:12 +00009784
Douglas Gregord6ff3322009-08-04 16:50:30 +00009785template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009786QualType
9787TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009788 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009789 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009790 unsigned IndexTypeQuals,
9791 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009792 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009793 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009794 IndexTypeQuals, BracketsRange);
9795}
9796
9797template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009798QualType
9799TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009800 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009801 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009802 unsigned IndexTypeQuals,
9803 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +00009804 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +00009805 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009806 IndexTypeQuals, BracketsRange);
9807}
9808
9809template<typename Derived>
9810QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009811 unsigned NumElements,
9812 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009813 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009814 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009815}
Mike Stump11289f42009-09-09 15:08:12 +00009816
Douglas Gregord6ff3322009-08-04 16:50:30 +00009817template<typename Derived>
9818QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9819 unsigned NumElements,
9820 SourceLocation AttributeLoc) {
9821 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9822 NumElements, true);
9823 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009824 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9825 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009826 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009827}
Mike Stump11289f42009-09-09 15:08:12 +00009828
Douglas Gregord6ff3322009-08-04 16:50:30 +00009829template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009830QualType
9831TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009832 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009833 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009834 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009835}
Mike Stump11289f42009-09-09 15:08:12 +00009836
Douglas Gregord6ff3322009-08-04 16:50:30 +00009837template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009838QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9839 QualType T,
9840 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009841 const FunctionProtoType::ExtProtoInfo &EPI) {
9842 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009843 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009844 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009845 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009846}
Mike Stump11289f42009-09-09 15:08:12 +00009847
Douglas Gregord6ff3322009-08-04 16:50:30 +00009848template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009849QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9850 return SemaRef.Context.getFunctionNoProtoType(T);
9851}
9852
9853template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009854QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9855 assert(D && "no decl found");
9856 if (D->isInvalidDecl()) return QualType();
9857
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009858 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009859 TypeDecl *Ty;
9860 if (isa<UsingDecl>(D)) {
9861 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009862 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009863 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9864
9865 // A valid resolved using typename decl points to exactly one type decl.
9866 assert(++Using->shadow_begin() == Using->shadow_end());
9867 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009868
John McCallb96ec562009-12-04 22:46:56 +00009869 } else {
9870 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9871 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9872 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9873 }
9874
9875 return SemaRef.Context.getTypeDeclType(Ty);
9876}
9877
9878template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009879QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9880 SourceLocation Loc) {
9881 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009882}
9883
9884template<typename Derived>
9885QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9886 return SemaRef.Context.getTypeOfType(Underlying);
9887}
9888
9889template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009890QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9891 SourceLocation Loc) {
9892 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009893}
9894
9895template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009896QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9897 UnaryTransformType::UTTKind UKind,
9898 SourceLocation Loc) {
9899 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9900}
9901
9902template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009903QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009904 TemplateName Template,
9905 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009906 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009907 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009908}
Mike Stump11289f42009-09-09 15:08:12 +00009909
Douglas Gregor1135c352009-08-06 05:28:30 +00009910template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009911QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9912 SourceLocation KWLoc) {
9913 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9914}
9915
9916template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009917TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009918TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009919 bool TemplateKW,
9920 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009921 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009922 Template);
9923}
9924
9925template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009926TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009927TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9928 const IdentifierInfo &Name,
9929 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009930 QualType ObjectType,
9931 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009932 UnqualifiedId TemplateName;
9933 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009934 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009935 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +00009936 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009937 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009938 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009939 /*EnteringContext=*/false,
9940 Template);
John McCall31f82722010-11-12 08:19:04 +00009941 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009942}
Mike Stump11289f42009-09-09 15:08:12 +00009943
Douglas Gregora16548e2009-08-11 05:31:07 +00009944template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009945TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009946TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009947 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009948 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009949 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009950 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009951 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009952 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009953 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009954 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009955 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +00009956 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009957 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009958 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009959 /*EnteringContext=*/false,
9960 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009961 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009962}
Chad Rosier1dcde962012-08-08 18:46:20 +00009963
Douglas Gregor71395fa2009-11-04 00:56:37 +00009964template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009965ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009966TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9967 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009968 Expr *OrigCallee,
9969 Expr *First,
9970 Expr *Second) {
9971 Expr *Callee = OrigCallee->IgnoreParenCasts();
9972 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009973
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +00009974 if (First->getObjectKind() == OK_ObjCProperty) {
9975 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
9976 if (BinaryOperator::isAssignmentOp(Opc))
9977 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
9978 First, Second);
9979 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
9980 if (Result.isInvalid())
9981 return ExprError();
9982 First = Result.get();
9983 }
9984
9985 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
9986 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
9987 if (Result.isInvalid())
9988 return ExprError();
9989 Second = Result.get();
9990 }
9991
Douglas Gregora16548e2009-08-11 05:31:07 +00009992 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009993 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009994 if (!First->getType()->isOverloadableType() &&
9995 !Second->getType()->isOverloadableType())
9996 return getSema().CreateBuiltinArraySubscriptExpr(First,
9997 Callee->getLocStart(),
9998 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009999 } else if (Op == OO_Arrow) {
10000 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010001 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10002 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010003 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010004 // The argument is not of overloadable type, so try to create a
10005 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010006 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010007 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010008
John McCallb268a282010-08-23 23:25:46 +000010009 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010010 }
10011 } else {
John McCallb268a282010-08-23 23:25:46 +000010012 if (!First->getType()->isOverloadableType() &&
10013 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010014 // Neither of the arguments is an overloadable type, so try to
10015 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010016 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010017 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010018 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010019 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010020 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010021
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010022 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010023 }
10024 }
Mike Stump11289f42009-09-09 15:08:12 +000010025
10026 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010027 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010028 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010029
John McCallb268a282010-08-23 23:25:46 +000010030 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010031 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010032 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010033 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010034 // If we've resolved this to a particular non-member function, just call
10035 // that function. If we resolved it to a member function,
10036 // CreateOverloaded* will find that function for us.
10037 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10038 if (!isa<CXXMethodDecl>(ND))
10039 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000010040 }
Mike Stump11289f42009-09-09 15:08:12 +000010041
Douglas Gregora16548e2009-08-11 05:31:07 +000010042 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000010043 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000010044 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000010045
Douglas Gregora16548e2009-08-11 05:31:07 +000010046 // Create the overloaded operator invocation for unary operators.
10047 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000010048 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010049 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000010050 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010051 }
Mike Stump11289f42009-09-09 15:08:12 +000010052
Douglas Gregore9d62932011-07-15 16:25:15 +000010053 if (Op == OO_Subscript) {
10054 SourceLocation LBrace;
10055 SourceLocation RBrace;
10056
10057 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
10058 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
10059 LBrace = SourceLocation::getFromRawEncoding(
10060 NameLoc.CXXOperatorName.BeginOpNameLoc);
10061 RBrace = SourceLocation::getFromRawEncoding(
10062 NameLoc.CXXOperatorName.EndOpNameLoc);
10063 } else {
10064 LBrace = Callee->getLocStart();
10065 RBrace = OpLoc;
10066 }
10067
10068 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
10069 First, Second);
10070 }
Sebastian Redladba46e2009-10-29 20:17:01 +000010071
Douglas Gregora16548e2009-08-11 05:31:07 +000010072 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000010073 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010074 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000010075 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
10076 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010077 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010078
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010079 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010080}
Mike Stump11289f42009-09-09 15:08:12 +000010081
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010082template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010083ExprResult
John McCallb268a282010-08-23 23:25:46 +000010084TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010085 SourceLocation OperatorLoc,
10086 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000010087 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010088 TypeSourceInfo *ScopeType,
10089 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010090 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010091 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000010092 QualType BaseType = Base->getType();
10093 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010094 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000010095 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000010096 !BaseType->getAs<PointerType>()->getPointeeType()
10097 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010098 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +000010099 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010100 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010101 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010102 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010103 /*FIXME?*/true);
10104 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010105
Douglas Gregor678f90d2010-02-25 01:56:36 +000010106 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010107 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
10108 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
10109 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
10110 NameInfo.setNamedTypeInfo(DestroyedType);
10111
Richard Smith8e4a3862012-05-15 06:15:11 +000010112 // The scope type is now known to be a valid nested name specifier
10113 // component. Tack it on to the end of the nested name specifier.
10114 if (ScopeType)
10115 SS.Extend(SemaRef.Context, SourceLocation(),
10116 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010117
Abramo Bagnara7945c982012-01-27 09:46:47 +000010118 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000010119 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010120 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010121 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000010122 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010123 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010124 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010125}
10126
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010127template<typename Derived>
10128StmtResult
10129TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000010130 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000010131 CapturedDecl *CD = S->getCapturedDecl();
10132 unsigned NumParams = CD->getNumParams();
10133 unsigned ContextParamPos = CD->getContextParamPosition();
10134 SmallVector<Sema::CapturedParamNameType, 4> Params;
10135 for (unsigned I = 0; I < NumParams; ++I) {
10136 if (I != ContextParamPos) {
10137 Params.push_back(
10138 std::make_pair(
10139 CD->getParam(I)->getName(),
10140 getDerived().TransformType(CD->getParam(I)->getType())));
10141 } else {
10142 Params.push_back(std::make_pair(StringRef(), QualType()));
10143 }
10144 }
Craig Topperc3ec1492014-05-26 06:22:03 +000010145 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000010146 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000010147 StmtResult Body;
10148 {
10149 Sema::CompoundScopeRAII CompoundScope(getSema());
10150 Body = getDerived().TransformStmt(S->getCapturedStmt());
10151 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000010152
10153 if (Body.isInvalid()) {
10154 getSema().ActOnCapturedRegionError();
10155 return StmtError();
10156 }
10157
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010158 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000010159}
10160
Douglas Gregord6ff3322009-08-04 16:50:30 +000010161} // end namespace clang
10162
10163#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H